From a46a34431c9c2d70058d12aa070b87b2526aee0d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 13 Jan 2010 21:12:34 +0000 Subject: [PATCH] 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 --- lib/Target/CBackend/CBackend.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index af85aacb2da..0fd975cffd8 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -35,6 +35,7 @@ #include "llvm/CodeGen/IntrinsicLowering.h" #include "llvm/Transforms/Scalar.h" #include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCSymbol.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/Support/CallSite.h" @@ -343,31 +344,11 @@ 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; + raw_string_ostream OS(Result); + MCSymbol::printMangledName(S, OS, 0); + return OS.str(); }