Changeset View
Changeset View
Standalone View
Standalone View
lib/IR/Function.cpp
Show First 20 Lines • Show All 527 Lines • ▼ Show 20 Lines | |||||
static std::string getMangledTypeStr(Type* Ty) { | static std::string getMangledTypeStr(Type* Ty) { | ||||
std::string Result; | std::string Result; | ||||
if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) { | if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) { | ||||
Result += "p" + llvm::utostr(PTyp->getAddressSpace()) + | Result += "p" + llvm::utostr(PTyp->getAddressSpace()) + | ||||
getMangledTypeStr(PTyp->getElementType()); | getMangledTypeStr(PTyp->getElementType()); | ||||
} else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) { | } else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) { | ||||
Result += "a" + llvm::utostr(ATyp->getNumElements()) + | Result += "a" + llvm::utostr(ATyp->getNumElements()) + | ||||
getMangledTypeStr(ATyp->getElementType()); | getMangledTypeStr(ATyp->getElementType()); | ||||
} else if (StructType* STyp = dyn_cast<StructType>(Ty)) { | } else if (StructType *STyp = dyn_cast<StructType>(Ty)) { | ||||
assert(!STyp->isLiteral() && "TODO: implement literal types"); | if (!STyp->isLiteral()) { | ||||
Result += "s_"; | |||||
chandlerc: Uh.... Am I the only one horrified that we didn't prefix this with anything?
Won't this cause… | |||||
I just kinda assumed people knew what they were doing in the existing code :) dberlin: I just kinda assumed people knew what they were doing in the existing code :)
In any case… | |||||
Result += STyp->getName(); | Result += STyp->getName(); | ||||
} else { | |||||
Result += "sl_"; | |||||
for (auto Elem : STyp->elements()) | |||||
Result += getMangledTypeStr(Elem); | |||||
Range based loop over STyp->elements()? majnemer: Range based loop over `STyp->elements()`? | |||||
} | |||||
// Ensure nested structs are distinguishable. | |||||
Result += "s"; | |||||
} else if (FunctionType* FT = dyn_cast<FunctionType>(Ty)) { | } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) { | ||||
Result += "f_" + getMangledTypeStr(FT->getReturnType()); | Result += "f_" + getMangledTypeStr(FT->getReturnType()); | ||||
for (size_t i = 0; i < FT->getNumParams(); i++) | for (size_t i = 0; i < FT->getNumParams(); i++) | ||||
Result += getMangledTypeStr(FT->getParamType(i)); | Result += getMangledTypeStr(FT->getParamType(i)); | ||||
if (FT->isVarArg()) | if (FT->isVarArg()) | ||||
Result += "vararg"; | Result += "vararg"; | ||||
// Ensure nested function types are distinguishable. | // Ensure nested function types are distinguishable. | ||||
Result += "f"; | Result += "f"; | ||||
} else if (isa<VectorType>(Ty)) | } else if (isa<VectorType>(Ty)) | ||||
▲ Show 20 Lines • Show All 769 Lines • Show Last 20 Lines |
Uh.... Am I the only one horrified that we didn't prefix this with anything?
Won't this cause types named 's...' to potentially collide with literal types? Yeah, pretty sure it will. It's not unique to literal types.
Let's take a look at:
Also, I think we need to ensure nested types are distinguishable here much like below with function types.