@@ -653,6 +653,37 @@ static StringRef stringify(const itanium_demangle::NameType *Node) {
653
653
return StringRef (Str.begin (), Str.size ());
654
654
}
655
655
656
+ // / Convert a mangled name that represents a basic integer, floating-point,
657
+ // / etc. type into the corresponding LLVM type.
658
+ static Type *getPrimitiveType (LLVMContext &Ctx,
659
+ const llvm::itanium_demangle::Node *N) {
660
+ using namespace llvm ::itanium_demangle;
661
+ if (auto *Name = dyn_cast<NameType>(N)) {
662
+ return parsePrimitiveType (Ctx, stringify (Name));
663
+ }
664
+ if (auto *BitInt = dyn_cast<BitIntType>(N)) {
665
+ unsigned BitWidth = 0 ;
666
+ BitInt->match ([&](const Node *NodeSize, bool ) {
667
+ const StringRef SizeStr (stringify (cast<NameType>(NodeSize)));
668
+ SizeStr.getAsInteger (10 , BitWidth);
669
+ });
670
+ return Type::getIntNTy (Ctx, BitWidth);
671
+ }
672
+ if (auto *FP = dyn_cast<BinaryFPType>(N)) {
673
+ StringRef SizeStr;
674
+ FP->match ([&](const Node *NodeDimension) {
675
+ SizeStr = stringify (cast<NameType>(NodeDimension));
676
+ });
677
+ return StringSwitch<Type *>(SizeStr)
678
+ .Case (" 16" , Type::getHalfTy (Ctx))
679
+ .Case (" 32" , Type::getFloatTy (Ctx))
680
+ .Case (" 64" , Type::getDoubleTy (Ctx))
681
+ .Case (" 128" , Type::getFP128Ty (Ctx))
682
+ .Default (nullptr );
683
+ }
684
+ return nullptr ;
685
+ }
686
+
656
687
template <typename FnType>
657
688
static TypedPointerType *
658
689
parseNode (Module *M, const llvm::itanium_demangle::Node *ParamType,
@@ -724,21 +755,15 @@ parseNode(Module *M, const llvm::itanium_demangle::Node *ParamType,
724
755
} else {
725
756
PointeeTy = parsePrimitiveType (M->getContext (), MangledStructName);
726
757
}
727
- } else if (auto *BitInt = dyn_cast<BitIntType>(Pointee)) {
728
- unsigned BitWidth = 0 ;
729
- BitInt->match ([&](const Node *NodeSize, bool ) {
730
- const StringRef SizeStr (stringify (cast<NameType>(NodeSize)));
731
- SizeStr.getAsInteger (10 , BitWidth);
732
- });
733
- PointeeTy = Type::getIntNTy (M->getContext (), BitWidth);
758
+ } else if (auto *Ty = getPrimitiveType (M->getContext (), Pointee)) {
759
+ PointeeTy = Ty;
734
760
} else if (auto *Vec = dyn_cast<itanium_demangle::VectorType>(Pointee)) {
735
761
unsigned ElemCount = 0 ;
736
762
const StringRef ElemCountStr (
737
763
stringify (cast<NameType>(Vec->getDimension ())));
738
764
ElemCountStr.getAsInteger (10 , ElemCount);
739
- if (auto *Name = dyn_cast<NameType>(Vec->getBaseType ())) {
740
- PointeeTy = parsePrimitiveType (M->getContext (), stringify (Name));
741
- PointeeTy = llvm::VectorType::get (PointeeTy, ElemCount, false );
765
+ if (auto *Ty = getPrimitiveType (M->getContext (), Vec->getBaseType ())) {
766
+ PointeeTy = llvm::VectorType::get (Ty, ElemCount, false );
742
767
}
743
768
} else if (llvm::isa<itanium_demangle::PointerType>(Pointee)) {
744
769
PointeeTy = parseNode (M, Pointee, GetStructType);
0 commit comments