[PATCH] D149093: [llvm-objdump] [NFC] Factor out DisassemblerTarget class.
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 3 00:16:18 PDT 2023
jhenderson added inline comments.
================
Comment at: llvm/tools/llvm-objdump/llvm-objdump.cpp:837-838
+ : TheTarget(TheTarget),
+ PrettyPrinter(&selectPrettyPrinter(Triple(TripleName))) {
+ RegisterInfo.reset(TheTarget->createMCRegInfo(TripleName));
+ if (!RegisterInfo)
----------------
As an alternative to my suggested inline edit, you could add a function that creates the relevant smart pointer and checks for the error before returning the pointer. You could then move most/all of the body of this class into the initialiser list. Something like the following rough code:
```
template <typename PtrTy, typename... ArgsTy>
PtrTy makePtrOrError(std::function<PtrTy(ArgsTy...)> Func, StringRef Message, ArgsTy... Args) {
PtrTy Ptr = Func(Args...);
if (!Ptr)
reportError(Message);
return Ptr;
}
DisassemblerTarget::DisassemblerTarget(...)
: ...
RegisterInfo(makePtrOrError(...)), AsmInfo(makePtrOrError(...)), /*etc*/{}
```
================
Comment at: llvm/tools/llvm-objdump/llvm-objdump.cpp:895
+ ObjectFileInfo(Other.ObjectFileInfo) {}
+
+} // namespace
----------------
Nit: don't need the new line at the end of the namespace IMHO.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149093/new/
https://reviews.llvm.org/D149093
More information about the llvm-commits
mailing list