Add a new option for targets that accept quoted labels.
authorChris Lattner <sabre@nondot.org>
Thu, 10 Nov 2005 19:30:07 +0000 (19:30 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 10 Nov 2005 19:30:07 +0000 (19:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24283 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Mangler.h
lib/VMCore/Mangler.cpp

index 975791f0023749016378eede6409ff86d649630a..6499b9d54b25e3020cf735fb68507c6c8e144fa3 100644 (file)
@@ -25,15 +25,15 @@ class Value;
 class GlobalValue;
 
 class Mangler {
 class GlobalValue;
 
 class Mangler {
-  /// This keeps track of which global values have had their names
-  /// mangled in the current module.
-  ///
-  std::set<const GlobalValue*> MangledGlobals;
-
   /// Prefix - This string is added to each symbol that is emitted, unless the
   /// symbol is marked as not needing this prefix.
   const char *Prefix;
   /// Prefix - This string is added to each symbol that is emitted, unless the
   /// symbol is marked as not needing this prefix.
   const char *Prefix;
-
+  
+  /// UseQuotes - If this is set, the target accepts global names in quotes, 
+  /// e.g. "foo bar" is a legal name.  This syntax is used instead of escaping
+  /// the space character.  By default, this is false.
+  bool UseQuotes;
+  
   /// Memo - This is used to remember the name that we assign a value.
   ///
   std::map<const Value*, std::string> Memo;
   /// Memo - This is used to remember the name that we assign a value.
   ///
   std::map<const Value*, std::string> Memo;
@@ -47,13 +47,20 @@ class Mangler {
   std::map<const Type*, unsigned> TypeMap;
   unsigned TypeCounter;
 
   std::map<const Type*, unsigned> TypeMap;
   unsigned TypeCounter;
 
-  void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
+  /// This keeps track of which global values have had their names
+  /// mangled in the current module.
+  ///
+  std::set<const GlobalValue*> MangledGlobals;
 public:
 
   // Mangler ctor - if a prefix is specified, it will be prepended onto all
   // symbols.
   Mangler(Module &M, const char *Prefix = "");
 
 public:
 
   // Mangler ctor - if a prefix is specified, it will be prepended onto all
   // symbols.
   Mangler(Module &M, const char *Prefix = "");
 
+  /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
+  /// strings for assembler labels.
+  void setUseQuotes(bool Val) { UseQuotes = Val; }
+  
   /// getTypeID - Return a unique ID for the specified LLVM type.
   ///
   unsigned getTypeID(const Type *Ty);
   /// getTypeID - Return a unique ID for the specified LLVM type.
   ///
   unsigned getTypeID(const Type *Ty);
@@ -72,6 +79,9 @@ public:
   /// from getValueName.
   ///
   std::string makeNameProper(const std::string &x, const char *Prefix = "");
   /// from getValueName.
   ///
   std::string makeNameProper(const std::string &x, const char *Prefix = "");
+  
+private:
+  void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
 };
 
 } // End llvm namespace
 };
 
 } // End llvm namespace
index 03111803186157d15338d72714fe130b9f42b19a..418eb9a71a35c4c0fe79422ca333edd359c311c2 100644 (file)
@@ -30,24 +30,51 @@ static std::string MangleLetter(unsigned char C) {
 ///
 std::string Mangler::makeNameProper(const std::string &X, const char *Prefix) {
   std::string Result;
 ///
 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
     else
-      Result += *I;
+      ++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
+      ++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;
 }
 
   return Result;
 }
 
@@ -119,7 +146,7 @@ void Mangler::InsertName(GlobalValue *GV,
 
 
 Mangler::Mangler(Module &M, const char *prefix)
 
 
 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;
   // Calculate which global values have names that will collide when we throw
   // away type information.
   std::map<std::string, GlobalValue*> Names;