From 770ceb69ba997d9a58cc258490640960911e7c11 Mon Sep 17 00:00:00 2001 From: Sam Parker Date: Fri, 13 Jan 2017 11:04:21 +0000 Subject: [ARM] Enable objdump to construct triple for ARM Now that The ARMAttributeParser has been moved into the library, it has been modified so that it can parse the attributes without printing them and stores them in a map. ELFObjectFile now queries the attributes to fill out the architecture details of a provided triple for 'arm' and 'thumb' targets. llvm-objdump uses this new functionality. Differential Revision: https://reviews.llvm.org/D28281 llvm-svn: 291898 --- llvm/lib/Support/ARMAttributeParser.cpp | 121 +++++++++++++++++++------------- 1 file changed, 73 insertions(+), 48 deletions(-) (limited to 'llvm/lib/Support/ARMAttributeParser.cpp') diff --git a/llvm/lib/Support/ARMAttributeParser.cpp b/llvm/lib/Support/ARMAttributeParser.cpp index 792510e6b84..5d9b2306b9a 100644 --- a/llvm/lib/Support/ARMAttributeParser.cpp +++ b/llvm/lib/Support/ARMAttributeParser.cpp @@ -89,32 +89,43 @@ StringRef ARMAttributeParser::ParseString(const uint8_t *Data, void ARMAttributeParser::IntegerAttribute(AttrType Tag, const uint8_t *Data, uint32_t &Offset) { - SW.printNumber(ARMBuildAttrs::AttrTypeAsString(Tag), - ParseInteger(Data, Offset)); + + uint64_t Value = ParseInteger(Data, Offset); + Attributes.insert(std::make_pair(Tag, Value)); + + if (SW) + SW->printNumber(ARMBuildAttrs::AttrTypeAsString(Tag), Value); } void ARMAttributeParser::StringAttribute(AttrType Tag, const uint8_t *Data, uint32_t &Offset) { StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false); - - DictScope AS(SW, "Attribute"); - SW.printNumber("Tag", Tag); - if (!TagName.empty()) - SW.printString("TagName", TagName); - SW.printString("Value", ParseString(Data, Offset)); + StringRef ValueDesc = ParseString(Data, Offset); + + if (SW) { + DictScope AS(*SW, "Attribute"); + SW->printNumber("Tag", Tag); + if (!TagName.empty()) + SW->printString("TagName", TagName); + SW->printString("Value", ValueDesc); + } } void ARMAttributeParser::PrintAttribute(unsigned Tag, unsigned Value, StringRef ValueDesc) { - StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false); - - DictScope AS(SW, "Attribute"); - SW.printNumber("Tag", Tag); - SW.printNumber("Value", Value); - if (!TagName.empty()) - SW.printString("TagName", TagName); - if (!ValueDesc.empty()) - SW.printString("Description", ValueDesc); + Attributes.insert(std::make_pair(Tag, Value)); + + if (SW) { + StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, + /*TagPrefix*/false); + DictScope AS(*SW, "Attribute"); + SW->printNumber("Tag", Tag); + SW->printNumber("Value", Value); + if (!TagName.empty()) + SW->printString("TagName", TagName); + if (!ValueDesc.empty()) + SW->printString("Description", ValueDesc); + } } void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data, @@ -449,20 +460,22 @@ void ARMAttributeParser::compatibility(AttrType Tag, const uint8_t *Data, uint64_t Integer = ParseInteger(Data, Offset); StringRef String = ParseString(Data, Offset); - DictScope AS(SW, "Attribute"); - SW.printNumber("Tag", Tag); - SW.startLine() << "Value: " << Integer << ", " << String << '\n'; - SW.printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false)); - switch (Integer) { - case 0: - SW.printString("Description", StringRef("No Specific Requirements")); - break; - case 1: - SW.printString("Description", StringRef("AEABI Conformant")); - break; - default: - SW.printString("Description", StringRef("AEABI Non-Conformant")); - break; + if (SW) { + DictScope AS(*SW, "Attribute"); + SW->printNumber("Tag", Tag); + SW->startLine() << "Value: " << Integer << ", " << String << '\n'; + SW->printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false)); + switch (Integer) { + case 0: + SW->printString("Description", StringRef("No Specific Requirements")); + break; + case 1: + SW->printString("Description", StringRef("AEABI Conformant")); + break; + default: + SW->printString("Description", StringRef("AEABI Non-Conformant")); + break; + } } } @@ -604,27 +617,33 @@ void ARMAttributeParser::ParseAttributeList(const uint8_t *Data, void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) { uint32_t Offset = sizeof(uint32_t); /* SectionLength */ - SW.printNumber("SectionLength", Length); - const char *VendorName = reinterpret_cast(Data + Offset); size_t VendorNameLength = std::strlen(VendorName); - SW.printString("Vendor", StringRef(VendorName, VendorNameLength)); Offset = Offset + VendorNameLength + 1; - if (StringRef(VendorName, VendorNameLength).lower() != "aeabi") + if (SW) { + SW->printNumber("SectionLength", Length); + SW->printString("Vendor", StringRef(VendorName, VendorNameLength)); + } + + if (StringRef(VendorName, VendorNameLength).lower() != "aeabi") { return; + } while (Offset < Length) { /// Tag_File | Tag_Section | Tag_Symbol uleb128:byte-size uint8_t Tag = Data[Offset]; - SW.printEnum("Tag", Tag, makeArrayRef(TagNames)); Offset = Offset + sizeof(Tag); uint32_t Size = *reinterpret_cast(Data + Offset); - SW.printNumber("Size", Size); Offset = Offset + sizeof(Size); + if (SW) { + SW->printEnum("Tag", Tag, makeArrayRef(TagNames)); + SW->printNumber("Size", Size); + } + if (Size > Length) { errs() << "subsection length greater than section length\n"; return; @@ -651,31 +670,37 @@ void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) { return; } - DictScope ASS(SW, ScopeName); - - if (!Indicies.empty()) - SW.printList(IndexName, Indicies); + if (SW) { + DictScope ASS(*SW, ScopeName); + if (!Indicies.empty()) + SW->printList(IndexName, Indicies); + } ParseAttributeList(Data, Offset, Length); } } -void ARMAttributeParser::Parse(ArrayRef Section) { +void ARMAttributeParser::Parse(ArrayRef Section, bool isLittle) { size_t Offset = 1; unsigned SectionNumber = 0; while (Offset < Section.size()) { - uint32_t SectionLength = - *reinterpret_cast(Section.data() + Offset); + uint32_t SectionLength = isLittle ? + *reinterpret_cast(Section.data() + Offset) : + *reinterpret_cast(Section.data() + Offset); - SW.startLine() << "Section " << ++SectionNumber << " {\n"; - SW.indent(); + if (SW) { + SW->startLine() << "Section " << ++SectionNumber << " {\n"; + SW->indent(); + } ParseSubsection(Section.data() + Offset, SectionLength); Offset = Offset + SectionLength; - SW.unindent(); - SW.startLine() << "}\n"; + if (SW) { + SW->unindent(); + SW->startLine() << "}\n"; + } } } } -- cgit v1.2.3