diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Stmt.cpp | 25 | ||||
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 29 |
2 files changed, 30 insertions, 24 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 682a9b1ee4..b7feda9b8f 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -154,6 +154,31 @@ std::string AsmStmt::getInputConstraint(unsigned i) const { Constraints[i + NumOutputs]->getByteLength()); } + +/// getNamedOperand - Given a symbolic operand reference like %[foo], +/// translate this into a numeric value needed to reference the same operand. +/// This returns -1 if the operand name is invalid. +int AsmStmt::getNamedOperand(const std::string &SymbolicName) const { + unsigned NumPlusOperands = 0; + + // Check if this is an output operand. + for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { + if (getOutputName(i) == SymbolicName) + return i; + + // Keep track of the number of '+' operands. + if (isOutputPlusConstraint(i)) ++NumPlusOperands; + } + + for (unsigned i = 0, e = getNumInputs(); i != e; ++i) + if (getInputName(i) == SymbolicName) + return getNumOutputs() + NumPlusOperands + i; + + // Not found. + return -1; +} + + //===----------------------------------------------------------------------===// // Constructors //===----------------------------------------------------------------------===// diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index ff1f76f4a3..93c4f5b07d 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -771,34 +771,15 @@ static std::string ConvertAsmString(const AsmStmt& S, bool &Failed) { if (EscapedChar == '[') { const char *NameEnd = (const char*)memchr(StrStart, ']', StrEnd-StrStart); // FIXME: Should be caught by sema. + // FIXME: Does sema catch multiple operands with the same name? assert(NameEnd != 0 && "Could not parse symbolic name"); - std::string SymbolicName(StrStart, NameEnd); - StrStart = NameEnd+1; - int Index = -1; - - // Check if this is an output operand. - for (unsigned i = 0; i != S.getNumOutputs(); ++i) { - if (S.getOutputName(i) == SymbolicName) { - Index = i; - break; - } - } - - if (Index == -1) { - for (unsigned i = 0; i != S.getNumInputs(); ++i) { - if (S.getInputName(i) == SymbolicName) { - Index = S.getNumOutputs() + i; - break; - } - } - } - - assert(Index != -1 && "Did not find right operand!"); - - Result += '$' + llvm::utostr(Index); + int OperandIndex = S.getNamedOperand(SymbolicName); + assert(OperandIndex != -1 && "FIXME: Catch in Sema."); + + Result += '$' + llvm::utostr(unsigned(OperandIndex)); continue; } |