diff options
author | Chad Rosier <mcrosier@apple.com> | 2012-09-06 19:35:00 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2012-09-06 19:35:00 +0000 |
commit | acc22b6b5a8ba501f896fb0d00afdff5c5a3f090 (patch) | |
tree | f7191fea8646a7fe07f93be65ebb5f4a2c461416 /lib | |
parent | 3359fa306836ffb64401aad4b561e7647b20d6ef (diff) |
[ms-inline asm] The IR representation of inline assembly enumerates the input
and output expressions much like that in GNU-style inline assembly. Output
expressions are first. Do this for MS-style inline asms.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163342 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaStmtAsm.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index e19ee96436..c6432ddc66 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -474,6 +474,8 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SmallVector<IdentifierInfo*, 4> Outputs; SmallVector<Expr*, 4> InputExprs; SmallVector<Expr*, 4> OutputExprs; + SmallVector<std::string, 4> InputExprNames; + SmallVector<std::string, 4> OutputExprNames; // Empty asm statements don't need to instantiate the AsmParser, etc. if (AsmToks.empty()) { @@ -628,10 +630,12 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, if (isDef || isMemDef) { Outputs.push_back(II); OutputExprs.push_back(Result.take()); + OutputExprNames.push_back(Name.str()); OutputConstraints.push_back("=r"); } else { Inputs.push_back(II); InputExprs.push_back(Result.take()); + InputExprNames.push_back(Name.str()); InputConstraints.push_back("r"); } } @@ -654,6 +658,27 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, E = InputConstraints.end(); I != E; ++I) Constraints.push_back(*I); + // Enumerate the AsmString expressions. + // FIXME: This isn't going to work if: + // 1. The symbol name and an opcode/reg share the same, or are a substring of + // the, name. + // 2. The symbol name appears more then once in the asm string. + unsigned OpNum = 0; + for (unsigned i = 0, e = OutputExprNames.size(); i != e; ++i, ++OpNum) { + size_t found = AsmString.find(OutputExprNames[i]); + SmallString<32> Res; + llvm::raw_svector_ostream OS(Res); + OS << '$' << OpNum; + AsmString.replace(found, OutputExprNames[i].size(), OS.str()); + } + for (unsigned i = 0, e = InputExprNames.size(); i != e; ++i, ++OpNum) { + size_t found = AsmString.find(InputExprNames[i]); + SmallString<32> Res; + llvm::raw_svector_ostream OS(Res); + OS << '$' << OpNum; + AsmString.replace(found, InputExprNames[i].size(), OS.str()); + } + MSAsmStmt *NS = new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple, /*IsVolatile*/ true, AsmToks, Inputs, Outputs, |