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

David Greene greened at obbligato.org
Wed Aug 5 14:01:28 PDT 2009


Author: greened
Date: Wed Aug  5 16:00:52 2009
New Revision: 78243

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

Fix some column padding bugs, reorganize things as suggested by Chris
and eliminate complexity.  Yay!

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.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=78243&r1=78242&r2=78243&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Wed Aug  5 16:00:52 2009
@@ -327,6 +327,12 @@
     void EmitComments(const MCInst &MI) const;
 
   protected:
+    /// getOperandColumn - Return the output column number (zero-based)
+    /// for operand % "operand."  If TargetAsmInfo has FirstOperandColumn
+    /// == 0 or MaxOperandLength == 0, return 0, meaning column alignment
+    /// is disabled.
+    unsigned getOperandColumn(int operand) const;
+
     /// PadToColumn - This gets called every time a tab is emitted.  If
     /// column padding is turned on, we replace the tab with the
     /// appropriate amount of padding.  If not, we replace the tab with a

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Wed Aug  5 16:00:52 2009
@@ -361,8 +361,11 @@
     const char *getCommentString() const {
       return CommentString;
     }
-    unsigned getOperandColumn(int operand) const {
-      return FirstOperandColumn + (MaxOperandLength+1)*(operand-1);
+    unsigned getFirstOperandColumn() const {
+      return FirstOperandColumn;
+    }
+    unsigned getMaxOperandLength() const {
+      return MaxOperandLength;
     }
     const char *getGlobalPrefix() const {
       return GlobalPrefix;

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

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Aug  5 16:00:52 2009
@@ -782,6 +782,20 @@
     }
   O << '\n';
 }
+
+/// getOperandColumn - Return the output column number (zero-based)
+/// for operand % "operand."  If TargetAsmInfo has FirstOperandColumn
+/// == 0 or MaxOperandLength == 0, return 0, meaning column alignment
+/// is disabled.
+unsigned AsmPrinter::getOperandColumn(int operand) const {
+  if (TAI->getFirstOperandColumn() > 0 && TAI->getMaxOperandLength() > 0) {
+    return TAI->getFirstOperandColumn()
+      + (TAI->getMaxOperandLength()+1)*(operand-1);
+  }
+  else {
+    return 0;
+  }
+}
     
 /// PadToColumn - This gets called every time a tab is emitted.  If
 /// column padding is turned on, we replace the tab with the
@@ -789,8 +803,8 @@
 /// space, except for the first operand so that initial operands are
 /// always lined up by tabs.
 void AsmPrinter::PadToColumn(unsigned Operand) const {
-  if (TAI->getOperandColumn(Operand) > 0) {
-    O.PadToColumn(TAI->getOperandColumn(Operand), 1);
+  if (getOperandColumn(Operand) > 0) {
+    O.PadToColumn(getOperandColumn(Operand), 1);
   }
   else {
     if (Operand == 1) {

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

==============================================================================
--- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Wed Aug  5 16:00:52 2009
@@ -148,8 +148,6 @@
 
     // Emit a constant string fragment.
 
-    // TODO: Recognize an operand separator to determine when to pad
-    // to the next operator.
     if (DollarPos != LastEmitted) {
       if (CurVariant == Variant || CurVariant == ~0U) {
         for (; LastEmitted != DollarPos; ++LastEmitted)
@@ -727,30 +725,10 @@
 
   O << "  // Emit the opcode for the instruction.\n"
     << "  unsigned Bits = OpInfo[MI->getOpcode()];\n"
-    << "  if (Bits == 0) return false;\n\n";
-  
-  O << "  unsigned OperandColumn = 1;\n\n"
-    << "  if (TAI->getOperandColumn(1) > 0) {\n"
-    << "    // Don't emit trailing whitespace, let the column padding do it.  This\n"
-    << "    // guarantees that a stray long opcode + tab won't upset the alignment.\n"
-    << "    // We need to handle this special case here because sometimes the initial\n"
-    << "    // mnemonic string includes a tab or space and sometimes it doesn't.\n"
-    << "    unsigned OpLength = std::strlen(AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "));\n"
-    << "    if (OpLength > 0 &&\n"
-    << "        ((AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == ' ' ||\n"
-    << "         (AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == '\\t')) {\n"
-    << "      do {\n"
-    << "        --OpLength;\n"
-    << "      } while ((AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == ' ' ||\n"
-    << "               (AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == '\\t');\n"
-    << "      for (unsigned Idx = 0; Idx < OpLength; ++Idx)\n"
-    << "        O << (AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[Idx];\n"
-    << "      O.PadToColumn(TAI->getOperandColumn(OperandColumn++), 1);\n"
-    << "    }\n"
-    << "  } else {\n"
-    << "    O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n"
-    << "  }\n\n";
-  
+    << "  if (Bits == 0) return false;\n"
+    << "  O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n\n";
+
+  O << "  unsigned OperandColumn = 1;\n\n";
 
   // Output the table driven operand information.
   BitsLeft = 32-AsmStrBits;





More information about the llvm-commits mailing list