/// have a name, this fills in a unique name for the global.
std::string getNameWithPrefix(const GlobalValue *GV,
bool isImplicitlyPrivate = false);
-
- /// appendMangledName - Add the specified string in mangled form if it uses
- /// any unusual characters.
- static void appendMangledName(SmallVectorImpl<char> &OutName, StringRef Str,
- const MCAsmInfo *MAI);
};
} // End llvm namespace
char CWriter::ID = 0;
-static std::string Mangle(const std::string &S) {
- SmallString<52> Result;
- Mangler::appendMangledName(Result, S, 0);
- return std::string(Result.begin(), Result.end());
+static std::string MangleType(const std::string &S) {
+ std::string Result;
+
+ for (unsigned i = 0, e = S.size(); i != e; ++i)
+ if (isalnum(S[i]) || S[i] == '_') {
+ Result += S[i];
+ } else {
+ Result += '_';
+ Result += 'A'+(S[i]&15);
+ Result += 'A'+((S[i]>>4)&15);
+ Result += '_';
+ }
+ return Result;
}
// Print out forward declarations for structure types before anything else!
Out << "/* Structure forward decls */\n";
for (; I != End; ++I) {
- std::string Name = "struct " + Mangle("l_"+I->first);
+ std::string Name = "struct " + MangleType("l_"+I->first);
Out << Name << ";\n";
TypeNames.insert(std::make_pair(I->second, Name));
}
// for struct or opaque types.
Out << "/* Typedefs */\n";
for (I = TST.begin(); I != End; ++I) {
- std::string Name = Mangle("l_"+I->first);
+ std::string Name = MangleType("l_"+I->first);
Out << "typedef ";
printType(Out, I->second, false, Name);
Out << ";\n";
/// appendMangledName - Add the specified string in mangled form if it uses
/// any unusual characters.
-void Mangler::appendMangledName(SmallVectorImpl<char> &OutName, StringRef Str,
- const MCAsmInfo *MAI) {
+static void appendMangledName(SmallVectorImpl<char> &OutName, StringRef Str,
+ const MCAsmInfo *MAI) {
// The first character is not allowed to be a number unless the target
// explicitly allows it.
if ((MAI == 0 || !MAI->doesAllowNameToStartWithDigit()) &&