[PATCH] D159539: [NFC] refactor demangle of llvm-nm
Digger Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 21 13:28:15 PDT 2023
DiggerLin created this revision.
DiggerLin added reviewers: jhenderson, hubert.reinterpretcast, MaskRay.
Herald added a subscriber: hiraditya.
Herald added a project: All.
DiggerLin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
refactor demangle of llvm-nm .
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159539
Files:
llvm/lib/Demangle/Demangle.cpp
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -629,30 +629,6 @@
outs() << format(" %02x", NType);
}
-static std::optional<std::string> demangle(StringRef Name) {
- std::string Demangled;
- if (nonMicrosoftDemangle(Name, Demangled))
- return Demangled;
- return std::nullopt;
-}
-
-static std::optional<std::string> demangleXCOFF(StringRef Name) {
- if (Name.empty() || Name[0] != '.')
- return demangle(Name);
-
- Name = Name.drop_front();
- std::optional<std::string> DemangledName = demangle(Name);
- if (DemangledName)
- return "." + *DemangledName;
- return std::nullopt;
-}
-
-static std::optional<std::string> demangleMachO(StringRef Name) {
- if (!Name.empty() && Name[0] == '_')
- Name = Name.drop_front();
- return demangle(Name);
-}
-
static bool symbolIsDefined(const NMSymbol &Sym) {
return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v';
}
@@ -822,15 +798,8 @@
std::string Name = S.Name;
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
- if (Demangle) {
- function_ref<std::optional<std::string>(StringRef)> Fn = ::demangle;
- if (Obj.isXCOFF())
- Fn = demangleXCOFF;
- if (Obj.isMachO())
- Fn = demangleMachO;
- if (std::optional<std::string> Opt = Fn(S.Name))
- Name = *Opt;
- }
+ if (Demangle)
+ Name = llvm::demangle(Name);
if (PrintFileName)
writeFileName(outs(), ArchiveName, ArchitectureName);
Index: llvm/lib/Demangle/Demangle.cpp
===================================================================
--- llvm/lib/Demangle/Demangle.cpp
+++ llvm/lib/Demangle/Demangle.cpp
@@ -27,6 +27,10 @@
nonMicrosoftDemangle(MangledName.substr(1), Result))
return Result;
+ if (starts_with(MangledName, '.') &&
+ nonMicrosoftDemangle(MangledName.substr(1), Result))
+ return "." + Result;
+
if (char *Demangled = microsoftDemangle(MangledName, nullptr, nullptr)) {
Result = Demangled;
std::free(Demangled);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159539.557197.patch
Type: text/x-patch
Size: 2128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230921/adad2cb7/attachment.bin>
More information about the llvm-commits
mailing list