Changes in directory llvm/lib/VMCore:
InlineAsm.cpp updated: 1.3 -> 1.4 --- Log message: parse and verify the constraint string. --- Diffs of the changes: (+68 -0) InlineAsm.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+) Index: llvm/lib/VMCore/InlineAsm.cpp diff -u llvm/lib/VMCore/InlineAsm.cpp:1.3 llvm/lib/VMCore/InlineAsm.cpp:1.4 --- llvm/lib/VMCore/InlineAsm.cpp:1.3 Wed Jan 25 16:26:05 2006 +++ llvm/lib/VMCore/InlineAsm.cpp Wed Jan 25 18:48:33 2006 @@ -13,6 +13,7 @@ #include "llvm/InlineAsm.h" #include "llvm/DerivedTypes.h" +#include <cctype> using namespace llvm; // NOTE: when memoizing the function type, we have to be careful to handle the @@ -37,6 +38,73 @@ 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; + + // Scan the constraints string. + for (std::string::const_iterator I = Constraints.begin(), + E = Constraints.end(); I != E; ) { + if (*I == ',') return false; // Empty constraint like ",," + + // Parse the prefix. + enum { + isInput, // 'x' + isOutput, // '=x' + isIndirectOutput, // '==x' + isClobber, // '~x' + } ConstraintType = isInput; + + if (*I == '~') { + ConstraintType = isClobber; + ++I; + } else if (*I == '=') { + ++I; + if (I != E && *I == '=') { + ConstraintType = isIndirectOutput; + ++I; + } else { + ConstraintType = isOutput; + } + } + + if (I == E) return false; // Just a prefix, like "==" or "~". + + switch (ConstraintType) { + case isOutput: + if (NumInputs || NumClobbers) return false; // outputs come first. + ++NumOutputs; + break; + case isInput: + case isIndirectOutput: + if (NumClobbers) return false; // inputs before clobbers. + ++NumInputs; + break; + case isClobber: + ++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 ((Ty->getReturnType() != Type::VoidTy) != NumOutputs) + return false; // NumOutputs = 1 iff has a result type. + + if (Ty->getNumParams() != NumInputs) return false; return true; } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits