32
32
33
33
#include < iostream>
34
34
35
+ using namespace swift ::Demangle;
36
+
35
37
static llvm::cl::opt<bool >
36
38
ExpandMode (" expand" ,
37
39
llvm::cl::desc (" Expand mode (show node structure of the demangling)" ));
@@ -44,6 +46,10 @@ static llvm::cl::opt<bool>
44
46
TreeOnly (" tree-only" ,
45
47
llvm::cl::desc (" Tree-only mode (do not show the demangled string)" ));
46
48
49
+ static llvm::cl::opt<bool >
50
+ StripSpecialization (" strip-specialization" ,
51
+ llvm::cl::desc (" Remangle the origin of a specialized function" ));
52
+
47
53
static llvm::cl::opt<bool >
48
54
RemangleMode (" test-remangle" ,
49
55
llvm::cl::desc (" Remangle test mode (show the remangled string)" ));
@@ -82,6 +88,22 @@ static llvm::StringRef substrAfter(llvm::StringRef whole,
82
88
return whole.substr ((part.data () - whole.data ()) + part.size ());
83
89
}
84
90
91
+ static void stripSpecialization (NodePointer Node) {
92
+ if (Node->getKind () != Node::Kind::Global)
93
+ return ;
94
+ switch (Node->getFirstChild ()->getKind ()) {
95
+ case Node::Kind::FunctionSignatureSpecialization:
96
+ case Node::Kind::GenericSpecialization:
97
+ case Node::Kind::GenericSpecializationNotReAbstracted:
98
+ case Node::Kind::GenericPartialSpecialization:
99
+ case Node::Kind::GenericPartialSpecializationNotReAbstracted:
100
+ Node->removeChildAt (0 );
101
+ break ;
102
+ default :
103
+ break ;
104
+ }
105
+ }
106
+
85
107
static void demangle (llvm::raw_ostream &os, llvm::StringRef name,
86
108
swift::Demangle::Context &DCtx,
87
109
const swift::Demangle::DemangleOptions &options) {
@@ -142,6 +164,12 @@ static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
142
164
llvm::outs () << remangled;
143
165
return ;
144
166
}
167
+ if (StripSpecialization) {
168
+ stripSpecialization (pointer);
169
+ std::string remangled = swift::Demangle::mangleNode (pointer);
170
+ llvm::outs () << remangled;
171
+ return ;
172
+ }
145
173
std::string string = swift::Demangle::nodeToString (pointer, options);
146
174
if (!CompactMode)
147
175
llvm::outs () << name << " ---> " ;
0 commit comments