]> granicus.if.org Git - clang/commitdiff
Add sema support for symbolic names in inline asm statements.
authorAnders Carlsson <andersca@mac.com>
Sun, 18 Jan 2009 01:56:57 +0000 (01:56 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 18 Jan 2009 01:56:57 +0000 (01:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62441 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/TargetInfo.cpp
lib/CodeGen/CGStmt.cpp
test/Sema/asm.c

index ca755b907fa1a694bf941fc460642a9215cc5350..da14365e4dd59e8ea937df3e89017868885fdef5 100644 (file)
@@ -202,7 +202,11 @@ public:
                                const std::string *OutputNamesBegin,
                                const std::string *OutputNamesEnd,
                                ConstraintInfo &info) const;
-
+  bool resolveSymbolicName(const char *&Name,
+                           const std::string *OutputNamesBegin,
+                           const std::string *OutputNamesEnd,
+                           unsigned &Index) const;
+  
   virtual std::string convertConstraint(const char Constraint) const {
     return std::string(1, Constraint);
   }
index 2ea1f232bfde6b5af1cf9c9e3bbdaa881471a3d2..eb912d578e3619b21b5389d7e414b034591d8174 100644 (file)
@@ -188,6 +188,36 @@ bool TargetInfo::validateOutputConstraint(const char *Name,
   return true;
 }
 
+bool TargetInfo::resolveSymbolicName(const char *&Name,
+                                     const std::string *OutputNamesBegin,
+                                     const std::string *OutputNamesEnd,
+                                     unsigned &Index) const
+{
+  assert(*Name == '[' && "Symbolic name did not start with '['");
+
+  Name++;
+  const char *Start = Name;
+  while (*Name && *Name != ']')
+    Name++;
+  
+  if (!*Name) {
+    // Missing ']'
+    return false;
+  }
+  
+  std::string SymbolicName(Start, Name - Start);
+  
+  Index = 0;
+  for (const std::string *it = OutputNamesBegin; 
+       it != OutputNamesEnd; 
+       ++it, Index++) {
+    if (SymbolicName == *it)
+      return true;
+  }
+
+  return false;
+}
+
 bool TargetInfo::validateInputConstraint(const char *Name,
                                          const std::string *OutputNamesBegin,
                                          const std::string *OutputNamesEnd,
@@ -210,7 +240,15 @@ bool TargetInfo::validateInputConstraint(const char *Name,
         // add more constraints as we hit it.  Eventually, an unknown
         // constraint should just be treated as 'g'.
         return false;
-      }        
+      }
+      break;
+    case '[': {
+      unsigned Index = 0;
+      if (!resolveSymbolicName(Name, OutputNamesBegin, OutputNamesEnd, Index))
+        return false;
+    
+      break;
+    }          
     case '%': // commutative
       // FIXME: Fail if % is used with the last operand.
       break;
index d86c3f4389110ed609fdd1b6e7518aa9acf91598..04fc26dd89557c61da464fc9b9b6c9d47a39b067 100644 (file)
@@ -980,7 +980,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
                                                  S.begin_output_names(),
                                                  S.end_output_names(),
                                                  Info);
-    assert(result && "Failed to parse input constraint"); result=result;
+    assert(result && "Failed to parse input constraint");
     
     if (i != 0 || S.getNumOutputs() > 0)
       Constraints += ',';
index d29335a924ffd487e76fcce1c2688c74a6ccfc5c..3bb7d78f5bc4f283a79efa293bc8b69e8243d2ab 100644 (file)
@@ -10,7 +10,11 @@ f()
   
   asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}}
   asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}}
-  
+
+  asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i));
+  asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}}
+  asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}}
+  asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}}
 }
 
 void