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

Chris Lattner lattner at cs.uiuc.edu
Mon Feb 6 15:41:00 PST 2006



Changes in directory llvm/utils/TableGen:

AsmWriterEmitter.cpp updated: 1.26 -> 1.27
---
Log message:

Add support for modifier strings in machine instr descriptions.  This allows
us to avoid creating lots of "Operand" types with different printers, instead
we can fold several together and use modifiers.  For example, we can now use:

${target:call} to say that the operand should be printed like a 'call' operand.



---
Diffs of the changes:  (+38 -6)

 AsmWriterEmitter.cpp |   44 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 38 insertions(+), 6 deletions(-)


Index: llvm/utils/TableGen/AsmWriterEmitter.cpp
diff -u llvm/utils/TableGen/AsmWriterEmitter.cpp:1.26 llvm/utils/TableGen/AsmWriterEmitter.cpp:1.27
--- llvm/utils/TableGen/AsmWriterEmitter.cpp:1.26	Mon Feb  6 16:43:28 2006
+++ llvm/utils/TableGen/AsmWriterEmitter.cpp	Mon Feb  6 17:40:48 2006
@@ -37,17 +37,23 @@
     /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
     /// machine instruction.
     unsigned MIOpNo;
+    
+    /// MiModifier - For isMachineInstrOperand, this is the modifier string for
+    /// an operand, specified with syntax like ${opname:modifier}.
+    std::string MiModifier;
 
     AsmWriterOperand(const std::string &LitStr)
       : OperandType(isLiteralTextOperand), Str(LitStr) {}
 
-    AsmWriterOperand(const std::string &Printer, unsigned OpNo) 
-      : OperandType(isMachineInstrOperand), Str(Printer), MIOpNo(OpNo) {}
+    AsmWriterOperand(const std::string &Printer, unsigned OpNo, 
+                     const std::string &Modifier) 
+      : OperandType(isMachineInstrOperand), Str(Printer), MIOpNo(OpNo),
+      MiModifier(Modifier) {}
 
     bool operator!=(const AsmWriterOperand &Other) const {
       if (OperandType != Other.OperandType || Str != Other.Str) return true;
       if (OperandType == isMachineInstrOperand)
-        return MIOpNo != Other.MIOpNo;
+        return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
       return false;
     }
     bool operator==(const AsmWriterOperand &Other) const {
@@ -84,8 +90,12 @@
 void AsmWriterOperand::EmitCode(std::ostream &OS) const {
   if (OperandType == isLiteralTextOperand)
     OS << "O << \"" << Str << "\"; ";
-  else
-    OS << Str << "(MI, " << MIOpNo << "); ";
+  else {
+    OS << Str << "(MI, " << MIOpNo;
+    if (!MiModifier.empty())
+      OS << ", \"" << MiModifier << '"';
+    OS << "); ";
+  }
 }
 
 
@@ -155,6 +165,10 @@
       std::string VarName(AsmString.begin()+DollarPos+1,
                           AsmString.begin()+VarEnd);
 
+      // Modifier - Support ${foo:modifier} syntax, where "modifier" is passed
+      // into printOperand.
+      std::string Modifier;
+      
       // In order to avoid starting the next string at the terminating curly
       // brace, advance the end position past it if we found an opening curly
       // brace.
@@ -162,6 +176,23 @@
         if (VarEnd >= AsmString.size())
           throw "Reached end of string before terminating curly brace in '"
                 + CGI.TheDef->getName() + "'";
+        
+        // Look for a modifier string.
+        if (AsmString[VarEnd] == ':') {
+          ++VarEnd;
+          if (VarEnd >= AsmString.size())
+            throw "Reached end of string before terminating curly brace in '"
+              + CGI.TheDef->getName() + "'";
+          
+          unsigned ModifierStart = VarEnd;
+          while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
+            ++VarEnd;
+          Modifier = std::string(AsmString.begin()+ModifierStart,
+                                 AsmString.begin()+VarEnd);
+          if (Modifier.empty())
+            throw "Bad operand modifier name in '"+ CGI.TheDef->getName() + "'";
+        }
+        
         if (AsmString[VarEnd] != '}')
           throw "Variable name beginning with '{' did not end with '}' in '"
                 + CGI.TheDef->getName() + "'";
@@ -185,7 +216,8 @@
       }
 
       if (CurVariant == Variant || CurVariant == ~0U) 
-        Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp));
+        Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp,
+                                            Modifier));
       LastEmitted = VarEnd;
     }
   }






More information about the llvm-commits mailing list