diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-05 02:32:26 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-05 02:32:26 +0000 |
commit | 5fd5fe0f7bfac0f7973475fcf7a5f8061d983538 (patch) | |
tree | 8596242c630f6f9a293d27abcda4f0c7746b806e /include/llvm/Object/YAML.h | |
parent | 6afb65c2b709cfa078d0f6f6c5feceb2abab8036 (diff) | |
download | external_llvm-5fd5fe0f7bfac0f7973475fcf7a5f8061d983538.tar.gz external_llvm-5fd5fe0f7bfac0f7973475fcf7a5f8061d983538.tar.bz2 external_llvm-5fd5fe0f7bfac0f7973475fcf7a5f8061d983538.zip |
Move BinaryRef to a new include/llvm/Object/YAML.h file.
It will be used for ELF dumping too.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183287 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Object/YAML.h')
-rw-r--r-- | include/llvm/Object/YAML.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/llvm/Object/YAML.h b/include/llvm/Object/YAML.h new file mode 100644 index 0000000000..44d387b84e --- /dev/null +++ b/include/llvm/Object/YAML.h @@ -0,0 +1,59 @@ +//===- YAML.h - YAMLIO utilities for object files ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares utility classes for handling the YAML representation of +// object files. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECT_YAML_H +#define LLVM_OBJECT_YAML_H + +#include "llvm/Support/YAMLTraits.h" + +namespace llvm { +namespace object { +namespace yaml { + +/// In an object file this is just a binary blob. In an yaml file it is an hex +/// string. Using this avoid having to allocate temporary strings. +class BinaryRef { + ArrayRef<uint8_t> Data; + bool isBinary; + +public: + BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), isBinary(true) {} + BinaryRef(StringRef Data) + : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()), + isBinary(false) {} + BinaryRef() : isBinary(false) {} + StringRef getHex() const { + assert(!isBinary); + return StringRef(reinterpret_cast<const char *>(Data.data()), Data.size()); + } + ArrayRef<uint8_t> getBinary() const { + assert(isBinary); + return Data; + } +}; + +} +} + +namespace yaml { +template <> struct ScalarTraits<object::yaml::BinaryRef> { + static void output(const object::yaml::BinaryRef &, void *, + llvm::raw_ostream &); + static StringRef input(StringRef, void *, object::yaml::BinaryRef &); +}; +} + +} + +#endif |