mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
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
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user