[llvm-commits] CVS: llvm/utils/TableGen/AsmWriterEmitter.cpp

Chris Lattner sabre at nondot.org
Tue Sep 26 16:45:23 PDT 2006



Changes in directory llvm/utils/TableGen:

AsmWriterEmitter.cpp updated: 1.41 -> 1.42
---
Log message:

Add support for ${:foo} syntax, where "foo" is passed into "printSpecial" and
has no associated operand.  This is useful for portably encoding stuff like
the comment character into an asm string.


---
Diffs of the changes:  (+25 -16)

 AsmWriterEmitter.cpp |   41 +++++++++++++++++++++++++----------------
 1 files changed, 25 insertions(+), 16 deletions(-)


Index: llvm/utils/TableGen/AsmWriterEmitter.cpp
diff -u llvm/utils/TableGen/AsmWriterEmitter.cpp:1.41 llvm/utils/TableGen/AsmWriterEmitter.cpp:1.42
--- llvm/utils/TableGen/AsmWriterEmitter.cpp:1.41	Mon Sep  4 21:12:02 2006
+++ llvm/utils/TableGen/AsmWriterEmitter.cpp	Tue Sep 26 18:45:08 2006
@@ -98,7 +98,9 @@
   if (OperandType == isLiteralTextOperand)
     return "O << \"" + Str + "\"; ";
 
-  std::string Result = Str + "(MI, " + utostr(MIOpNo);
+  std::string Result = Str + "(MI";
+  if (MIOpNo != ~0U)
+    Result += ", " + utostr(MIOpNo);
   if (!MiModifier.empty())
     Result += ", \"" + MiModifier + '"';
   return Result + "); ";
@@ -172,7 +174,8 @@
                           AsmString.begin()+VarEnd);
 
       // Modifier - Support ${foo:modifier} syntax, where "modifier" is passed
-      // into printOperand.
+      // into printOperand.  Also support ${:feature}, which is passed into
+      // printSpecial.
       std::string Modifier;
       
       // In order to avoid starting the next string at the terminating curly
@@ -204,23 +207,29 @@
                 + CGI.TheDef->getName() + "'";
         ++VarEnd;
       }
-      if (VarName.empty())
+      if (VarName.empty() && Modifier.empty())
         throw "Stray '$' in '" + CGI.TheDef->getName() +
               "' asm string, maybe you want $$?";
 
-      unsigned OpNo = CGI.getOperandNamed(VarName);
-      CodeGenInstruction::OperandInfo OpInfo = CGI.OperandList[OpNo];
-
-      // If this is a two-address instruction, verify the second operand isn't
-      // used.
-      unsigned MIOp = OpInfo.MIOperandNo;
-      if (CGI.isTwoAddress && MIOp == 1)
-        throw "Should refer to operand #0 instead of #1 for two-address"
-              " instruction '" + CGI.TheDef->getName() + "'!";
-
-      if (CurVariant == Variant || CurVariant == ~0U) 
-        Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp,
-                                            Modifier));
+      if (VarName.empty()) {
+        // Just a modifier, pass this into printSpecial.
+        Operands.push_back(AsmWriterOperand("printSpecial", ~0U, Modifier));
+      } else {
+        // Otherwise, normal operand.
+        unsigned OpNo = CGI.getOperandNamed(VarName);
+        CodeGenInstruction::OperandInfo OpInfo = CGI.OperandList[OpNo];
+
+        // If this is a two-address instruction, verify the second operand isn't
+        // used.
+        unsigned MIOp = OpInfo.MIOperandNo;
+        if (CGI.isTwoAddress && MIOp == 1)
+          throw "Should refer to operand #0 instead of #1 for two-address"
+                " instruction '" + CGI.TheDef->getName() + "'!";
+        
+        if (CurVariant == Variant || CurVariant == ~0U) 
+          Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp,
+                                              Modifier));
+      }
       LastEmitted = VarEnd;
     }
   }






More information about the llvm-commits mailing list