[llvm] 3aa0849 - [NFC][XCOFF] refactor readobj/XCOFFDumper.cpp
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 08:33:55 PDT 2020
Author: diggerlin
Date: 2020-04-07T11:33:31-04:00
New Revision: 3aa084947e5fad795f45f0907d3e436db1a19757
URL: https://github.com/llvm/llvm-project/commit/3aa084947e5fad795f45f0907d3e436db1a19757
DIFF: https://github.com/llvm/llvm-project/commit/3aa084947e5fad795f45f0907d3e436db1a19757.diff
LOG: [NFC][XCOFF] refactor readobj/XCOFFDumper.cpp
SUMMARY:
refactor readobj/XCOFFDumper.cpp with helper function getAlignmentLog2() , getSymbolType(), isLabel().
Reviewers: Hubert Tong, James Henderson
Subscribers: rupprecht, seiyai,hiradityu
Differential Revision: https://reviews.llvm.org/D77562
Added:
Modified:
llvm/include/llvm/Object/XCOFFObjectFile.h
llvm/tools/llvm-readobj/XCOFFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h
index 4e2ad81ecfd7..84596b7a97fc 100644
--- a/llvm/include/llvm/Object/XCOFFObjectFile.h
+++ b/llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -130,6 +130,8 @@ struct XCOFFStringTable {
struct XCOFFCsectAuxEnt32 {
static constexpr uint8_t SymbolTypeMask = 0x07;
+ static constexpr uint8_t SymbolAlignmentMask = 0xF8;
+ static constexpr size_t SymbolAlignmentBitOffset = 3;
support::ubig32_t
SectionOrLength; // If the symbol type is XTY_SD or XTY_CM, the csect
@@ -144,9 +146,14 @@ struct XCOFFCsectAuxEnt32 {
support::ubig32_t StabInfoIndex;
support::ubig16_t StabSectNum;
+ uint16_t getAlignmentLog2() const {
+ return (SymbolAlignmentAndType & SymbolAlignmentMask) >>
+ SymbolAlignmentBitOffset;
+ }
+
uint8_t getSymbolType() const {
return SymbolAlignmentAndType & SymbolTypeMask;
- };
+ }
bool isLabel() const { return getSymbolType() == XCOFF::XTY_LD; }
};
diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index 1f9403665594..dd62f98d9595 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -22,11 +22,6 @@ using namespace object;
namespace {
class XCOFFDumper : public ObjDumper {
- enum {
- SymbolTypeMask = 0x07,
- SymbolAlignmentMask = 0xF8,
- SymbolAlignmentBitOffset = 3
- };
public:
XCOFFDumper(const XCOFFObjectFile &Obj, ScopedPrinter &Writer)
@@ -211,17 +206,15 @@ void XCOFFDumper::printCsectAuxEnt32(const XCOFFCsectAuxEnt32 *AuxEntPtr) {
DictScope SymDs(W, "CSECT Auxiliary Entry");
W.printNumber("Index",
Obj.getSymbolIndex(reinterpret_cast<uintptr_t>(AuxEntPtr)));
- if ((AuxEntPtr->SymbolAlignmentAndType & SymbolTypeMask) == XCOFF::XTY_LD)
+ if (AuxEntPtr->isLabel())
W.printNumber("ContainingCsectSymbolIndex", AuxEntPtr->SectionOrLength);
else
W.printNumber("SectionLen", AuxEntPtr->SectionOrLength);
W.printHex("ParameterHashIndex", AuxEntPtr->ParameterHashIndex);
W.printHex("TypeChkSectNum", AuxEntPtr->TypeChkSectNum);
// Print out symbol alignment and type.
- W.printNumber("SymbolAlignmentLog2",
- (AuxEntPtr->SymbolAlignmentAndType & SymbolAlignmentMask) >>
- SymbolAlignmentBitOffset);
- W.printEnum("SymbolType", AuxEntPtr->SymbolAlignmentAndType & SymbolTypeMask,
+ W.printNumber("SymbolAlignmentLog2", AuxEntPtr->getAlignmentLog2());
+ W.printEnum("SymbolType", AuxEntPtr->getSymbolType(),
makeArrayRef(CsectSymbolTypeClass));
W.printEnum("StorageMappingClass",
static_cast<uint8_t>(AuxEntPtr->StorageMappingClass),
More information about the llvm-commits
mailing list