[lld] 73d8d83 - [ARM] Change ARMAttributeParser::Parse to use support::endianness and simplify
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 21 11:05:41 PST 2020
Author: Fangrui Song
Date: 2020-02-21T11:05:33-08:00
New Revision: 73d8d83a6d9adac3216ea8a39eb502b2a5c4d083
URL: https://github.com/llvm/llvm-project/commit/73d8d83a6d9adac3216ea8a39eb502b2a5c4d083
DIFF: https://github.com/llvm/llvm-project/commit/73d8d83a6d9adac3216ea8a39eb502b2a5c4d083.diff
LOG: [ARM] Change ARMAttributeParser::Parse to use support::endianness and simplify
Added:
Modified:
lld/ELF/InputFiles.cpp
llvm/include/llvm/Object/ELFObjectFile.h
llvm/include/llvm/Support/ARMAttributeParser.h
llvm/lib/Support/ARMAttributeParser.cpp
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/unittests/Support/ARMAttributeParser.cpp
Removed:
################################################################################
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index b3f8984240d2..c37436e43738 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -842,7 +842,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
break;
ARMAttributeParser attributes;
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(&sec));
- attributes.Parse(contents, /*isLittle*/ config->ekind == ELF32LEKind);
+ attributes.parse(contents, config->ekind == ELF32LEKind ? support::little
+ : support::big);
updateSupportedARMFeatures(attributes);
updateARMVFPArgs(attributes, this);
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 8a68e49477fd..7effce6ab6c7 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -380,7 +380,7 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1)
return Error::success();
- Attributes.Parse(Contents, ELFT::TargetEndianness == support::little);
+ Attributes.parse(Contents, ELFT::TargetEndianness);
break;
}
}
diff --git a/llvm/include/llvm/Support/ARMAttributeParser.h b/llvm/include/llvm/Support/ARMAttributeParser.h
index f6c39abb4f21..df7417f7a383 100644
--- a/llvm/include/llvm/Support/ARMAttributeParser.h
+++ b/llvm/include/llvm/Support/ARMAttributeParser.h
@@ -11,6 +11,7 @@
#include "ARMBuildAttributes.h"
#include "ScopedPrinter.h"
+#include "llvm/Support/Endian.h"
#include <map>
@@ -124,7 +125,7 @@ class ARMAttributeParser {
ARMAttributeParser() : SW(nullptr) { }
- void Parse(ArrayRef<uint8_t> Section, bool isLittle);
+ void parse(ArrayRef<uint8_t> Section, support::endianness E);
bool hasAttribute(unsigned Tag) const {
return Attributes.count(Tag);
diff --git a/llvm/lib/Support/ARMAttributeParser.cpp b/llvm/lib/Support/ARMAttributeParser.cpp
index 8a89f4c45fb9..812b160c2e33 100644
--- a/llvm/lib/Support/ARMAttributeParser.cpp
+++ b/llvm/lib/Support/ARMAttributeParser.cpp
@@ -695,14 +695,14 @@ void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) {
}
}
-void ARMAttributeParser::Parse(ArrayRef<uint8_t> Section, bool isLittle) {
+void ARMAttributeParser::parse(ArrayRef<uint8_t> Section,
+ support::endianness E) {
uint64_t Offset = 1;
unsigned SectionNumber = 0;
while (Offset < Section.size()) {
- uint32_t SectionLength = isLittle ?
- support::endian::read32le(Section.data() + Offset) :
- support::endian::read32be(Section.data() + Offset);
+ uint32_t SectionLength =
+ support::endian::read32(Section.data() + Offset, E);
if (SW) {
SW->startLine() << "Section " << ++SectionNumber << " {\n";
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 794c4630699a..93ec47751b6b 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2688,7 +2688,7 @@ template <> void ELFDumper<ELF32LE>::printAttributes() {
if (Contents.size() == 1)
continue;
- ARMAttributeParser(&W).Parse(Contents, true);
+ ARMAttributeParser(&W).parse(Contents, support::little);
}
}
diff --git a/llvm/unittests/Support/ARMAttributeParser.cpp b/llvm/unittests/Support/ARMAttributeParser.cpp
index 6781acc59a72..adb36de8e66b 100644
--- a/llvm/unittests/Support/ARMAttributeParser.cpp
+++ b/llvm/unittests/Support/ARMAttributeParser.cpp
@@ -34,7 +34,7 @@ bool testBuildAttr(unsigned Tag, unsigned Value,
reinterpret_cast<const uint8_t*>(OS.str().c_str()), OS.str().size());
ARMAttributeParser Parser;
- Parser.Parse(Bytes, true);
+ Parser.parse(Bytes, support::little);
return (Parser.hasAttribute(ExpectedTag) &&
Parser.getAttributeValue(ExpectedTag) == ExpectedValue);
More information about the llvm-commits
mailing list