[cfe-commits] r66532 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp test/CodeGen/asm.c

Chris Lattner sabre at nondot.org
Mon Mar 9 23:38:02 PDT 2009


Author: lattner
Date: Tue Mar 10 01:38:02 2009
New Revision: 66532

URL: http://llvm.org/viewvc/llvm-project?rev=66532&view=rev
Log:
reduce duplication of parsing code between %0 and %x0 and
add support for modifiers on named references, like %c[foo].


Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/test/CodeGen/asm.c

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=66532&r1=66531&r2=66532&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Tue Mar 10 01:38:02 2009
@@ -739,31 +739,27 @@
       continue;
     }
     
+    // Handle %x4 and %x[foo] by capturing x as the modifier character.
+    char Modifier = '\0';
+    if (isalpha(EscapedChar)) {
+      Modifier = EscapedChar;
+      EscapedChar = *StrStart++;
+    }
+    
     if (isdigit(EscapedChar)) {
       // %n - Assembler operand n
       char *End;
       unsigned long N = strtoul(StrStart-1, &End, 10);
       assert(End != StrStart-1 && "We know that EscapedChar is a digit!");
-      
-      // FIXME: This should be caught during Sema.
-      assert(N < NumOperands && "Operand number out of range!");
-      
-      Result += '$' + llvm::utostr(N);
       StrStart = End;
-      continue;
-    }
-    
-    if (isalpha(EscapedChar)) {
-      char *End;
-      // Skip the single letter escape and read the number, e.g. "%x4".
-      unsigned long N = strtoul(StrStart, &End, 10);
-      // FIXME: This should be caught during Sema.
-      assert(End != StrStart && "Missing operand!");
+      
       // FIXME: This should be caught during Sema.
       assert(N < NumOperands && "Operand number out of range!");
       
-      Result += "${" + llvm::utostr(N) + ':' + EscapedChar + '}';
-      StrStart = End;
+      if (Modifier == '\0')
+        Result += '$' + llvm::utostr(N);
+      else
+        Result += "${" + llvm::utostr(N) + ':' + Modifier + '}';
       continue;
     }
     
@@ -776,10 +772,13 @@
       std::string SymbolicName(StrStart, NameEnd);
       StrStart = NameEnd+1;
       
-      int OperandIndex = S.getNamedOperand(SymbolicName);
-      assert(OperandIndex != -1 && "FIXME: Catch in Sema.");
+      int N = S.getNamedOperand(SymbolicName);
+      assert(N != -1 && "FIXME: Catch in Sema.");
 
-      Result += '$' + llvm::utostr(unsigned(OperandIndex));
+      if (Modifier == '\0')
+        Result += '$' + llvm::utostr(N);
+      else
+        Result += "${" + llvm::utostr(N) + ':' + Modifier + '}';
       continue;
     }
      

Modified: cfe/trunk/test/CodeGen/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm.c?rev=66532&r1=66531&r2=66532&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/asm.c (original)
+++ cfe/trunk/test/CodeGen/asm.c Tue Mar 10 01:38:02 2009
@@ -31,4 +31,9 @@
 // RUN: grep "T7 NAMED: \$2" %t
 void t7(int a) {
   __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4));
-}
\ No newline at end of file
+}
+
+// RUN: grep "T8 NAMED MODIFIER: \${0:c}" %t
+void t8() {
+  __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4));
+}





More information about the cfe-commits mailing list