This is an archive of the discontinued LLVM Phabricator instance.

[NFC][llvm-nm] refactor function dumpSymbolNamesFromFile
ClosedPublic

Authored by DiggerLin on Feb 16 2022, 1:28 PM.

Details

Summary

split the function into several small functions.
change the function like

static void dumpSymbolNamesFromFile(std::string &Filename) {

ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
    MemoryBuffer::getFileOrSTDIN(Filename);
if (error(BufferOrErr.getError(), Filename))
  return;

LLVMContext Context;
LLVMContext *ContextPtr = NoLLVMBitcode ? nullptr : &Context;
Expected<std::unique_ptr<Binary>> BinaryOrErr =
    createBinary(BufferOrErr.get()->getMemBufferRef(), ContextPtr);
if (!BinaryOrErr) {
  error(BinaryOrErr.takeError(), Filename);
  return;
}
Binary &Bin = *BinaryOrErr.get();
if (Archive *A = dyn_cast<Archive>(&Bin))
  dumpArchive(A, Filename, ContextPtr);
else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Bin))
  dumpMachOUniversalBinary(UB, Filename, ContextPtr);
else if (TapiUniversal *TU = dyn_cast<TapiUniversal>(&Bin))
  dumpTapiUniversal(TU, Filename);
else if (SymbolicFile *O = dyn_cast<SymbolicFile>(&Bin))
  dumpSymbolicFile(O, Filename);

}

Diff Detail

Event Timeline

DiggerLin created this revision.Feb 16 2022, 1:28 PM
DiggerLin requested review of this revision.Feb 16 2022, 1:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2022, 1:28 PM
MaskRay accepted this revision.Feb 16 2022, 8:39 PM

LGTM.

This revision is now accepted and ready to land.Feb 16 2022, 8:39 PM

Looks good, with one request though.

llvm/tools/llvm-nm/llvm-nm.cpp
2054

Might be worth a comment saying what the boolean return indicates.

DiggerLin updated this revision to Diff 409638.Feb 17 2022, 6:59 AM
DiggerLin marked an inline comment as done.
jhenderson accepted this revision.Feb 17 2022, 7:10 AM

Looks good, with the suggested comment rewrite.

llvm/tools/llvm-nm/llvm-nm.cpp
2054–2055

(and reflow as necesary).

I've taken the wording from a similar comment elsewhere.

This revision was landed with ongoing or failed builds.Feb 17 2022, 9:04 AM
This revision was automatically updated to reflect the committed changes.