diff options
| author | 2023-07-18 21:39:37 -0400 | |
|---|---|---|
| committer | 2023-07-18 22:39:26 -0400 | |
| commit | 1ab3bd5a5eb966ce3966688857c6fa516039c1c2 (patch) | |
| tree | 0666011e6ddd40c71534c1827f86f7b297170edf /externals/demangle/ItaniumDemangle.cpp | |
| parent | CMake: Require LLVM 17 or later (diff) | |
| download | yuzu-1ab3bd5a5eb966ce3966688857c6fa516039c1c2.tar.gz yuzu-1ab3bd5a5eb966ce3966688857c6fa516039c1c2.tar.xz yuzu-1ab3bd5a5eb966ce3966688857c6fa516039c1c2.zip | |
demangle: Update to llvm/llvm-project@ecbc812e0cca
Diffstat (limited to 'externals/demangle/ItaniumDemangle.cpp')
| -rw-r--r-- | externals/demangle/ItaniumDemangle.cpp | 171 |
1 files changed, 90 insertions, 81 deletions
diff --git a/externals/demangle/ItaniumDemangle.cpp b/externals/demangle/ItaniumDemangle.cpp index b055a2fd7..47dd5d301 100644 --- a/externals/demangle/ItaniumDemangle.cpp +++ b/externals/demangle/ItaniumDemangle.cpp | |||
| @@ -20,9 +20,7 @@ | |||
| 20 | #include <cstdlib> | 20 | #include <cstdlib> |
| 21 | #include <cstring> | 21 | #include <cstring> |
| 22 | #include <functional> | 22 | #include <functional> |
| 23 | #include <numeric> | ||
| 24 | #include <utility> | 23 | #include <utility> |
| 25 | #include <vector> | ||
| 26 | 24 | ||
| 27 | using namespace llvm; | 25 | using namespace llvm; |
| 28 | using namespace llvm::itanium_demangle; | 26 | using namespace llvm::itanium_demangle; |
| @@ -81,8 +79,8 @@ struct DumpVisitor { | |||
| 81 | } | 79 | } |
| 82 | 80 | ||
| 83 | void printStr(const char *S) { fprintf(stderr, "%s", S); } | 81 | void printStr(const char *S) { fprintf(stderr, "%s", S); } |
| 84 | void print(StringView SV) { | 82 | void print(std::string_view SV) { |
| 85 | fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.begin()); | 83 | fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.data()); |
| 86 | } | 84 | } |
| 87 | void print(const Node *N) { | 85 | void print(const Node *N) { |
| 88 | if (N) | 86 | if (N) |
| @@ -90,14 +88,6 @@ struct DumpVisitor { | |||
| 90 | else | 88 | else |
| 91 | printStr("<null>"); | 89 | printStr("<null>"); |
| 92 | } | 90 | } |
| 93 | void print(NodeOrString NS) { | ||
| 94 | if (NS.isNode()) | ||
| 95 | print(NS.asNode()); | ||
| 96 | else if (NS.isString()) | ||
| 97 | print(NS.asString()); | ||
| 98 | else | ||
| 99 | printStr("NodeOrString()"); | ||
| 100 | } | ||
| 101 | void print(NodeArray A) { | 91 | void print(NodeArray A) { |
| 102 | ++Depth; | 92 | ++Depth; |
| 103 | printStr("{"); | 93 | printStr("{"); |
| @@ -116,13 +106,11 @@ struct DumpVisitor { | |||
| 116 | // Overload used when T is exactly 'bool', not merely convertible to 'bool'. | 106 | // Overload used when T is exactly 'bool', not merely convertible to 'bool'. |
| 117 | void print(bool B) { printStr(B ? "true" : "false"); } | 107 | void print(bool B) { printStr(B ? "true" : "false"); } |
| 118 | 108 | ||
| 119 | template <class T> | 109 | template <class T> std::enable_if_t<std::is_unsigned<T>::value> print(T N) { |
| 120 | typename std::enable_if<std::is_unsigned<T>::value>::type print(T N) { | ||
| 121 | fprintf(stderr, "%llu", (unsigned long long)N); | 110 | fprintf(stderr, "%llu", (unsigned long long)N); |
| 122 | } | 111 | } |
| 123 | 112 | ||
| 124 | template <class T> | 113 | template <class T> std::enable_if_t<std::is_signed<T>::value> print(T N) { |
| 125 | typename std::enable_if<std::is_signed<T>::value>::type print(T N) { | ||
| 126 | fprintf(stderr, "%lld", (long long)N); | 114 | fprintf(stderr, "%lld", (long long)N); |
| 127 | } | 115 | } |
| 128 | 116 | ||
| @@ -185,6 +173,50 @@ struct DumpVisitor { | |||
| 185 | return printStr("TemplateParamKind::Template"); | 173 | return printStr("TemplateParamKind::Template"); |
| 186 | } | 174 | } |
| 187 | } | 175 | } |
| 176 | void print(Node::Prec P) { | ||
| 177 | switch (P) { | ||
| 178 | case Node::Prec::Primary: | ||
| 179 | return printStr("Node::Prec::Primary"); | ||
| 180 | case Node::Prec::Postfix: | ||
| 181 | return printStr("Node::Prec::Postfix"); | ||
| 182 | case Node::Prec::Unary: | ||
| 183 | return printStr("Node::Prec::Unary"); | ||
| 184 | case Node::Prec::Cast: | ||
| 185 | return printStr("Node::Prec::Cast"); | ||
| 186 | case Node::Prec::PtrMem: | ||
| 187 | return printStr("Node::Prec::PtrMem"); | ||
| 188 | case Node::Prec::Multiplicative: | ||
| 189 | return printStr("Node::Prec::Multiplicative"); | ||
| 190 | case Node::Prec::Additive: | ||
| 191 | return printStr("Node::Prec::Additive"); | ||
| 192 | case Node::Prec::Shift: | ||
| 193 | return printStr("Node::Prec::Shift"); | ||
| 194 | case Node::Prec::Spaceship: | ||
| 195 | return printStr("Node::Prec::Spaceship"); | ||
| 196 | case Node::Prec::Relational: | ||
| 197 | return printStr("Node::Prec::Relational"); | ||
| 198 | case Node::Prec::Equality: | ||
| 199 | return printStr("Node::Prec::Equality"); | ||
| 200 | case Node::Prec::And: | ||
| 201 | return printStr("Node::Prec::And"); | ||
| 202 | case Node::Prec::Xor: | ||
| 203 | return printStr("Node::Prec::Xor"); | ||
| 204 | case Node::Prec::Ior: | ||
| 205 | return printStr("Node::Prec::Ior"); | ||
| 206 | case Node::Prec::AndIf: | ||
| 207 | return printStr("Node::Prec::AndIf"); | ||
| 208 | case Node::Prec::OrIf: | ||
| 209 | return printStr("Node::Prec::OrIf"); | ||
| 210 | case Node::Prec::Conditional: | ||
| 211 | return printStr("Node::Prec::Conditional"); | ||
| 212 | case Node::Prec::Assign: | ||
| 213 | return printStr("Node::Prec::Assign"); | ||
| 214 | case Node::Prec::Comma: | ||
| 215 | return printStr("Node::Prec::Comma"); | ||
| 216 | case Node::Prec::Default: | ||
| 217 | return printStr("Node::Prec::Default"); | ||
| 218 | } | ||
| 219 | } | ||
| 188 | 220 | ||
| 189 | void newLine() { | 221 | void newLine() { |
| 190 | printStr("\n"); | 222 | printStr("\n"); |
| @@ -334,36 +366,21 @@ public: | |||
| 334 | 366 | ||
| 335 | using Demangler = itanium_demangle::ManglingParser<DefaultAllocator>; | 367 | using Demangler = itanium_demangle::ManglingParser<DefaultAllocator>; |
| 336 | 368 | ||
| 337 | char *llvm::itaniumDemangle(const char *MangledName, char *Buf, | 369 | char *llvm::itaniumDemangle(std::string_view MangledName) { |
| 338 | size_t *N, int *Status) { | 370 | if (MangledName.empty()) |
| 339 | if (MangledName == nullptr || (Buf != nullptr && N == nullptr)) { | ||
| 340 | if (Status) | ||
| 341 | *Status = demangle_invalid_args; | ||
| 342 | return nullptr; | 371 | return nullptr; |
| 343 | } | ||
| 344 | |||
| 345 | int InternalStatus = demangle_success; | ||
| 346 | Demangler Parser(MangledName, MangledName + std::strlen(MangledName)); | ||
| 347 | OutputStream S; | ||
| 348 | 372 | ||
| 373 | Demangler Parser(MangledName.data(), | ||
| 374 | MangledName.data() + MangledName.length()); | ||
| 349 | Node *AST = Parser.parse(); | 375 | Node *AST = Parser.parse(); |
| 376 | if (!AST) | ||
| 377 | return nullptr; | ||
| 350 | 378 | ||
| 351 | if (AST == nullptr) | 379 | OutputBuffer OB; |
| 352 | InternalStatus = demangle_invalid_mangled_name; | 380 | assert(Parser.ForwardTemplateRefs.empty()); |
| 353 | else if (!initializeOutputStream(Buf, N, S, 1024)) | 381 | AST->print(OB); |
| 354 | InternalStatus = demangle_memory_alloc_failure; | 382 | OB += '\0'; |
| 355 | else { | 383 | return OB.getBuffer(); |
| 356 | assert(Parser.ForwardTemplateRefs.empty()); | ||
| 357 | AST->print(S); | ||
| 358 | S += '\0'; | ||
| 359 | if (N != nullptr) | ||
| 360 | *N = S.getCurrentPosition(); | ||
| 361 | Buf = S.getBuffer(); | ||
| 362 | } | ||
| 363 | |||
| 364 | if (Status) | ||
| 365 | *Status = InternalStatus; | ||
| 366 | return InternalStatus == demangle_success ? Buf : nullptr; | ||
| 367 | } | 384 | } |
| 368 | 385 | ||
| 369 | ItaniumPartialDemangler::ItaniumPartialDemangler() | 386 | ItaniumPartialDemangler::ItaniumPartialDemangler() |
| @@ -396,14 +413,12 @@ bool ItaniumPartialDemangler::partialDemangle(const char *MangledName) { | |||
| 396 | } | 413 | } |
| 397 | 414 | ||
| 398 | static char *printNode(const Node *RootNode, char *Buf, size_t *N) { | 415 | static char *printNode(const Node *RootNode, char *Buf, size_t *N) { |
| 399 | OutputStream S; | 416 | OutputBuffer OB(Buf, N); |
| 400 | if (!initializeOutputStream(Buf, N, S, 128)) | 417 | RootNode->print(OB); |
| 401 | return nullptr; | 418 | OB += '\0'; |
| 402 | RootNode->print(S); | ||
| 403 | S += '\0'; | ||
| 404 | if (N != nullptr) | 419 | if (N != nullptr) |
| 405 | *N = S.getCurrentPosition(); | 420 | *N = OB.getCurrentPosition(); |
| 406 | return S.getBuffer(); | 421 | return OB.getBuffer(); |
| 407 | } | 422 | } |
| 408 | 423 | ||
| 409 | char *ItaniumPartialDemangler::getFunctionBaseName(char *Buf, size_t *N) const { | 424 | char *ItaniumPartialDemangler::getFunctionBaseName(char *Buf, size_t *N) const { |
| @@ -417,8 +432,8 @@ char *ItaniumPartialDemangler::getFunctionBaseName(char *Buf, size_t *N) const { | |||
| 417 | case Node::KAbiTagAttr: | 432 | case Node::KAbiTagAttr: |
| 418 | Name = static_cast<const AbiTagAttr *>(Name)->Base; | 433 | Name = static_cast<const AbiTagAttr *>(Name)->Base; |
| 419 | continue; | 434 | continue; |
| 420 | case Node::KStdQualifiedName: | 435 | case Node::KModuleEntity: |
| 421 | Name = static_cast<const StdQualifiedName *>(Name)->Child; | 436 | Name = static_cast<const ModuleEntity *>(Name)->Name; |
| 422 | continue; | 437 | continue; |
| 423 | case Node::KNestedName: | 438 | case Node::KNestedName: |
| 424 | Name = static_cast<const NestedName *>(Name)->Name; | 439 | Name = static_cast<const NestedName *>(Name)->Name; |
| @@ -441,9 +456,7 @@ char *ItaniumPartialDemangler::getFunctionDeclContextName(char *Buf, | |||
| 441 | return nullptr; | 456 | return nullptr; |
| 442 | const Node *Name = static_cast<const FunctionEncoding *>(RootNode)->getName(); | 457 | const Node *Name = static_cast<const FunctionEncoding *>(RootNode)->getName(); |
| 443 | 458 | ||
| 444 | OutputStream S; | 459 | OutputBuffer OB(Buf, N); |
| 445 | if (!initializeOutputStream(Buf, N, S, 128)) | ||
| 446 | return nullptr; | ||
| 447 | 460 | ||
| 448 | KeepGoingLocalFunction: | 461 | KeepGoingLocalFunction: |
| 449 | while (true) { | 462 | while (true) { |
| @@ -458,27 +471,27 @@ char *ItaniumPartialDemangler::getFunctionDeclContextName(char *Buf, | |||
| 458 | break; | 471 | break; |
| 459 | } | 472 | } |
| 460 | 473 | ||
| 474 | if (Name->getKind() == Node::KModuleEntity) | ||
| 475 | Name = static_cast<const ModuleEntity *>(Name)->Name; | ||
| 476 | |||
| 461 | switch (Name->getKind()) { | 477 | switch (Name->getKind()) { |
| 462 | case Node::KStdQualifiedName: | ||
| 463 | S += "std"; | ||
| 464 | break; | ||
| 465 | case Node::KNestedName: | 478 | case Node::KNestedName: |
| 466 | static_cast<const NestedName *>(Name)->Qual->print(S); | 479 | static_cast<const NestedName *>(Name)->Qual->print(OB); |
| 467 | break; | 480 | break; |
| 468 | case Node::KLocalName: { | 481 | case Node::KLocalName: { |
| 469 | auto *LN = static_cast<const LocalName *>(Name); | 482 | auto *LN = static_cast<const LocalName *>(Name); |
| 470 | LN->Encoding->print(S); | 483 | LN->Encoding->print(OB); |
| 471 | S += "::"; | 484 | OB += "::"; |
| 472 | Name = LN->Entity; | 485 | Name = LN->Entity; |
| 473 | goto KeepGoingLocalFunction; | 486 | goto KeepGoingLocalFunction; |
| 474 | } | 487 | } |
| 475 | default: | 488 | default: |
| 476 | break; | 489 | break; |
| 477 | } | 490 | } |
| 478 | S += '\0'; | 491 | OB += '\0'; |
| 479 | if (N != nullptr) | 492 | if (N != nullptr) |
| 480 | *N = S.getCurrentPosition(); | 493 | *N = OB.getCurrentPosition(); |
| 481 | return S.getBuffer(); | 494 | return OB.getBuffer(); |
| 482 | } | 495 | } |
| 483 | 496 | ||
| 484 | char *ItaniumPartialDemangler::getFunctionName(char *Buf, size_t *N) const { | 497 | char *ItaniumPartialDemangler::getFunctionName(char *Buf, size_t *N) const { |
| @@ -494,17 +507,15 @@ char *ItaniumPartialDemangler::getFunctionParameters(char *Buf, | |||
| 494 | return nullptr; | 507 | return nullptr; |
| 495 | NodeArray Params = static_cast<FunctionEncoding *>(RootNode)->getParams(); | 508 | NodeArray Params = static_cast<FunctionEncoding *>(RootNode)->getParams(); |
| 496 | 509 | ||
| 497 | OutputStream S; | 510 | OutputBuffer OB(Buf, N); |
| 498 | if (!initializeOutputStream(Buf, N, S, 128)) | ||
| 499 | return nullptr; | ||
| 500 | 511 | ||
| 501 | S += '('; | 512 | OB += '('; |
| 502 | Params.printWithComma(S); | 513 | Params.printWithComma(OB); |
| 503 | S += ')'; | 514 | OB += ')'; |
| 504 | S += '\0'; | 515 | OB += '\0'; |
| 505 | if (N != nullptr) | 516 | if (N != nullptr) |
| 506 | *N = S.getCurrentPosition(); | 517 | *N = OB.getCurrentPosition(); |
| 507 | return S.getBuffer(); | 518 | return OB.getBuffer(); |
| 508 | } | 519 | } |
| 509 | 520 | ||
| 510 | char *ItaniumPartialDemangler::getFunctionReturnType( | 521 | char *ItaniumPartialDemangler::getFunctionReturnType( |
| @@ -512,18 +523,16 @@ char *ItaniumPartialDemangler::getFunctionReturnType( | |||
| 512 | if (!isFunction()) | 523 | if (!isFunction()) |
| 513 | return nullptr; | 524 | return nullptr; |
| 514 | 525 | ||
| 515 | OutputStream S; | 526 | OutputBuffer OB(Buf, N); |
| 516 | if (!initializeOutputStream(Buf, N, S, 128)) | ||
| 517 | return nullptr; | ||
| 518 | 527 | ||
| 519 | if (const Node *Ret = | 528 | if (const Node *Ret = |
| 520 | static_cast<const FunctionEncoding *>(RootNode)->getReturnType()) | 529 | static_cast<const FunctionEncoding *>(RootNode)->getReturnType()) |
| 521 | Ret->print(S); | 530 | Ret->print(OB); |
| 522 | 531 | ||
| 523 | S += '\0'; | 532 | OB += '\0'; |
| 524 | if (N != nullptr) | 533 | if (N != nullptr) |
| 525 | *N = S.getCurrentPosition(); | 534 | *N = OB.getCurrentPosition(); |
| 526 | return S.getBuffer(); | 535 | return OB.getBuffer(); |
| 527 | } | 536 | } |
| 528 | 537 | ||
| 529 | char *ItaniumPartialDemangler::finishDemangle(char *Buf, size_t *N) const { | 538 | char *ItaniumPartialDemangler::finishDemangle(char *Buf, size_t *N) const { |
| @@ -563,8 +572,8 @@ bool ItaniumPartialDemangler::isCtorOrDtor() const { | |||
| 563 | case Node::KNestedName: | 572 | case Node::KNestedName: |
| 564 | N = static_cast<const NestedName *>(N)->Name; | 573 | N = static_cast<const NestedName *>(N)->Name; |
| 565 | break; | 574 | break; |
| 566 | case Node::KStdQualifiedName: | 575 | case Node::KModuleEntity: |
| 567 | N = static_cast<const StdQualifiedName *>(N)->Child; | 576 | N = static_cast<const ModuleEntity *>(N)->Name; |
| 568 | break; | 577 | break; |
| 569 | } | 578 | } |
| 570 | } | 579 | } |