[cfe-commits] r62441 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/TargetInfo.cpp lib/CodeGen/CGStmt.cpp test/Sema/asm.c
Anders Carlsson
andersca at mac.com
Sat Jan 17 17:56:57 PST 2009
Author: andersca
Date: Sat Jan 17 19:56:57 2009
New Revision: 62441
URL: http://llvm.org/viewvc/llvm-project?rev=62441&view=rev
Log:
Add sema support for symbolic names in inline asm statements.
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/Sema/asm.c
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=62441&r1=62440&r2=62441&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Sat Jan 17 19:56:57 2009
@@ -202,7 +202,11 @@
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);
}
Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=62441&r1=62440&r2=62441&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Sat Jan 17 19:56:57 2009
@@ -188,6 +188,36 @@
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 @@
// 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;
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=62441&r1=62440&r2=62441&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Jan 17 19:56:57 2009
@@ -980,7 +980,7 @@
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 += ',';
Modified: cfe/trunk/test/Sema/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=62441&r1=62440&r2=62441&view=diff
==============================================================================
--- cfe/trunk/test/Sema/asm.c (original)
+++ cfe/trunk/test/Sema/asm.c Sat Jan 17 19:56:57 2009
@@ -10,7 +10,11 @@
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
More information about the cfe-commits
mailing list