[llvm] r351940 - [llvm-objdump] - Split disassembleObject() into two methods. NFCI.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 23 02:33:27 PST 2019
Author: grimar
Date: Wed Jan 23 02:33:26 2019
New Revision: 351940
URL: http://llvm.org/viewvc/llvm-project?rev=351940&view=rev
Log:
[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
Modified:
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=351940&r1=351939&r2=351940&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jan 23 02:33:26 2019
@@ -885,66 +885,13 @@ getRelocsMap(llvm::object::ObjectFile co
return Ret;
}
-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));
-
- StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": " :
- "\t\t\t%08" PRIx64 ": ";
-
- SourcePrinter SP(Obj, TheTarget->getName());
+static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
+ MCContext &Ctx, MCDisassembler *DisAsm,
+ const MCInstrAnalysis *MIA, MCInstPrinter *IP,
+ const MCSubtargetInfo *STI, PrettyPrinter &PIP,
+ SourcePrinter &SP, bool InlineRelocs) {
+ StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": "
+ : "\t\t\t%08" PRIx64 ": ";
std::map<SectionRef, std::vector<RelocationRef>> RelocMap;
if (InlineRelocs)
@@ -1418,6 +1365,68 @@ static void disassembleObject(const Obje
}
}
+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) {
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
"%08" PRIx64;
More information about the llvm-commits
mailing list