1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[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
This commit is contained in:
diggerlin 2020-04-07 11:33:31 -04:00
parent a3ab90cba3
commit a53a69c279
2 changed files with 11 additions and 11 deletions

View File

@ -130,6 +130,8 @@ struct XCOFFStringTable {
struct XCOFFCsectAuxEnt32 { struct XCOFFCsectAuxEnt32 {
static constexpr uint8_t SymbolTypeMask = 0x07; static constexpr uint8_t SymbolTypeMask = 0x07;
static constexpr uint8_t SymbolAlignmentMask = 0xF8;
static constexpr size_t SymbolAlignmentBitOffset = 3;
support::ubig32_t support::ubig32_t
SectionOrLength; // If the symbol type is XTY_SD or XTY_CM, the csect SectionOrLength; // If the symbol type is XTY_SD or XTY_CM, the csect
@ -144,9 +146,14 @@ struct XCOFFCsectAuxEnt32 {
support::ubig32_t StabInfoIndex; support::ubig32_t StabInfoIndex;
support::ubig16_t StabSectNum; support::ubig16_t StabSectNum;
uint16_t getAlignmentLog2() const {
return (SymbolAlignmentAndType & SymbolAlignmentMask) >>
SymbolAlignmentBitOffset;
}
uint8_t getSymbolType() const { uint8_t getSymbolType() const {
return SymbolAlignmentAndType & SymbolTypeMask; return SymbolAlignmentAndType & SymbolTypeMask;
}; }
bool isLabel() const { return getSymbolType() == XCOFF::XTY_LD; } bool isLabel() const { return getSymbolType() == XCOFF::XTY_LD; }
}; };

View File

@ -22,11 +22,6 @@ using namespace object;
namespace { namespace {
class XCOFFDumper : public ObjDumper { class XCOFFDumper : public ObjDumper {
enum {
SymbolTypeMask = 0x07,
SymbolAlignmentMask = 0xF8,
SymbolAlignmentBitOffset = 3
};
public: public:
XCOFFDumper(const XCOFFObjectFile &Obj, ScopedPrinter &Writer) XCOFFDumper(const XCOFFObjectFile &Obj, ScopedPrinter &Writer)
@ -211,17 +206,15 @@ void XCOFFDumper::printCsectAuxEnt32(const XCOFFCsectAuxEnt32 *AuxEntPtr) {
DictScope SymDs(W, "CSECT Auxiliary Entry"); DictScope SymDs(W, "CSECT Auxiliary Entry");
W.printNumber("Index", W.printNumber("Index",
Obj.getSymbolIndex(reinterpret_cast<uintptr_t>(AuxEntPtr))); Obj.getSymbolIndex(reinterpret_cast<uintptr_t>(AuxEntPtr)));
if ((AuxEntPtr->SymbolAlignmentAndType & SymbolTypeMask) == XCOFF::XTY_LD) if (AuxEntPtr->isLabel())
W.printNumber("ContainingCsectSymbolIndex", AuxEntPtr->SectionOrLength); W.printNumber("ContainingCsectSymbolIndex", AuxEntPtr->SectionOrLength);
else else
W.printNumber("SectionLen", AuxEntPtr->SectionOrLength); W.printNumber("SectionLen", AuxEntPtr->SectionOrLength);
W.printHex("ParameterHashIndex", AuxEntPtr->ParameterHashIndex); W.printHex("ParameterHashIndex", AuxEntPtr->ParameterHashIndex);
W.printHex("TypeChkSectNum", AuxEntPtr->TypeChkSectNum); W.printHex("TypeChkSectNum", AuxEntPtr->TypeChkSectNum);
// Print out symbol alignment and type. // Print out symbol alignment and type.
W.printNumber("SymbolAlignmentLog2", W.printNumber("SymbolAlignmentLog2", AuxEntPtr->getAlignmentLog2());
(AuxEntPtr->SymbolAlignmentAndType & SymbolAlignmentMask) >> W.printEnum("SymbolType", AuxEntPtr->getSymbolType(),
SymbolAlignmentBitOffset);
W.printEnum("SymbolType", AuxEntPtr->SymbolAlignmentAndType & SymbolTypeMask,
makeArrayRef(CsectSymbolTypeClass)); makeArrayRef(CsectSymbolTypeClass));
W.printEnum("StorageMappingClass", W.printEnum("StorageMappingClass",
static_cast<uint8_t>(AuxEntPtr->StorageMappingClass), static_cast<uint8_t>(AuxEntPtr->StorageMappingClass),