llvm.org GIT mirror llvm / 471f1e9
stop the CBE from using deprecated Mangler stuff. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93341 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 39 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
340340 }
341341
342342 char CWriter::ID = 0;
343
344
345 static bool isAcceptableChar(char C) {
346 if ((C < 'a' || C > 'z') && (C < 'A' || C > 'Z') &&
347 (C < '0' || C > '9') && C != '_' && C != '$' && C != '@')
348 return false;
349 return true;
350 }
351
352 static char HexDigit(int V) {
353 return V < 10 ? V+'0' : V+'A'-10;
354 }
355
356 static std::string Mangle(const std::string &S) {
357 std::string Result;
358
359 for (unsigned i = 0, e = S.size(); i != e; ++i)
360 if (isAcceptableChar(S[i]))
361 Result += S[i];
362 else {
363 Result += '_';
364 Result += HexDigit((S[i] >> 4) & 15);
365 Result += HexDigit(S[i] & 15);
366 Result += '_';
367 }
368
369 return Result;
370 }
371
343372
344373 /// This method inserts names for any unnamed structure types that are used by
345374 /// the program, and removes names from structure types that are not used by the
14311460
14321461 std::string CWriter::GetValueName(const Value *Operand) {
14331462 // Mangle globals with the standard mangler interface for LLC compatibility.
1434 if (const GlobalValue *GV = dyn_cast(Operand))
1435 return Mang->getMangledName(GV);
1463 if (const GlobalValue *GV = dyn_cast(Operand)) {
1464 SmallString<128> Str;
1465 Mang->getNameWithPrefix(Str, GV, false);
1466 return Mangle(Str.str().str());
1467 }
14361468
14371469 std::string Name = Operand->getName();
14381470
18571889
18581890 // Ensure that all structure types have names...
18591891 Mang = new Mangler(M);
1860 Mang->markCharUnacceptable('.');
18611892
18621893 // Keep track of which functions are static ctors/dtors so they can have
18631894 // an attribute added to their prototypes.
22072238 // If there are no type names, exit early.
22082239 if (I == End) return;
22092240
2210 SmallString<128> TempName;
2211
22122241 // Print out forward declarations for structure types before anything else!
22132242 Out << "/* Structure forward decls */\n";
22142243 for (; I != End; ++I) {
2215 const char *Prefix = "struct l_";
2216 TempName.append(Prefix, Prefix+strlen(Prefix));
2217 Mang->makeNameProper(TempName, I->first);
2218 Out << TempName.str() << ";\n";
2219 TypeNames.insert(std::make_pair(I->second, TempName.str()));
2220 TempName.clear();
2244 std::string Name = "struct " + Mangle("l_"+I->first);
2245 Out << Name << ";\n";
2246 TypeNames.insert(std::make_pair(I->second, Name));
22212247 }
22222248
22232249 Out << '\n';
22262252 // for struct or opaque types.
22272253 Out << "/* Typedefs */\n";
22282254 for (I = TST.begin(); I != End; ++I) {
2229 const char *Prefix = "l_";
2230 TempName.append(Prefix, Prefix+strlen(Prefix));
2231 Mang->makeNameProper(TempName, I->first);
2232
2255 std::string Name = Mangle("l_"+I->first);
22332256 Out << "typedef ";
2234 printType(Out, I->second, false, TempName.str());
2257 printType(Out, I->second, false, Name);
22352258 Out << ";\n";
2236 TempName.clear();
22372259 }
22382260
22392261 Out << '\n';