From a53a69c279eb8553095646725b27a40d9c815bb8 Mon Sep 17 00:00:00 2001 From: diggerlin Date: Tue, 7 Apr 2020 11:33:31 -0400 Subject: [PATCH] [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 --- include/llvm/Object/XCOFFObjectFile.h | 9 ++++++++- tools/llvm-readobj/XCOFFDumper.cpp | 13 +++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/llvm/Object/XCOFFObjectFile.h b/include/llvm/Object/XCOFFObjectFile.h index 4e2ad81ecfd..84596b7a97f 100644 --- a/include/llvm/Object/XCOFFObjectFile.h +++ b/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/tools/llvm-readobj/XCOFFDumper.cpp b/tools/llvm-readobj/XCOFFDumper.cpp index 1f940366559..dd62f98d959 100644 --- a/tools/llvm-readobj/XCOFFDumper.cpp +++ b/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(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(AuxEntPtr->StorageMappingClass),