[llvm-commits] [llvm] r98118 - in /llvm/trunk: include/llvm/MC/MCContext.h lib/MC/MCContext.cpp lib/MC/MCParser/AsmParser.cpp

Chris Lattner sabre at nondot.org
Tue Mar 9 17:29:27 PST 2010


Author: lattner
Date: Tue Mar  9 19:29:27 2010
New Revision: 98118

URL: http://llvm.org/viewvc/llvm-project?rev=98118&view=rev
Log:
eliminate MCContext::CreateSymbol and CreateTemporarySymbol.
Add a new GetOrCreateTemporarySymbol method and a version that
takes a twine.

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=98118&r1=98117&r2=98118&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Mar  9 19:29:27 2010
@@ -46,11 +46,6 @@
     /// @name Symbol Managment
     /// @{
 
-    /// CreateSymbol - Create a new symbol with the specified @p Name.
-    ///
-    /// @param Name - The symbol name, which must be unique across all symbols.
-    MCSymbol *CreateSymbol(StringRef Name);
-
     /// GetOrCreateSymbol - Lookup the symbol inside with the specified
     /// @p Name.  If it exists, return it.  If not, create a forward
     /// reference and return it.
@@ -59,13 +54,15 @@
     MCSymbol *GetOrCreateSymbol(StringRef Name);
     MCSymbol *GetOrCreateSymbol(const Twine &Name);
 
-    /// CreateTemporarySymbol - Create a new temporary symbol with the specified
-    /// @p Name.
+    /// GetOrCreateTemporarySymbol - Create a new assembler temporary symbol
+    /// with the specified @p Name if it doesn't exist or return the existing
+    /// one if it does.
     ///
     /// @param Name - The symbol name, for debugging purposes only, temporary
     /// symbols do not surive assembly. If non-empty the name must be unique
     /// across all symbols.
-    MCSymbol *CreateTemporarySymbol(StringRef Name = "");
+    MCSymbol *GetOrCreateTemporarySymbol(StringRef Name = "");
+    MCSymbol *GetOrCreateTemporarySymbol(const Twine &Name);
 
     /// LookupSymbol - Get the symbol for \p Name, or null.
     MCSymbol *LookupSymbol(StringRef Name) const;

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=98118&r1=98117&r2=98118&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue Mar  9 19:29:27 2010
@@ -23,16 +23,8 @@
   // we don't need to free them here.
 }
 
-MCSymbol *MCContext::CreateSymbol(StringRef Name) {
-  assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
-
-  // Create and bind the symbol, and ensure that names are unique.
-  MCSymbol *&Entry = Symbols[Name];
-  assert(!Entry && "Duplicate symbol definition!");
-  return Entry = new (*this) MCSymbol(Name, false);
-}
-
 MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
+  assert(!Name.empty() && "Normal symbols cannot be unnamed!");
   MCSymbol *&Entry = Symbols[Name];
   if (Entry) return Entry;
 
@@ -46,17 +38,24 @@
 }
 
 
-MCSymbol *MCContext::CreateTemporarySymbol(StringRef Name) {
+MCSymbol *MCContext::GetOrCreateTemporarySymbol(StringRef Name) {
   // If unnamed, just create a symbol.
   if (Name.empty())
     new (*this) MCSymbol("", true);
     
   // Otherwise create as usual.
   MCSymbol *&Entry = Symbols[Name];
-  assert(!Entry && "Duplicate symbol definition!");
+  if (Entry) return Entry;
   return Entry = new (*this) MCSymbol(Name, true);
 }
 
+MCSymbol *MCContext::GetOrCreateTemporarySymbol(const Twine &Name) {
+  SmallString<128> NameSV;
+  Name.toVector(NameSV);
+  return GetOrCreateTemporarySymbol(NameSV.str());
+}
+
+
 MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
   return Symbols.lookup(Name);
 }

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=98118&r1=98117&r2=98118&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Mar  9 19:29:27 2010
@@ -240,14 +240,10 @@
 }
 
 MCSymbol *AsmParser::CreateSymbol(StringRef Name) {
-  if (MCSymbol *S = Ctx.LookupSymbol(Name))
-    return S;
-
   // If the label starts with L it is an assembler temporary label.
   if (Name.startswith("L"))
-    return Ctx.CreateTemporarySymbol(Name);
-
-  return Ctx.CreateSymbol(Name);
+    return Ctx.GetOrCreateTemporarySymbol(Name);
+  return Ctx.GetOrCreateSymbol(Name);
 }
 
 /// ParsePrimaryExpr - Parse a primary expression and return it.





More information about the llvm-commits mailing list