summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-01-26 02:21:59 +0000
committerChris Lattner <sabre@nondot.org>2006-01-26 02:21:59 +0000
commitf0b415f178615714de38fb8196f49d131e54274b (patch)
tree165778fcae2266b04606e650b10d1710f418a709 /lib
parent507fdbc0e8cfece312779e45eb86f2320c75b87e (diff)
downloadllvm-f0b415f178615714de38fb8196f49d131e54274b.tar.gz
llvm-f0b415f178615714de38fb8196f49d131e54274b.tar.bz2
llvm-f0b415f178615714de38fb8196f49d131e54274b.tar.xz
add method for constraint parsing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25637 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/InlineAsm.cpp79
1 files changed, 50 insertions, 29 deletions
diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp
index 3ccd8aca7e..e9a81e4ed8 100644
--- a/lib/VMCore/InlineAsm.cpp
+++ b/lib/VMCore/InlineAsm.cpp
@@ -38,25 +38,17 @@ const FunctionType *InlineAsm::getFunctionType() const {
return cast<FunctionType>(getType()->getElementType());
}
-/// Verify - Verify that the specified constraint string is reasonable for the
-/// specified function type, and otherwise validate the constraint string.
-bool InlineAsm::Verify(const FunctionType *Ty, const std::string &Constraints) {
- if (Ty->isVarArg()) return false;
-
- unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
+std::vector<std::pair<InlineAsm::ConstraintPrefix, std::string> >
+InlineAsm::ParseConstraints(const std::string &Constraints) {
+ std::vector<std::pair<InlineAsm::ConstraintPrefix, std::string> > Result;
// Scan the constraints string.
for (std::string::const_iterator I = Constraints.begin(),
- E = Constraints.end(); I != E; ) {
- if (*I == ',') return false; // Empty constraint like ",,"
+ E = Constraints.end(); I != E; ) {
+ if (*I == ',') { Result.clear(); break; } // Empty constraint like ",,"
// Parse the prefix.
- enum {
- isInput, // 'x'
- isOutput, // '=x'
- isIndirectOutput, // '==x'
- isClobber, // '~x'
- } ConstraintType = isInput;
+ ConstraintPrefix ConstraintType = isInput;
if (*I == '~') {
ConstraintType = isClobber;
@@ -71,9 +63,49 @@ bool InlineAsm::Verify(const FunctionType *Ty, const std::string &Constraints) {
}
}
- if (I == E) return false; // Just a prefix, like "==" or "~".
+ if (I == E) { Result.clear(); break; } // Just a prefix, like "==" or "~".
+
+ std::string::const_iterator IdStart = I;
+
+ // Parse the id. We accept [a-zA-Z0-9] currently.
+ while (I != E && isalnum(*I)) ++I;
+
+ if (IdStart == I) { // Requires more than just a prefix
+ Result.clear();
+ break;
+ }
- switch (ConstraintType) {
+ // Remember this constraint.
+ Result.push_back(std::make_pair(ConstraintType, std::string(IdStart, I)));
+
+ // If we reached the end of the ID, we must have the end of the string or a
+ // comma, which we skip now.
+ if (I != E) {
+ if (*I != ',') { Result.clear(); break; }
+ ++I;
+ if (I == E) { Result.clear(); break; } // don't allow "xyz,"
+ }
+ }
+
+ return Result;
+}
+
+
+/// Verify - Verify that the specified constraint string is reasonable for the
+/// specified function type, and otherwise validate the constraint string.
+bool InlineAsm::Verify(const FunctionType *Ty, const std::string &ConstStr) {
+ if (Ty->isVarArg()) return false;
+
+ std::vector<std::pair<ConstraintPrefix, std::string> >
+ Constraints = ParseConstraints(ConstStr);
+
+ // Error parsing constraints.
+ if (Constraints.empty() && !ConstStr.empty()) return false;
+
+ unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
+
+ for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
+ switch (Constraints[i].first) {
case isOutput:
if (NumInputs || NumClobbers) return false; // outputs come first.
++NumOutputs;
@@ -87,20 +119,9 @@ bool InlineAsm::Verify(const FunctionType *Ty, const std::string &Constraints) {
++NumClobbers;
break;
}
-
- // Parse the id. We accept [a-zA-Z0-9] currently.
- while (I != E && isalnum(*I)) ++I;
-
- // If we reached the end of the ID, we must have the end of the string or a
- // comma, which we skip now.
- if (I != E) {
- if (*I != ',') return false;
- ++I;
- if (I == E) return false; // don't allow "xyz,"
- }
}
-
- if (NumOutputs > 1) return false; // Only one result allowed.
+
+ if (NumOutputs > 1) return false; // Only one result allowed so far.
if ((Ty->getReturnType() != Type::VoidTy) != NumOutputs)
return false; // NumOutputs = 1 iff has a result type.