forked from OSchip/llvm-project
[llvm-objdump] - Split disassembleObject() into two methods. NFCI.
Currently, disassembleObject() is a ~550 lines length function. This patch splits it into two, where first do all helper objects initializations and calls the second which does all the rest job. This is a straightforward split. Differential revision: https://reviews.llvm.org/D57020 llvm-svn: 351940
This commit is contained in:
parent
6046d087c5
commit
bcbe98bcb9
|
@ -885,66 +885,13 @@ getRelocsMap(llvm::object::ObjectFile const &Obj) {
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
|
||||||
if (StartAddress > StopAddress)
|
MCContext &Ctx, MCDisassembler *DisAsm,
|
||||||
error("Start address should be less than stop address");
|
const MCInstrAnalysis *MIA, MCInstPrinter *IP,
|
||||||
|
const MCSubtargetInfo *STI, PrettyPrinter &PIP,
|
||||||
const Target *TheTarget = getTarget(Obj);
|
SourcePrinter &SP, bool InlineRelocs) {
|
||||||
|
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": "
|
||||||
// Package up features to be passed to target/subtarget
|
: "\t\t\t%08" PRIx64 ": ";
|
||||||
SubtargetFeatures Features = Obj->getFeatures();
|
|
||||||
if (!MAttrs.empty())
|
|
||||||
for (unsigned I = 0; I != MAttrs.size(); ++I)
|
|
||||||
Features.AddFeature(MAttrs[I]);
|
|
||||||
|
|
||||||
std::unique_ptr<const MCRegisterInfo> MRI(
|
|
||||||
TheTarget->createMCRegInfo(TripleName));
|
|
||||||
if (!MRI)
|
|
||||||
report_error(Obj->getFileName(), "no register info for target " +
|
|
||||||
TripleName);
|
|
||||||
|
|
||||||
// Set up disassembler.
|
|
||||||
std::unique_ptr<const MCAsmInfo> AsmInfo(
|
|
||||||
TheTarget->createMCAsmInfo(*MRI, TripleName));
|
|
||||||
if (!AsmInfo)
|
|
||||||
report_error(Obj->getFileName(), "no assembly info for target " +
|
|
||||||
TripleName);
|
|
||||||
std::unique_ptr<const MCSubtargetInfo> STI(
|
|
||||||
TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
|
|
||||||
if (!STI)
|
|
||||||
report_error(Obj->getFileName(), "no subtarget info for target " +
|
|
||||||
TripleName);
|
|
||||||
std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
|
|
||||||
if (!MII)
|
|
||||||
report_error(Obj->getFileName(), "no instruction info for target " +
|
|
||||||
TripleName);
|
|
||||||
MCObjectFileInfo MOFI;
|
|
||||||
MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
|
|
||||||
// FIXME: for now initialize MCObjectFileInfo with default values
|
|
||||||
MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx);
|
|
||||||
|
|
||||||
std::unique_ptr<MCDisassembler> DisAsm(
|
|
||||||
TheTarget->createMCDisassembler(*STI, Ctx));
|
|
||||||
if (!DisAsm)
|
|
||||||
report_error(Obj->getFileName(), "no disassembler for target " +
|
|
||||||
TripleName);
|
|
||||||
|
|
||||||
std::unique_ptr<const MCInstrAnalysis> MIA(
|
|
||||||
TheTarget->createMCInstrAnalysis(MII.get()));
|
|
||||||
|
|
||||||
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
|
|
||||||
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
|
|
||||||
Triple(TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
|
|
||||||
if (!IP)
|
|
||||||
report_error(Obj->getFileName(), "no instruction printer for target " +
|
|
||||||
TripleName);
|
|
||||||
IP->setPrintImmHex(PrintImmHex);
|
|
||||||
PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
|
|
||||||
|
|
||||||
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": " :
|
|
||||||
"\t\t\t%08" PRIx64 ": ";
|
|
||||||
|
|
||||||
SourcePrinter SP(Obj, TheTarget->getName());
|
|
||||||
|
|
||||||
std::map<SectionRef, std::vector<RelocationRef>> RelocMap;
|
std::map<SectionRef, std::vector<RelocationRef>> RelocMap;
|
||||||
if (InlineRelocs)
|
if (InlineRelocs)
|
||||||
|
@ -1418,6 +1365,68 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
||||||
|
if (StartAddress > StopAddress)
|
||||||
|
error("Start address should be less than stop address");
|
||||||
|
|
||||||
|
const Target *TheTarget = getTarget(Obj);
|
||||||
|
|
||||||
|
// Package up features to be passed to target/subtarget
|
||||||
|
SubtargetFeatures Features = Obj->getFeatures();
|
||||||
|
if (!MAttrs.empty())
|
||||||
|
for (unsigned I = 0; I != MAttrs.size(); ++I)
|
||||||
|
Features.AddFeature(MAttrs[I]);
|
||||||
|
|
||||||
|
std::unique_ptr<const MCRegisterInfo> MRI(
|
||||||
|
TheTarget->createMCRegInfo(TripleName));
|
||||||
|
if (!MRI)
|
||||||
|
report_error(Obj->getFileName(),
|
||||||
|
"no register info for target " + TripleName);
|
||||||
|
|
||||||
|
// Set up disassembler.
|
||||||
|
std::unique_ptr<const MCAsmInfo> AsmInfo(
|
||||||
|
TheTarget->createMCAsmInfo(*MRI, TripleName));
|
||||||
|
if (!AsmInfo)
|
||||||
|
report_error(Obj->getFileName(),
|
||||||
|
"no assembly info for target " + TripleName);
|
||||||
|
std::unique_ptr<const MCSubtargetInfo> STI(
|
||||||
|
TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
|
||||||
|
if (!STI)
|
||||||
|
report_error(Obj->getFileName(),
|
||||||
|
"no subtarget info for target " + TripleName);
|
||||||
|
std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
|
||||||
|
if (!MII)
|
||||||
|
report_error(Obj->getFileName(),
|
||||||
|
"no instruction info for target " + TripleName);
|
||||||
|
MCObjectFileInfo MOFI;
|
||||||
|
MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
|
||||||
|
// FIXME: for now initialize MCObjectFileInfo with default values
|
||||||
|
MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx);
|
||||||
|
|
||||||
|
std::unique_ptr<MCDisassembler> DisAsm(
|
||||||
|
TheTarget->createMCDisassembler(*STI, Ctx));
|
||||||
|
if (!DisAsm)
|
||||||
|
report_error(Obj->getFileName(),
|
||||||
|
"no disassembler for target " + TripleName);
|
||||||
|
|
||||||
|
std::unique_ptr<const MCInstrAnalysis> MIA(
|
||||||
|
TheTarget->createMCInstrAnalysis(MII.get()));
|
||||||
|
|
||||||
|
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
|
||||||
|
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
|
||||||
|
Triple(TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
|
||||||
|
if (!IP)
|
||||||
|
report_error(Obj->getFileName(),
|
||||||
|
"no instruction printer for target " + TripleName);
|
||||||
|
IP->setPrintImmHex(PrintImmHex);
|
||||||
|
|
||||||
|
PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
|
||||||
|
SourcePrinter SP(Obj, TheTarget->getName());
|
||||||
|
|
||||||
|
disassembleObject(TheTarget, Obj, Ctx, DisAsm.get(), MIA.get(), IP.get(),
|
||||||
|
STI.get(), PIP, SP, InlineRelocs);
|
||||||
|
}
|
||||||
|
|
||||||
void llvm::printRelocations(const ObjectFile *Obj) {
|
void llvm::printRelocations(const ObjectFile *Obj) {
|
||||||
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
|
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
|
||||||
"%08" PRIx64;
|
"%08" PRIx64;
|
||||||
|
|
Loading…
Reference in New Issue