[llvm-commits] [llvm] r75490 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h include/llvm/Target/TargetAsmInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/Target/TargetAsmInfo.cpp utils/TableGen/AsmWriterEmitter.cpp

David Greene greened at obbligato.org
Mon Jul 13 13:25:49 PDT 2009


Author: greened
Date: Mon Jul 13 15:25:48 2009
New Revision: 75490

URL: http://llvm.org/viewvc/llvm-project?rev=75490&view=rev
Log:

Add infrastructure to allow post instruction printing action triggers.
We'll eventually use this to print comments in asm files and do other
fun things.

This adds interfaces to the AsmPrinter and changes TableGen to invoke
the postInstructionAction when appropriate.  It also add parameters to
TargetAsmInfo to control comment layout.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=75490&r1=75489&r2=75490&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Jul 13 15:25:48 2009
@@ -34,6 +34,7 @@
   class MachineConstantPoolEntry;
   class MachineConstantPoolValue;
   class MachineModuleInfo;
+  class MCInst;
   class DwarfWriter;
   class Mangler;
   class Section;
@@ -64,7 +65,7 @@
     
     /// DW - If available, this is a pointer to the current dwarf writer.
     DwarfWriter *DW;
-    
+
   public:
     /// Output stream on which we're printing assembly code.
     ///
@@ -332,6 +333,17 @@
     /// debug tables.
     void printDeclare(const MachineInstr *MI) const;
 
+    /// postInstructionAction - Handling printing of items after the
+    /// instruction iteself has been printed (e.g. comments)
+    void postInstructionAction(const MachineInstr &MI) const {
+      postInstructionActionImpl(MI);
+      EmitComments(MI);
+    }
+    void postInstructionAction(const MCInst &MI) const {
+      postInstructionActionImpl(MI);
+      EmitComments(MI);
+    }
+    
   protected:
     /// EmitZeros - Emit a block of zeros.
     ///
@@ -396,7 +408,7 @@
 
     /// printOffset - This is just convenient handler for printing offsets.
     void printOffset(int64_t Offset) const;
-
+ 
   private:
     const GlobalValue *findGlobalValue(const Constant* CV);
     void EmitLLVMUsedList(Constant *List);
@@ -408,6 +420,14 @@
     void EmitGlobalConstantFP(const ConstantFP* CFP, unsigned AddrSpace);
     void EmitGlobalConstantLargeInt(const ConstantInt* CI, unsigned AddrSpace);
     GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
+
+    /// EmitComments - Pretty-print comments for instructions
+    void EmitComments(const MachineInstr &MI) const;
+    /// EmitComments - Pretty-print comments for instructions
+    void EmitComments(const MCInst &MI) const;
+
+    virtual void postInstructionActionImpl(const MachineInstr &MI) const {}
+    virtual void postInstructionActionImpl(const MCInst &MI) const {}
   };
 }
 

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=75490&r1=75489&r2=75490&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Mon Jul 13 15:25:48 2009
@@ -214,6 +214,10 @@
     /// measure inline asm instructions.
     char SeparatorChar;                   // Defaults to ';'
 
+    /// CommentColumn - This indicates the comment num (zero-based) at
+    /// which asm comments should be printed.
+    unsigned CommentColumn;               // Defaults to 60
+
     /// CommentString - This indicates the comment character used by the
     /// assembler.
     const char *CommentString;            // Defaults to "#"
@@ -693,6 +697,9 @@
     char getSeparatorChar() const {
       return SeparatorChar;
     }
+    const unsigned getCommentColumn() const {
+      return CommentColumn;
+    }
     const char *getCommentString() const {
       return CommentString;
     }

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Jul 13 15:25:48 2009
@@ -24,6 +24,7 @@
 #include "llvm/Analysis/DebugInfo.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetAsmInfo.h"
@@ -1748,3 +1749,15 @@
   cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
   llvm_unreachable();
 }
+
+/// EmitComments - Pretty-print comments for instructions
+void AsmPrinter::EmitComments(const MachineInstr &MI) const
+{
+  // No comments in MachineInstr yet
+}
+
+/// EmitComments - Pretty-print comments for instructions
+void AsmPrinter::EmitComments(const MCInst &MI) const
+{
+  // No comments in MCInst yet
+}

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=75490&r1=75489&r2=75490&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Mon Jul 13 15:25:48 2009
@@ -43,6 +43,7 @@
   MaxInstLength = 4;
   PCSymbol = "$";
   SeparatorChar = ';';
+  CommentColumn = 60;
   CommentString = "#";
   GlobalPrefix = "";
   PrivateGlobalPrefix = ".";

Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=75490&r1=75489&r2=75490&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Mon Jul 13 15:25:48 2009
@@ -259,8 +259,6 @@
       LastEmitted = VarEnd;
     }
   }
-
-  AddLiteralString("\\n");
 }
 
 /// MatchesAllButOneOp - If this instruction is exactly identical to the
@@ -357,7 +355,6 @@
     }
     O << "\n";
   }
-
   O << "    break;\n";
 }
 
@@ -385,8 +382,12 @@
     Command = "    " + Inst->Operands[0].getCode() + "\n";
 
     // If this is the last operand, emit a return.
-    if (Inst->Operands.size() == 1)
+    if (Inst->Operands.size() == 1) {
+      Command += "    postInstructionAction(*MI);\n";
+      // Print the final newline
+      Command += "    O << \"\\n\";\n";
       Command += "    return true;\n";
+    }
     
     // Check to see if we already have 'Command' in UniqueOperandCommands.
     // If not, add it.
@@ -452,8 +453,12 @@
       std::string Command = "    " + FirstInst->Operands[Op].getCode() + "\n";
       
       // If this is the last operand, emit a return after the code.
-      if (FirstInst->Operands.size() == Op+1)
+      if (FirstInst->Operands.size() == Op+1) {
+        Command += "    postInstructionAction(*MI);\n";
+        // Print the final newline
+        Command += "    O << \"\\n\";\n";
         Command += "    return true;\n";
+      }
       
       UniqueOperandCommands[CommandIdx] += Command;
       InstOpsUsed[CommandIdx]++;
@@ -564,10 +569,11 @@
     // For the first operand check, add a default value for instructions with
     // just opcode strings to use.
     if (isFirst) {
-      UniqueOperandCommands.push_back("    return true;\n");
+      // Do the post instruction processing and print the final newline
+      UniqueOperandCommands.push_back("    postInstructionAction(*MI);\n    O << \"\\n\";\n    return true;\n");
       isFirst = false;
     }
-    
+
     std::vector<unsigned> InstIdxs;
     std::vector<unsigned> NumInstOpsHandled;
     FindUniqueOperandCommands(UniqueOperandCommands, InstIdxs,
@@ -739,6 +745,9 @@
       EmitInstructions(Instructions, O);
 
     O << "  }\n";
+    O << "  postInstructionAction(*MI);\n";
+    // Print the final newline
+    O << "  O << \"\\n\";\n";
     O << "  return true;\n";
   }
   





More information about the llvm-commits mailing list