From: Chad Rosier Date: Tue, 16 Oct 2012 21:55:39 +0000 (+0000) Subject: [ms-inline asm] Move some logic around to simplify the interface between the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e54cba1ec0b0e498ee67d200289035797932e714;p=clang [ms-inline asm] Move some logic around to simplify the interface between the front-end and the AsmParser. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166063 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 673b272181..a9bbb48f03 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -1660,9 +1660,9 @@ class MSAsmStmt : public AsmStmt { public: MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, ArrayRef asmtoks, - ArrayRef inputs, ArrayRef outputs, - ArrayRef inputexprs, ArrayRef outputexprs, - StringRef asmstr, ArrayRef constraints, + unsigned numoutputs, unsigned numinputs, + ArrayRef names, ArrayRef constraints, + ArrayRef exprs, StringRef asmstr, ArrayRef clobbers, SourceLocation endloc); /// \brief Build an empty MS-style inline-assembly statement. diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index db13f67e90..eafcf92eee 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -673,30 +673,24 @@ GCCAsmStmt::GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, - ArrayRef asmtoks, ArrayRef inputs, - ArrayRef outputs, - ArrayRef inputexprs, ArrayRef outputexprs, - StringRef asmstr, ArrayRef constraints, - ArrayRef clobbers, SourceLocation endloc) - : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, outputs.size(), - inputs.size(), clobbers.size()), LBraceLoc(lbraceloc), + ArrayRef asmtoks, unsigned numoutputs, + unsigned numinputs, ArrayRef names, + ArrayRef constraints, ArrayRef exprs, + StringRef asmstr, ArrayRef clobbers, + SourceLocation endloc) + : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, + numinputs, clobbers.size()), LBraceLoc(lbraceloc), EndLoc(endloc), AsmStr(asmstr.str()), NumAsmToks(asmtoks.size()) { - assert (inputs.size() == inputexprs.size() && "Input expr size mismatch!"); - assert (outputs.size() == outputexprs.size() && "Input expr size mismatch!"); unsigned NumExprs = NumOutputs + NumInputs; Names = new (C) IdentifierInfo*[NumExprs]; - for (unsigned i = 0, e = NumOutputs; i != e; ++i) - Names[i] = outputs[i]; - for (unsigned i = NumOutputs, j = 0, e = NumExprs; i != e; ++i, ++j) - Names[i] = inputs[j]; + for (unsigned i = 0, e = NumExprs; i != e; ++i) + Names[i] = names[i]; Exprs = new (C) Stmt*[NumExprs]; - for (unsigned i = 0, e = NumOutputs; i != e; ++i) - Exprs[i] = outputexprs[i]; - for (unsigned i = NumOutputs, j = 0, e = NumExprs; i != e; ++i, ++j) - Exprs[i] = inputexprs[j]; + for (unsigned i = 0, e = NumExprs; i != e; ++i) + Exprs[i] = exprs[i]; AsmToks = new (C) Token[NumAsmToks]; for (unsigned i = 0, e = NumAsmToks; i != e; ++i) diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index 339ff7a953..18a8f7344c 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -390,12 +390,15 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef AsmToks,SourceLocation EndLoc) { SmallVector Inputs; SmallVector Outputs; - SmallVector InputExprs; - SmallVector OutputExprs; - SmallVector Constraints; + SmallVector Names; SmallVector InputConstraints; SmallVector OutputConstraints; - + SmallVector Constraints; + unsigned NumOutputs; + unsigned NumInputs; + SmallVector InputExprs; + SmallVector OutputExprs; + SmallVector Exprs; SmallVector Clobbers; std::set ClobberRegs; @@ -406,8 +409,8 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, StringRef EmptyAsmStr; MSAsmStmt *NS = new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true, - /*IsVolatile*/ true, AsmToks, Inputs, Outputs, - InputExprs, OutputExprs, EmptyAsmStr, Constraints, + /*IsVolatile*/ true, AsmToks, /*NumOutputs*/ 0, + /*NumInputs*/ 0, Names, Constraints, Exprs, EmptyAsmStr, Clobbers, EndLoc); return Owned(NS); } @@ -534,19 +537,30 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, Parser->freeParsedOperands(); } } + + // Set the number of Outputs and Inputs. + NumOutputs = Outputs.size(); + NumInputs = Inputs.size(); + + // Set the unique clobbers. for (std::set::iterator I = ClobberRegs.begin(), E = ClobberRegs.end(); I != E; ++I) Clobbers.push_back(*I); - // Merge the output and input constraints. Output constraints are expected - // first. - for (SmallVectorImpl::iterator I = OutputConstraints.begin(), - E = OutputConstraints.end(); I != E; ++I) - Constraints.push_back(*I); - - for (SmallVectorImpl::iterator I = InputConstraints.begin(), - E = InputConstraints.end(); I != E; ++I) - Constraints.push_back(*I); + // Merge the various outputs and inputs. Output are expected first. + Names.resize(NumOutputs + NumInputs); + Constraints.resize(NumOutputs + NumInputs); + Exprs.resize(NumOutputs + NumInputs); + for (unsigned i = 0; i < NumOutputs; ++i) { + Names[i] = Outputs[i]; + Constraints[i] = OutputConstraints[i]; + Exprs[i] = OutputExprs[i]; + } + for (unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) { + Names[j] = Inputs[i]; + Constraints[j] = InputConstraints[i]; + Exprs[j] = InputExprs[i]; + } // Build the IR assembly string. std::string AsmStringIR; @@ -584,9 +598,9 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, AsmString = OS.str(); MSAsmStmt *NS = - new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ false, - /*IsVolatile*/ true, AsmToks, Inputs, Outputs, - InputExprs, OutputExprs, AsmString, Constraints, + new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true, + /*IsVolatile*/ true, AsmToks, NumOutputs, + NumInputs, Names, Constraints, Exprs, AsmString, Clobbers, EndLoc); return Owned(NS); }