Skip to content

Commit c6d0eb1

Browse files
committed
Closes #33
1 parent 3177894 commit c6d0eb1

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h

+3
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ struct FunctionSymbolNode : public SymbolNode {
623623
FunctionSignatureNode *Signature = nullptr;
624624
};
625625

626+
std::string
627+
getCallingConventionNameByDemangledName(std::string_view DemangledName);
628+
626629
} // namespace ms_demangle
627630
} // namespace llvm
628631

llvm/lib/Demangle/Demangle.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "llvm/Demangle/Demangle.h"
14+
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
1415
#include "llvm/Demangle/StringViewExtras.h"
1516
#include <cstdlib>
1617
#include <string_view>
@@ -19,11 +20,21 @@ using llvm::itanium_demangle::starts_with;
1920

2021
/// demangle a string to get the function name.
2122
std::string llvm::demangleGetFunctionName(std::string_view MangledName) {
23+
std::string Result;
24+
if (nonMicrosoftDemangle(MangledName, Result))
25+
return Result;
26+
2227
std::string DemangledStr = llvm::demangle(MangledName);
28+
std::string CCName =
29+
llvm::ms_demangle::getCallingConventionNameByDemangledName(DemangledStr);
30+
if (CCName.empty())
31+
return DemangledStr;
32+
2333
size_t StartIndex = DemangledStr.find("(");
2434
if (StartIndex != std::string::npos) {
25-
size_t EndIndex = DemangledStr.rfind(" ", StartIndex);
35+
size_t EndIndex = DemangledStr.find(CCName + " ");
2636
if (EndIndex != std::string::npos) {
37+
EndIndex += CCName.size();
2738
DemangledStr =
2839
DemangledStr.substr(EndIndex + 1, StartIndex - EndIndex - 1);
2940
}

llvm/lib/Demangle/MicrosoftDemangleNodes.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ static void outputCallingConvention(OutputBuffer &OB, CallingConv CC) {
117117
}
118118
}
119119

120+
std::string llvm::ms_demangle::getCallingConventionNameByDemangledName(
121+
std::string_view DemangledName) {
122+
if (DemangledName.find("__cdecl") != std::string::npos)
123+
return "__cdecl";
124+
if (DemangledName.find("__fastcall") != std::string::npos)
125+
return "__fastcall";
126+
if (DemangledName.find("__stdcall") != std::string::npos)
127+
return "__stdcall";
128+
if (DemangledName.find("__thiscall") != std::string::npos)
129+
return "__thiscall";
130+
if (DemangledName.find("__pascal") != std::string::npos)
131+
return "__pascal";
132+
if (DemangledName.find("__regcall") != std::string::npos)
133+
return "__regcall";
134+
if (DemangledName.find("__eabi") != std::string::npos)
135+
return "__eabi";
136+
if (DemangledName.find("__vectorcall") != std::string::npos)
137+
return "__vectorcall";
138+
if (DemangledName.find("__clrcall") != std::string::npos)
139+
return "__clrcall";
140+
return "";
141+
}
142+
120143
std::string Node::toString(OutputFlags Flags) const {
121144
OutputBuffer OB;
122145
this->output(OB, Flags);

0 commit comments

Comments
 (0)