diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-13 19:54:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-13 19:54:07 +0000 |
commit | d2f59b85e999fdb999f0929b90fe0163d5e40c14 (patch) | |
tree | f185ac235dabdb33db3f7b2c2658344f9ebfb2c3 /lib/Target/CBackend | |
parent | 925e1ee4a64d977b200dbb37a5de21060e98eae5 (diff) | |
download | external_llvm-d2f59b85e999fdb999f0929b90fe0163d5e40c14.zip external_llvm-d2f59b85e999fdb999f0929b90fe0163d5e40c14.tar.gz external_llvm-d2f59b85e999fdb999f0929b90fe0163d5e40c14.tar.bz2 |
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
Diffstat (limited to 'lib/Target/CBackend')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 914af53..af85aac 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -342,6 +342,35 @@ namespace { char CWriter::ID = 0; + +static bool isAcceptableChar(char C) { + if ((C < 'a' || C > 'z') && (C < 'A' || C > 'Z') && + (C < '0' || C > '9') && C != '_' && C != '$' && C != '@') + return false; + return true; +} + +static char HexDigit(int V) { + return V < 10 ? V+'0' : V+'A'-10; +} + +static std::string Mangle(const std::string &S) { + std::string Result; + + for (unsigned i = 0, e = S.size(); i != e; ++i) + if (isAcceptableChar(S[i])) + Result += S[i]; + else { + Result += '_'; + Result += HexDigit((S[i] >> 4) & 15); + Result += HexDigit(S[i] & 15); + Result += '_'; + } + + return Result; +} + + /// This method inserts names for any unnamed structure types that are used by /// the program, and removes names from structure types that are not used by the /// program. @@ -1432,8 +1461,11 @@ void CWriter::printConstantWithCast(Constant* CPV, unsigned Opcode) { std::string CWriter::GetValueName(const Value *Operand) { // Mangle globals with the standard mangler interface for LLC compatibility. - if (const GlobalValue *GV = dyn_cast<GlobalValue>(Operand)) - return Mang->getMangledName(GV); + if (const GlobalValue *GV = dyn_cast<GlobalValue>(Operand)) { + SmallString<128> Str; + Mang->getNameWithPrefix(Str, GV, false); + return Mangle(Str.str().str()); + } std::string Name = Operand->getName(); @@ -1858,7 +1890,6 @@ bool CWriter::doInitialization(Module &M) { // Ensure that all structure types have names... Mang = new Mangler(M); - Mang->markCharUnacceptable('.'); // Keep track of which functions are static ctors/dtors so they can have // an attribute added to their prototypes. @@ -2208,17 +2239,12 @@ void CWriter::printModuleTypes(const TypeSymbolTable &TST) { // If there are no type names, exit early. if (I == End) return; - SmallString<128> TempName; - // Print out forward declarations for structure types before anything else! Out << "/* Structure forward decls */\n"; for (; I != End; ++I) { - const char *Prefix = "struct l_"; - TempName.append(Prefix, Prefix+strlen(Prefix)); - Mang->makeNameProper(TempName, I->first); - Out << TempName.str() << ";\n"; - TypeNames.insert(std::make_pair(I->second, TempName.str())); - TempName.clear(); + std::string Name = "struct " + Mangle("l_"+I->first); + Out << Name << ";\n"; + TypeNames.insert(std::make_pair(I->second, Name)); } Out << '\n'; @@ -2227,14 +2253,10 @@ void CWriter::printModuleTypes(const TypeSymbolTable &TST) { // for struct or opaque types. Out << "/* Typedefs */\n"; for (I = TST.begin(); I != End; ++I) { - const char *Prefix = "l_"; - TempName.append(Prefix, Prefix+strlen(Prefix)); - Mang->makeNameProper(TempName, I->first); - + std::string Name = Mangle("l_"+I->first); Out << "typedef "; - printType(Out, I->second, false, TempName.str()); + printType(Out, I->second, false, Name); Out << ";\n"; - TempName.clear(); } Out << '\n'; |