diff options
author | Chad Rosier <mcrosier@apple.com> | 2012-10-02 21:49:14 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2012-10-02 21:49:14 +0000 |
commit | 09d7710e0492a4005ea56d9c4b067777c481d55d (patch) | |
tree | b611e0cce8ac77441124e63dba2ce321ba007c2a /clang/lib/Sema/SemaStmtAsm.cpp | |
parent | 25f5cbcd13acc06c3b7d1cd9904b95b70cb4a641 (diff) | |
download | bcm5719-llvm-09d7710e0492a4005ea56d9c4b067777c481d55d.tar.gz bcm5719-llvm-09d7710e0492a4005ea56d9c4b067777c481d55d.zip |
[ms-inline asm] Rewrite the symbol references as wildcard MCParsedAsmOperands.
A Sema lookup is used to determine the size of the variable, which is in turn
used during wildcard matching.
llvm-svn: 165058
Diffstat (limited to 'clang/lib/Sema/SemaStmtAsm.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmtAsm.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index 3c3a9eb0b5c..de485b9f95b 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -575,6 +575,43 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, // If we had an error parsing the operands, fail gracefully. if (HadError) { DEF_SIMPLE_MSASM(EmptyAsmStr); return Owned(NS); } + // Rewrite the symbol references as wildcard MCParsedAsmOperands. + for (unsigned i = 1, e = Operands.size(); i != e; ++i) + if (Operands[i]->isMem()) { + StringRef Name = getMSInlineAsmExprName(Pieces[StrIdx][i]); + + // The expr may be a register. E.g., DWORD PTR [eax] + if (Context.getTargetInfo().isValidGCCRegisterName(Name)) + continue; + + IdentifierInfo *II = getIdentifierInfo(Name, AsmToks, + AsmTokRanges[StrIdx].first, + AsmTokRanges[StrIdx].second); + // Lookup the identifier. + // TODO: Someone with more experience with clang should verify this the + // proper way of doing a symbol lookup. + DeclarationName DeclName(II); + Scope *CurScope = getCurScope(); + LookupResult R(*this, DeclName, AsmLoc, Sema::LookupOrdinaryName); + if (!this->LookupName(R, CurScope, false/*AllowBuiltinCreation*/)) + assert(0 && "Sema::LookupName failed!"); + assert (R.isSingleResult() && "Expected a single result?!"); + NamedDecl *Decl = R.getFoundDecl(); + switch (Decl->getKind()) { + default: + assert(0 && "Unknown decl kind."); + break; + case Decl::Var: { + case Decl::ParmVar: + VarDecl *Var = cast<VarDecl>(Decl); + QualType Ty = Var->getType(); + // Set the expected operand size. + Operands[i]->setMSAsmWildcard(Context.getTypeInfo(Ty).first); + break; + } + } + } + // Match the MCInstr. unsigned Kind; unsigned Opcode; @@ -619,8 +656,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, // Expr/Input or Output. StringRef Name = getMSInlineAsmExprName(Pieces[StrIdx][i]); - // The expr may be a register. - // E.g., DWORD PTR [eax] + // The expr may be a register. E.g., DWORD PTR [eax] if (Context.getTargetInfo().isValidGCCRegisterName(Name)) continue; |