add a twine version of MCContext::GetOrCreateSymbol.
authorChris Lattner <sabre@nondot.org>
Mon, 19 Oct 2009 22:49:00 +0000 (22:49 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 19 Oct 2009 22:49:00 +0000 (22:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84561 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
lib/MC/MCContext.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

index e577ef53d13a0fb3e876b862f4b1988c06aa0b45..fa20f4506465750cb53a8c352debb14e6407bd21 100644 (file)
@@ -19,6 +19,7 @@ namespace llvm {
   class MCSection;
   class MCSymbol;
   class StringRef;
+  class Twine;
 
   /// MCContext - Context object for machine code objects.  This class owns all
   /// of the sections that it creates.
@@ -58,6 +59,7 @@ namespace llvm {
     /// @param IsTemporary - Whether this symbol is an assembler temporary,
     /// which should not survive into the symbol table for the translation unit.
     MCSymbol *GetOrCreateSymbol(const StringRef &Name);
+    MCSymbol *GetOrCreateSymbol(const Twine &Name);
 
     /// CreateTemporarySymbol - Create a new temporary symbol with the specified
     /// @param Name.
index db59f7f505c6d39976fb8ca2809eb31071c43899..09479c595a9ee0b2312d45b39b10e3180fc75a23 100644 (file)
@@ -8,10 +8,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/MC/MCContext.h"
-
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/MC/MCValue.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
 using namespace llvm;
 
 MCContext::MCContext() {
@@ -38,6 +39,13 @@ MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
   return Entry = new (*this) MCSymbol(Name, false);
 }
 
+MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
+  SmallString<128> NameSV;
+  Name.toVector(NameSV);
+  return GetOrCreateSymbol(NameSV.str());
+}
+
+
 MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
   // If unnamed, just create a symbol.
   if (Name.empty())
index 7e89b9f5e92ea65a5d068bb9417c217f9dd3db94..576cc9c529e7535fc3e0c55ec110b9a231d77691 100644 (file)
@@ -173,7 +173,7 @@ namespace {
         else {
           // FIXME: Remove this when Darwin transition to @GOT like syntax.
           Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
-          MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name.c_str());
+          MCSymbol *Sym = OutContext.GetOrCreateSymbol(StringRef(Name));
           
           MachineModuleInfoMachO &MMIMachO =
             MMI->getObjFileInfo<MachineModuleInfoMachO>();
@@ -1336,10 +1336,11 @@ void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) {
     
     // Emit the label.
     // FIXME: MOVE TO SHARED PLACE.
-    SmallString<60> Name;
     unsigned Id = (unsigned)MI->getOperand(2).getImm();
-    raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "PC" << Id;
-    OutStreamer.EmitLabel(OutContext.GetOrCreateSymbol(Name.str()));
+    const char *Prefix = MAI->getPrivateGlobalPrefix();
+    MCSymbol *Label =
+      OutContext.GetOrCreateSymbol(Twine(Prefix)+"PC"+Twine(Id));
+    OutStreamer.EmitLabel(Label);
     
     
     // Form and emit tha dd.
index a07d82d90e76e9d0d35df1bf32e72b5c01af06fd..ae8e6d3db4622b599500cfbc8b5711d7a2376d5d 100644 (file)
@@ -288,12 +288,12 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) {
     std::string Name = Mang->makeNameProper(MO.getSymbolName());
     if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
       Name += "$stub";
-      MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
+      MCSymbol *Sym = OutContext.GetOrCreateSymbol(StringRef(Name));
       const MCSymbol *&StubSym =
         MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
       if (StubSym == 0) {
         Name.erase(Name.end()-5, Name.end());
-        StubSym = OutContext.GetOrCreateSymbol(Name);
+        StubSym = OutContext.GetOrCreateSymbol(StringRef(Name));
       }
     }