[llvm-commits] CVS: llvm/lib/VMCore/Mangler.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Nov 10 11:30:18 PST 2005
Changes in directory llvm/lib/VMCore:
Mangler.cpp updated: 1.21 -> 1.22
---
Log message:
Add a new option for targets that accept quoted labels.
---
Diffs of the changes: (+44 -17)
Mangler.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 44 insertions(+), 17 deletions(-)
Index: llvm/lib/VMCore/Mangler.cpp
diff -u llvm/lib/VMCore/Mangler.cpp:1.21 llvm/lib/VMCore/Mangler.cpp:1.22
--- llvm/lib/VMCore/Mangler.cpp:1.21 Thu Nov 10 13:02:18 2005
+++ llvm/lib/VMCore/Mangler.cpp Thu Nov 10 13:30:07 2005
@@ -30,24 +30,51 @@
///
std::string Mangler::makeNameProper(const std::string &X, const char *Prefix) {
std::string Result;
-
- // If X does not start with (char)1, add the prefix.
- std::string::const_iterator I = X.begin();
- if (*I != 1)
- Result = Prefix;
- else
- ++I; // Skip over the marker.
- // Mangle the first letter specially, don't allow numbers...
- if (*I >= '0' && *I <= '9')
- Result += MangleLetter(*I++);
-
- for (std::string::const_iterator E = X.end(); I != E; ++I)
- if ((*I < 'a' || *I > 'z') && (*I < 'A' || *I > 'Z') &&
- (*I < '0' || *I > '9') && *I != '_' && *I != '$')
- Result += MangleLetter(*I);
+ if (!UseQuotes) {
+ // If X does not start with (char)1, add the prefix.
+ std::string::const_iterator I = X.begin();
+ if (*I != 1)
+ Result = Prefix;
+ else
+ ++I; // Skip over the marker.
+
+ // Mangle the first letter specially, don't allow numbers...
+ if (*I >= '0' && *I <= '9')
+ Result += MangleLetter(*I++);
+
+ for (std::string::const_iterator E = X.end(); I != E; ++I)
+ if ((*I < 'a' || *I > 'z') && (*I < 'A' || *I > 'Z') &&
+ (*I < '0' || *I > '9') && *I != '_' && *I != '$')
+ Result += MangleLetter(*I);
+ else
+ Result += *I;
+ } else {
+ bool NeedsQuotes = false;
+
+ // If X does not start with (char)1, add the prefix.
+ std::string::const_iterator I = X.begin();
+ if (*I != 1)
+ Result = Prefix;
else
- Result += *I;
+ ++I; // Skip over the marker.
+
+ // If the first character is a number, we need quotes.
+ if (*I >= '0' && *I <= '9')
+ NeedsQuotes = true;
+
+ for (std::string::const_iterator E = X.end(); I != E; ++I)
+ if (*I == '"')
+ Result += "_QQ_";
+ else {
+ if ((*I < 'a' || *I > 'z') && (*I < 'A' || *I > 'Z') &&
+ (*I < '0' || *I > '9') && *I != '_' && *I != '$' && *I != '.')
+ NeedsQuotes = true;
+ Result += *I;
+ }
+ if (NeedsQuotes)
+ Result = '"' + Result + '"';
+ }
return Result;
}
@@ -119,7 +146,7 @@
Mangler::Mangler(Module &M, const char *prefix)
- : Prefix(prefix), Count(0), TypeCounter(0) {
+ : Prefix(prefix), UseQuotes(false), Count(0), TypeCounter(0) {
// Calculate which global values have names that will collide when we throw
// away type information.
std::map<std::string, GlobalValue*> Names;
More information about the llvm-commits
mailing list