llvm.org GIT mirror llvm / a46a344
reduce duplicate mangling logic by using MCSymbol::printMangledName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93351 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 4 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
3434 #include "llvm/CodeGen/IntrinsicLowering.h"
3535 #include "llvm/Transforms/Scalar.h"
3636 #include "llvm/MC/MCAsmInfo.h"
37 #include "llvm/MC/MCSymbol.h"
3738 #include "llvm/Target/TargetData.h"
3839 #include "llvm/Target/TargetRegistry.h"
3940 #include "llvm/Support/CallSite.h"
342343 char CWriter::ID = 0;
343344
344345
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
356346 static std::string Mangle(const std::string &S) {
357347 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;
348 raw_string_ostream OS(Result);
349 MCSymbol::printMangledName(S, OS, 0);
350 return OS.str();
370351 }
371352
372353