]> granicus.if.org Git - clang/commitdiff
Improvements to inline asm code generation.
authorAnders Carlsson <andersca@mac.com>
Tue, 5 Feb 2008 23:18:57 +0000 (23:18 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 5 Feb 2008 23:18:57 +0000 (23:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46779 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGStmt.cpp

index c65197085054a36ef8aa9f72ad16c7ded11f2c44..557588e9ac457cc29ae653b62e71a4ec5c91f099 100644 (file)
@@ -506,13 +506,30 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
 }
 
 static inline std::string ConvertAsmString(const char *Start,
-                                           unsigned NumOperands)
+                                           unsigned NumOperands,
+                                           bool IsSimple)
 {
   static unsigned AsmCounter = 0;
   
   AsmCounter++;
   
   std::string Result;
+  if (IsSimple) {
+    while (*Start) {
+      switch (*Start) {
+      default:
+        Result += *Start;
+        break;
+      case '$':
+        Result += "$$";
+        break;
+      }
+      
+      Start++;
+    }
+    
+    return Result;
+  }
   
   while (*Start) {
     switch (*Start) {
@@ -552,6 +569,21 @@ static inline std::string ConvertAsmString(const char *Start,
         }
         
         Result += '$' + llvm::utostr(n);
+        Start = End;
+      } else if (isalpha(EscapedChar)) {
+        char *End;
+        
+        unsigned long n = strtoul(Start + 1, &End, 10);
+        if (Start == End) {
+          // FIXME: This should be caught during Sema.
+          assert(0 && "Missing operand!");
+        } else if (n >= NumOperands) {
+          // FIXME: This should be caught during Sema.
+          assert(0 && "Operand number out of range!");
+        }
+        
+        Result += "${" + llvm::utostr(n) + ':' + EscapedChar + '}';
+        Start = End;
       } else {
         assert(0 && "Unhandled asm escaped character!");
       }
@@ -591,7 +623,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   std::string AsmString = 
     ConvertAsmString(std::string(S.getAsmString()->getStrData(),
                                  S.getAsmString()->getByteLength()).c_str(),
-                     S.getNumOutputs() + S.getNumInputs());
+                     S.getNumOutputs() + S.getNumInputs(), S.isSimple());
   
   std::string Constraints;