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

Chris Lattner sabre at nondot.org
Fri Jan 22 11:52:01 PST 2010


Author: lattner
Date: Fri Jan 22 13:52:01 2010
New Revision: 94202

URL: http://llvm.org/viewvc/llvm-project?rev=94202&view=rev
Log:
Convert some more random-comment-printing stuff to use 
AddComment and GetCommentOS.  Add a blank line between globals
(even in non-verbose mode) to make the assembly more readable.

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

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=94202&r1=94201&r2=94202&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Fri Jan 22 13:52:01 2010
@@ -81,6 +81,9 @@
 
     MCContext &getContext() const { return Context; }
 
+    /// @name Assembly File Formatting.
+    /// @{
+
     /// AddComment - Add a comment that can be emitted to the generated .s
     /// file if applicable as a QoI issue to make the output of the compiler
     /// more readable.  This only affects the MCAsmStreamer, and only when
@@ -95,6 +98,11 @@
     /// use this method.
     virtual raw_ostream &GetCommentOS();
     
+    /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
+    virtual void AddBlankLine() {}
+    
+    /// @}
+    
     /// @name Symbol & Section Management
     /// @{
     

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=94202&r1=94201&r2=94202&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Jan 22 13:52:01 2010
@@ -32,6 +32,7 @@
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/Target/Mangler.h"
@@ -173,10 +174,9 @@
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
     
     if (VerboseAsm) {
-      O.PadToColumn(MAI->getCommentColumn());
-      O << MAI->getCommentString() << ' ';
-      WriteAsOperand(O, GV, /*PrintType=*/false, GV->getParent());
-      O << '\n';
+      WriteAsOperand(OutStreamer.GetCommentOS(), GV,
+                     /*PrintType=*/false, GV->getParent());
+      OutStreamer.GetCommentOS() << '\n';
     }
     
     // Handle common symbols.
@@ -266,10 +266,9 @@
 
   EmitAlignment(AlignLog, GV);
   if (VerboseAsm) {
-    O.PadToColumn(MAI->getCommentColumn());
-    O << MAI->getCommentString() << ' ';
-    WriteAsOperand(O, GV, /*PrintType=*/false, GV->getParent());
-    O << '\n';
+    WriteAsOperand(OutStreamer.GetCommentOS(), GV,
+                   /*PrintType=*/false, GV->getParent());
+    OutStreamer.GetCommentOS() << '\n';
   }
   OutStreamer.EmitLabel(GVSym);
 
@@ -277,6 +276,8 @@
 
   if (MAI->hasDotTypeDotSizeDirective())
     O << "\t.size\t" << *GVSym << ", " << Size << '\n';
+  
+  OutStreamer.AddBlankLine();
 }
 
 
@@ -1141,9 +1142,8 @@
   
   if (CFP->getType()->isFloatTy()) {
     if (AP.VerboseAsm) {
-      float Val = CFP->getValueAPF().convertToFloat();  // for comment only
-      AP.O.PadToColumn(AP.MAI->getCommentColumn());
-      AP.O << AP.MAI->getCommentString() << " float " << Val << '\n';
+      float Val = CFP->getValueAPF().convertToFloat();
+      AP.OutStreamer.GetCommentOS() << "float " << Val << '\n';
     }
     uint64_t Val = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
     AP.OutStreamer.EmitIntValue(Val, 4, AddrSpace);
@@ -1161,9 +1161,8 @@
       bool ignored;
       DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
                         &ignored);
-      AP.O.PadToColumn(AP.MAI->getCommentColumn());
-      AP.O << AP.MAI->getCommentString() << " x86_fp80 ~= "
-           << DoubleVal.convertToDouble() << '\n';
+      AP.OutStreamer.GetCommentOS() << "x86_fp80 ~= "
+        << DoubleVal.convertToDouble() << '\n';
     }
     
     if (AP.TM.getTargetData()->isBigEndian()) {
@@ -1226,12 +1225,8 @@
     case 2:
     case 4:
     case 8:
-      if (VerboseAsm) {
-        O.PadToColumn(MAI->getCommentColumn());
-        O << MAI->getCommentString() << " 0x";
-        O.write_hex(CI->getZExtValue());
-        O << '\n';
-      }
+      if (VerboseAsm)
+        OutStreamer.GetCommentOS() << format("0x%llx\n", CI->getZExtValue());
       OutStreamer.EmitIntValue(CI->getZExtValue(), Size, AddrSpace);
       return;
     default:
@@ -1670,30 +1665,32 @@
   // will be.
   if (MBB->hasAddressTaken()) {
     const BasicBlock *BB = MBB->getBasicBlock();
+    if (VerboseAsm)
+      OutStreamer.AddComment("Address Taken");
     OutStreamer.EmitLabel(GetBlockAddressSymbol(BB->getParent(), BB));
-    if (VerboseAsm) {
-      O.PadToColumn(MAI->getCommentColumn());
-      O << MAI->getCommentString() << " Address Taken" << '\n';
-    }
   }
 
   // Print the main label for the block.
   if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
-    if (VerboseAsm)
+    if (VerboseAsm) {
       O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
+      if (const BasicBlock *BB = MBB->getBasicBlock())
+        if (BB->hasName())
+          OutStreamer.AddComment("%" + BB->getName());
+      OutStreamer.AddBlankLine();
+    }
   } else {
+    if (VerboseAsm) {
+      if (const BasicBlock *BB = MBB->getBasicBlock())
+        if (BB->hasName())
+          OutStreamer.AddComment("%" + BB->getName());
+    }
     OutStreamer.EmitLabel(GetMBBSymbol(MBB->getNumber()));
   }
   
   // Print some comments to accompany the label.
-  if (VerboseAsm) {
-    if (const BasicBlock *BB = MBB->getBasicBlock())
-      if (BB->hasName()) {
-        O.PadToColumn(MAI->getCommentColumn());
-        O << MAI->getCommentString() << ' ';
-        WriteAsOperand(O, BB, /*PrintType=*/false);
-      }
-
+  // FIXME: REENABLE.
+  if (0 && VerboseAsm) {
     EmitComments(*MBB);
     O << '\n';
   }

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=94202&r1=94201&r2=94202&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Jan 22 13:52:01 2010
@@ -73,6 +73,11 @@
     return CommentStream;
   }
   
+  /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
+  virtual void AddBlankLine() {
+    EmitEOL();
+  }
+  
   /// @name MCStreamer Interface
   /// @{
 





More information about the llvm-commits mailing list