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

Nate Begeman natebegeman at mac.com
Thu Jul 14 15:50:41 PDT 2005



Changes in directory llvm/utils/TableGen:

AsmWriterEmitter.cpp updated: 1.19 -> 1.20
---
Log message:

Add support for a TODO; instructions in .td files can now have arguments
printed as part of the opcode.  This allows something like
cmp${cc}ss in the x86 backed to be printed as cmpltss, cmpless, etc.
depending on what the value of $cc is.


---
Diffs of the changes:  (+24 -1)

 AsmWriterEmitter.cpp |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletion(-)


Index: llvm/utils/TableGen/AsmWriterEmitter.cpp
diff -u llvm/utils/TableGen/AsmWriterEmitter.cpp:1.19 llvm/utils/TableGen/AsmWriterEmitter.cpp:1.20
--- llvm/utils/TableGen/AsmWriterEmitter.cpp:1.19	Thu Apr 21 19:00:35 2005
+++ llvm/utils/TableGen/AsmWriterEmitter.cpp	Thu Jul 14 17:50:30 2005
@@ -155,12 +155,35 @@
       LastEmitted = DollarPos+2;
     } else {
       // Get the name of the variable.
-      // TODO: should eventually handle ${foo}bar as $foo
       std::string::size_type VarEnd = DollarPos+1;
+
+      // handle ${foo}bar as $foo by detecting whether the character following
+      // the dollar sign is a curly brace.  If so, advance VarEnd and DollarPos
+      // so the variable name does not contain the leading curly brace.
+      bool hasCurlyBraces = false;
+      if (VarEnd < AsmString.size() && '{' == AsmString[VarEnd]) {
+        hasCurlyBraces = true;
+        ++DollarPos;
+        ++VarEnd;
+      }
+
       while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
         ++VarEnd;
       std::string VarName(AsmString.begin()+DollarPos+1,
                           AsmString.begin()+VarEnd);
+
+      // 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.
+      if (hasCurlyBraces) {
+        if (VarEnd >= AsmString.size())
+          throw "Reached end of string before terminating curly brace in '"
+                + CGI.Name + "'";
+        if (AsmString[VarEnd] != '}')
+          throw "Variant name beginning with '{' did not end with '}' in '"
+                + CGI.Name + "'";
+        ++VarEnd;
+      }
       if (VarName.empty())
         throw "Stray '$' in '" + CGI.Name + "' asm string, maybe you want $$?";
 






More information about the llvm-commits mailing list