29 constexpr
const char *itanium_demangle::FloatData<float>::spec;
30 constexpr
const char *itanium_demangle::FloatData<double>::spec;
31 constexpr
const char *itanium_demangle::FloatData<long double>::spec;
41 const char *t1 = first + 1;
43 if (std::isdigit(*t1))
45 else if (*t1 ==
'_') {
46 for (++t1; t1 != last && std::isdigit(*t1); ++t1)
48 if (t1 != last && *t1 ==
'_')
52 }
else if (std::isdigit(*first)) {
53 const char *t1 = first + 1;
54 for (; t1 != last && std::isdigit(*t1); ++t1)
67 bool PendingNewline =
false;
69 template<
typename NodeT>
static constexpr
bool wantsNewline(
const NodeT *) {
73 static constexpr
bool wantsNewline(...) {
return false; }
75 template<
typename ...Ts>
static bool anyWantNewline(Ts ...Vs) {
76 for (
bool B : {wantsNewline(Vs)...})
82 void printStr(
const char *S) { fprintf(stderr,
"%s", S); }
83 void print(StringView SV) {
84 fprintf(stderr,
"\"%.*s\"", (
int)SV.size(), SV.begin());
86 void print(
const Node *
N) {
88 N->visit(std::ref(*
this));
96 for (
const Node *N : A) {
108 void print(
bool B) { printStr(B ?
"true" :
"false"); }
111 typename std::enable_if<std::is_unsigned<T>::value>
::type print(
T N) {
112 fprintf(stderr,
"%llu", (
unsigned long long)N);
116 typename std::enable_if<std::is_signed<T>::value>
::type print(
T N) {
117 fprintf(stderr,
"%lld", (
long long)N);
123 return printStr(
"ReferenceKind::LValue");
125 return printStr(
"ReferenceKind::RValue");
131 return printStr(
"FunctionRefQual::FrefQualNone");
133 return printStr(
"FunctionRefQual::FrefQualLValue");
135 return printStr(
"FunctionRefQual::FrefQualRValue");
139 if (!Qs)
return printStr(
"QualNone");
145 for (QualName
Name : Names) {
149 if (Qs) printStr(
" | ");
156 return printStr(
"SpecialSubKind::allocator");
158 return printStr(
"SpecialSubKind::basic_string");
160 return printStr(
"SpecialSubKind::string");
162 return printStr(
"SpecialSubKind::istream");
164 return printStr(
"SpecialSubKind::ostream");
166 return printStr(
"SpecialSubKind::iostream");
172 return printStr(
"TemplateParamKind::Type");
174 return printStr(
"TemplateParamKind::NonType");
176 return printStr(
"TemplateParamKind::Template");
182 for (
unsigned I = 0;
I !=
Depth; ++
I)
184 PendingNewline =
false;
187 template<
typename T>
void printWithPendingNewline(
T V) {
190 PendingNewline =
true;
193 template<
typename T>
void printWithComma(
T V) {
194 if (PendingNewline || wantsNewline(V)) {
201 printWithPendingNewline(V);
204 struct CtorArgPrinter {
205 DumpVisitor &Visitor;
207 template<
typename T,
typename ...Rest>
void operator()(
T V, Rest ...Vs) {
208 if (Visitor.anyWantNewline(V, Vs...))
210 Visitor.printWithPendingNewline(V);
211 int PrintInOrder[] = { (Visitor.printWithComma(Vs), 0)..., 0 };
216 template<
typename NodeT>
void operator()(
const NodeT *Node) {
219 Node->match(CtorArgPrinter{*
this});
220 fprintf(stderr,
")");
224 void operator()(
const ForwardTemplateReference *Node) {
226 fprintf(stderr,
"ForwardTemplateReference(");
227 if (Node->Ref && !Node->Printing) {
228 Node->Printing =
true;
229 CtorArgPrinter{*
this}(Node->Ref);
230 Node->Printing =
false;
232 CtorArgPrinter{*
this}(Node->Index);
234 fprintf(stderr,
")");
248 class BumpPointerAllocator {
254 static constexpr
size_t AllocSize = 4096;
255 static constexpr
size_t UsableAllocSize = AllocSize -
sizeof(BlockMeta);
257 alignas(
long double)
char InitialBuffer[AllocSize];
258 BlockMeta* BlockList =
nullptr;
261 char* NewMeta =
static_cast<char *
>(std::malloc(AllocSize));
262 if (NewMeta ==
nullptr)
264 BlockList =
new (NewMeta) BlockMeta{BlockList, 0};
267 void* allocateMassive(
size_t NBytes) {
268 NBytes +=
sizeof(BlockMeta);
269 BlockMeta* NewMeta =
reinterpret_cast<BlockMeta*
>(std::malloc(NBytes));
270 if (NewMeta ==
nullptr)
272 BlockList->Next =
new (NewMeta) BlockMeta{BlockList->Next, 0};
273 return static_cast<void*
>(NewMeta + 1);
277 BumpPointerAllocator()
278 : BlockList(new (InitialBuffer) BlockMeta{
nullptr, 0}) {}
280 void* allocate(
size_t N) {
281 N = (N + 15u) & ~15u;
282 if (N + BlockList->Current >= UsableAllocSize) {
283 if (N > UsableAllocSize)
284 return allocateMassive(N);
287 BlockList->Current +=
N;
288 return static_cast<void*
>(
reinterpret_cast<char*
>(BlockList + 1) +
289 BlockList->Current - N);
294 BlockMeta* Tmp = BlockList;
295 BlockList = BlockList->Next;
296 if (reinterpret_cast<char*>(Tmp) != InitialBuffer)
299 BlockList =
new (InitialBuffer) BlockMeta{
nullptr, 0};
302 ~BumpPointerAllocator() { reset(); }
305 class DefaultAllocator {
306 BumpPointerAllocator Alloc;
309 void reset() { Alloc.reset(); }
311 template<
typename T,
typename ...Args>
T *makeNode(
Args &&...args) {
312 return new (Alloc.allocate(
sizeof(
T)))
313 T(std::forward<Args>(args)...);
316 void *allocateNodeArray(
size_t sz) {
317 return Alloc.allocate(
sizeof(Node *) * sz);
326 using Demangler = itanium_demangle::ManglingParser<DefaultAllocator>;
330 if (MangledName ==
nullptr || (Buf !=
nullptr && N ==
nullptr)) {
337 Demangler Parser(MangledName, MangledName + std::strlen(MangledName));
340 Node *AST = Parser.parse();
347 assert(Parser.ForwardTemplateRefs.empty());
351 *N = S.getCurrentPosition();
356 *Status = InternalStatus;
364 delete static_cast<Demangler *
>(Context);
369 : RootNode(
Other.RootNode), Context(
Other.Context) {
383 size_t Len = std::strlen(MangledName);
384 Parser->reset(MangledName, MangledName + Len);
385 RootNode = Parser->parse();
386 return RootNode ==
nullptr;
389 static char *
printNode(
const Node *RootNode,
char *Buf,
size_t *N) {
396 *N = S.getCurrentPosition();
397 return S.getBuffer();
407 switch (Name->getKind()) {
408 case Node::KAbiTagAttr:
411 case Node::KStdQualifiedName:
414 case Node::KNestedName:
417 case Node::KLocalName:
420 case Node::KNameWithTemplateArgs:
439 KeepGoingLocalFunction:
441 if (Name->getKind() == Node::KAbiTagAttr) {
445 if (Name->getKind() == Node::KNameWithTemplateArgs) {
452 switch (Name->getKind()) {
453 case Node::KStdQualifiedName:
456 case Node::KNestedName:
459 case Node::KLocalName: {
464 goto KeepGoingLocalFunction;
471 *N = S.getCurrentPosition();
472 return S.getBuffer();
497 *N = S.getCurrentPosition();
498 return S.getBuffer();
502 char *Buf,
size_t *N)
const {
510 if (
const Node *
Ret =
511 static_cast<const FunctionEncoding *>(RootNode)->getReturnType())
516 *N = S.getCurrentPosition();
517 return S.getBuffer();
521 assert(RootNode !=
nullptr &&
"must call partialDemangle()");
522 return printNode(static_cast<Node *>(RootNode), Buf, N);
526 assert(RootNode !=
nullptr &&
"must call partialDemangle()");
534 const Node *N =
static_cast<const Node *
>(RootNode);
536 switch (N->getKind()) {
539 case Node::KCtorDtorName:
542 case Node::KAbiTagAttr:
545 case Node::KFunctionEncoding:
548 case Node::KLocalName:
549 N =
static_cast<const LocalName *
>(
N)->Entity;
551 case Node::KNameWithTemplateArgs:
554 case Node::KNestedName:
557 case Node::KStdQualifiedName:
566 assert(RootNode !=
nullptr &&
"must call partialDemangle()");
567 return static_cast<const Node *
>(RootNode)->getKind() ==
568 Node::KFunctionEncoding;
572 assert(RootNode !=
nullptr &&
"must call partialDemangle()");
573 auto K =
static_cast<const Node *
>(RootNode)->getKind();
574 return K == Node::KSpecialName || K == Node::KCtorVtableSpecialName;
char * itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status)
ItaniumPartialDemangler & operator=(ItaniumPartialDemangler &&Other)
ItaniumPartialDemangler()
This class represents lattice values for constants.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void printWithComma(OutputStream &S) const
static void dump(StringRef Title, SpillInfo const &Spills)
bool isData() const
If this symbol describes a variable.
bool isFunction() const
If this symbol describes a function.
char * getFunctionName(char *Buf, size_t *N) const
Get the entire name of this function.
static StringRef getName(Value *V)
const char * parse_discriminator(const char *first, const char *last)
bool isCtorOrDtor() const
If this symbol describes a constructor or destructor.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void print(OutputStream &S) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
itanium_demangle::ManglingParser< DefaultAllocator > Demangler
char * getFunctionBaseName(char *Buf, size_t *N) const
Get the base name of a function.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool partialDemangle(const char *MangledName)
Demangle into an AST.
char * getFunctionDeclContextName(char *Buf, size_t *N) const
Get the context name for a function.
char * getFunctionParameters(char *Buf, size_t *N) const
Get the parameters for this function.
char * getFunctionReturnType(char *Buf, size_t *N) const
bool isSpecialName() const
If this symbol is a <special-name>.
static char * printNode(const Node *RootNode, char *Buf, size_t *N)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool hasFunctionQualifiers() const
If this function has any any cv or reference qualifiers.
char * finishDemangle(char *Buf, size_t *N) const
Just print the entire mangled name into Buf.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool initializeOutputStream(char *Buf, size_t *N, OutputStream &S, size_t InitSize)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
~ItaniumPartialDemangler()