diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-05-31 20:26:44 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-05-31 20:26:44 +0000 |
commit | 05bc4a6f20fb4bad971dc6ebb86b9ee29307bd3d (patch) | |
tree | 689fc46d860140b2305957bac56bfc2073fdeb3b /include | |
parent | 47afc19625e97a3716d813f014a3a48468e591ca (diff) | |
download | llvm-05bc4a6f20fb4bad971dc6ebb86b9ee29307bd3d.tar.gz llvm-05bc4a6f20fb4bad971dc6ebb86b9ee29307bd3d.tar.bz2 llvm-05bc4a6f20fb4bad971dc6ebb86b9ee29307bd3d.tar.xz |
Don't allocate temporary string for section data.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183040 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Object/COFFYaml.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/include/llvm/Object/COFFYaml.h b/include/llvm/Object/COFFYaml.h index 08cbab428c..f4732e23bc 100644 --- a/include/llvm/Object/COFFYaml.h +++ b/include/llvm/Object/COFFYaml.h @@ -36,10 +36,34 @@ inline SectionCharacteristics operator|(SectionCharacteristics a, // The structure of the yaml files is not an exact 1:1 match to COFF. In order // to use yaml::IO, we use these structures which are closer to the source. namespace COFFYAML { + /// 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. + /// FIXME: not COFF specific. + class BinaryRef { + union { + ArrayRef<uint8_t> BinaryData; + StringRef HexData; + }; + bool isBinary; + public: + BinaryRef(ArrayRef<uint8_t> BinaryData) + : BinaryData(BinaryData), isBinary(true) {} + BinaryRef(StringRef HexData) : HexData(HexData), isBinary(false) {} + BinaryRef() : isBinary(false) {} + StringRef getHex() const { + assert(!isBinary); + return HexData; + } + ArrayRef<uint8_t> getBinary() const { + assert(isBinary); + return BinaryData; + } + }; + struct Section { COFF::section Header; unsigned Alignment; - StringRef SectionData; + BinaryRef SectionData; std::vector<COFF::relocation> Relocations; StringRef Name; Section(); @@ -49,7 +73,7 @@ namespace COFFYAML { COFF::symbol Header; COFF::SymbolBaseType SimpleType; COFF::SymbolComplexType ComplexType; - StringRef AuxiliaryData; + BinaryRef AuxiliaryData; StringRef Name; Symbol(); }; @@ -70,6 +94,12 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation) namespace llvm { namespace yaml { +template<> +struct ScalarTraits<COFFYAML::BinaryRef> { + static void output(const COFFYAML::BinaryRef &, void*, llvm::raw_ostream &); + static StringRef input(StringRef, void*, COFFYAML::BinaryRef &); +}; + template <> struct ScalarEnumerationTraits<COFF::MachineTypes> { static void enumeration(IO &IO, COFF::MachineTypes &Value); |