Add back parsing of header charactestics.

It had been dropped during the switch to yaml::IO. Also add a test going
from yaml2obj to llvm-readobj. It can be extended as we add more
fields/formats to yaml2obj.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178786 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-04-04 20:30:52 +00:00
parent e50faa754b
commit 5152e4fb06
3 changed files with 43 additions and 1 deletions

View File

@ -1,5 +1,6 @@
header: !Header header: !Header
Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) Machine: IMAGE_FILE_MACHINE_I386 # (0x14c)
Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ]
sections: sections:
- !Section - !Section

View File

@ -0,0 +1,5 @@
RUN: yaml2obj %p/Inputs/COFF/i386.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix COFF-I386
// COFF-I386: Characteristics [ (0x200)
// COFF-I386-NEXT: IMAGE_FILE_DEBUG_STRIPPED (0x200)
// COFF-I386-NEXT: ]

View File

@ -129,6 +129,7 @@ namespace COFFYAML {
struct Header { struct Header {
COFF::MachineTypes Machine; COFF::MachineTypes Machine;
std::vector<COFF::Characteristics> Characteristics;
}; };
struct Symbol { struct Symbol {
@ -159,6 +160,18 @@ struct COFFParser {
StringTable.append(4, 0); StringTable.append(4, 0);
} }
void parseHeader() {
Header.Machine = Obj.HeaderData.Machine;
const std::vector<COFF::Characteristics> &Characteristics =
Obj.HeaderData.Characteristics;
for (std::vector<COFF::Characteristics>::const_iterator I =
Characteristics.begin(), E = Characteristics.end(); I != E; ++I) {
uint16_t Characteristic = *I;
Header.Characteristics |= Characteristic;
}
}
bool parseSections() { bool parseSections() {
for (std::vector<COFFYAML::Section>::iterator i = Obj.Sections.begin(), for (std::vector<COFFYAML::Section>::iterator i = Obj.Sections.begin(),
e = Obj.Sections.end(); i != e; ++i) { e = Obj.Sections.end(); i != e; ++i) {
@ -239,7 +252,7 @@ struct COFFParser {
} }
bool parse() { bool parse() {
Header.Machine = Obj.HeaderData.Machine; parseHeader();
if (!parseSections()) if (!parseSections())
return false; return false;
if (!parseSymbols()) if (!parseSymbols())
@ -409,6 +422,7 @@ void writeCOFF(COFFParser &CP, raw_ostream &OS) {
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation) LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::SectionCharacteristics) LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::SectionCharacteristics)
LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::Characteristics)
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section) LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol) LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
@ -510,6 +524,27 @@ struct ScalarEnumerationTraits<COFF::MachineTypes> {
} }
}; };
template <>
struct ScalarEnumerationTraits<COFF::Characteristics> {
static void enumeration(IO &IO, COFF::Characteristics &Value) {
ECase(IMAGE_FILE_RELOCS_STRIPPED);
ECase(IMAGE_FILE_EXECUTABLE_IMAGE);
ECase(IMAGE_FILE_LINE_NUMS_STRIPPED);
ECase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
ECase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
ECase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
ECase(IMAGE_FILE_BYTES_REVERSED_LO);
ECase(IMAGE_FILE_32BIT_MACHINE);
ECase(IMAGE_FILE_DEBUG_STRIPPED);
ECase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
ECase(IMAGE_FILE_NET_RUN_FROM_SWAP);
ECase(IMAGE_FILE_SYSTEM);
ECase(IMAGE_FILE_DLL);
ECase(IMAGE_FILE_UP_SYSTEM_ONLY);
ECase(IMAGE_FILE_BYTES_REVERSED_HI);
}
};
template <> template <>
struct ScalarEnumerationTraits<COFF::SectionCharacteristics> { struct ScalarEnumerationTraits<COFF::SectionCharacteristics> {
static void enumeration(IO &IO, COFF::SectionCharacteristics &Value) { static void enumeration(IO &IO, COFF::SectionCharacteristics &Value) {
@ -605,6 +640,7 @@ template <>
struct MappingTraits<COFFYAML::Header> { struct MappingTraits<COFFYAML::Header> {
static void mapping(IO &IO, COFFYAML::Header &H) { static void mapping(IO &IO, COFFYAML::Header &H) {
IO.mapRequired("Machine", H.Machine); IO.mapRequired("Machine", H.Machine);
IO.mapOptional("Characteristics", H.Characteristics);
} }
}; };