[llvm-commits] [llvm] r100294 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/MC/MCStreamer.cpp

Chris Lattner sabre at nondot.org
Sat Apr 3 15:12:35 PDT 2010


Author: lattner
Date: Sat Apr  3 17:12:35 2010
New Revision: 100294

URL: http://llvm.org/viewvc/llvm-project?rev=100294&view=rev
Log:
add a twine form of MCStreamer::EmitRawText, and mc'ize
a few more things in AsmPrinter.cpp.

Modified:
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/MC/MCStreamer.cpp

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=100294&r1=100293&r2=100294&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Sat Apr  3 17:12:35 2010
@@ -286,6 +286,7 @@
     /// the specified string in the output .s file.  This capability is
     /// indicated by the hasRawTextSupport() predicate.  By default this aborts.
     virtual void EmitRawText(StringRef String);
+    void EmitRawText(const Twine &String);
     
     /// Finish - Finish emission of machine code and flush any output.
     virtual void Finish() = 0;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=100294&r1=100293&r2=100294&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sat Apr  3 17:12:35 2010
@@ -164,7 +164,7 @@
       // .linkonce discard
       // FIXME: It would be nice to use .linkonce samesize for non-common
       // globals.
-      O << LinkOnce;
+      OutStreamer.EmitRawText(LinkOnce);
     } else {
       // .weak _foo
       OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
@@ -1386,9 +1386,9 @@
   if (AsmStr[0] == 0) {
     if (!OutStreamer.hasRawTextSupport()) return;
 
-    OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+
+    OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
                             MAI->getInlineAsmStart());
-    OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+
+    OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
                             MAI->getInlineAsmEnd());
     return;
   }
@@ -1396,7 +1396,7 @@
   // Emit the #APP start marker.  This has to happen even if verbose-asm isn't
   // enabled, so we use EmitRawText.
   if (OutStreamer.hasRawTextSupport())
-    OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+
+    OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
                             MAI->getInlineAsmStart());
 
   // Emit the inline asm to a temporary string so we can emit it through
@@ -1584,7 +1584,7 @@
   // Emit the #NOAPP end marker.  This has to happen even if verbose-asm isn't
   // enabled, so we use EmitRawText.
   if (OutStreamer.hasRawTextSupport())
-    OutStreamer.EmitRawText(std::string("\t")+MAI->getCommentString()+
+    OutStreamer.EmitRawText(Twine("\t")+MAI->getCommentString()+
                             MAI->getInlineAsmEnd());
 }
 
@@ -1592,21 +1592,24 @@
 /// that is an implicit def.
 void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
   if (!VerboseAsm) return;
-  O.PadToColumn(MAI->getCommentColumn());
-  O << MAI->getCommentString() << " implicit-def: "
-    << TRI->getName(MI->getOperand(0).getReg());
+  OutStreamer.AddComment(Twine("implicit-def: ") +
+                         TRI->getName(MI->getOperand(0).getReg()));
   OutStreamer.AddBlankLine();
 }
 
 void AsmPrinter::printKill(const MachineInstr *MI) const {
   if (!VerboseAsm) return;
   O.PadToColumn(MAI->getCommentColumn());
-  O << MAI->getCommentString() << " kill:";
+  
+  std::string Str = "kill:";
   for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) {
-    const MachineOperand &op = MI->getOperand(n);
-    assert(op.isReg() && "KILL instruction must have only register operands");
-    O << ' ' << TRI->getName(op.getReg()) << (op.isDef() ? "<def>" : "<kill>");
+    const MachineOperand &Op = MI->getOperand(n);
+    assert(Op.isReg() && "KILL instruction must have only register operands");
+    Str += ' ';
+    Str += TRI->getName(Op.getReg());
+    Str += (Op.isDef() ? "<def>" : "<kill>");
   }
+  OutStreamer.AddComment(Str);
   OutStreamer.AddBlankLine();
 }
 
@@ -1772,15 +1775,16 @@
 
   // Print the main label for the block.
   if (MBB->pred_empty() || isBlockOnlyReachableByFallthrough(MBB)) {
-    if (VerboseAsm) {
-      // NOTE: Want this comment at start of line.
-      O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
+    if (VerboseAsm && OutStreamer.hasRawTextSupport()) {
       if (const BasicBlock *BB = MBB->getBasicBlock())
         if (BB->hasName())
           OutStreamer.AddComment("%" + BB->getName());
       
       PrintBasicBlockLoopComments(*MBB, LI, *this);
-      OutStreamer.AddBlankLine();
+      
+      // NOTE: Want this comment at start of line, don't emit with AddComment.
+      OutStreamer.EmitRawText(Twine(MAI->getCommentString()) + " BB#" +
+                              Twine(MBB->getNumber()) + ":");
     }
   } else {
     if (VerboseAsm) {

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=100294&r1=100293&r2=100294&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Sat Apr  3 17:12:35 2010
@@ -10,6 +10,8 @@
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
 #include <cstdlib>
 using namespace llvm;
 
@@ -54,3 +56,9 @@
   " something must not be fully mc'ized\n";
   abort();
 }
+
+void MCStreamer::EmitRawText(const Twine &T) {
+  SmallString<128> Str;
+  T.toVector(Str);
+  EmitRawText(Str.str());
+}





More information about the llvm-commits mailing list