From: Chad Rosier Date: Tue, 2 Oct 2012 18:51:05 +0000 (+0000) Subject: [ms-inline asm] Enhance the isSimpleMSAsm() function to handle operands with pointer... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04d566429532968a0466293517bad8d0a2ede59f;p=platform%2Fupstream%2Fllvm.git [ms-inline asm] Enhance the isSimpleMSAsm() function to handle operands with pointer size directives (e.g., dword ptr [eax]). llvm-svn: 165031 --- diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index 81ae7e7..3c3a9eb 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -331,6 +331,28 @@ static bool isMSAsmKeyword(StringRef Name) { return Ret; } +// Check to see if the expression is a substring of the asm operand. +static StringRef getMSInlineAsmExprName(StringRef Name) { + // Strip off the size directives. + // E.g., DWORD PTR [V] -> V + if (Name.startswith("BYTE") || Name.startswith("byte") || + Name.startswith("WORD") || Name.startswith("word") || + Name.startswith("DWORD") || Name.startswith("dword") || + Name.startswith("QWORD") || Name.startswith("qword") || + Name.startswith("XWORD") || Name.startswith("xword") || + Name.startswith("XMMWORD") || Name.startswith("xmmword") || + Name.startswith("YMMWORD") || Name.startswith("ymmword")) { + std::pair< StringRef, StringRef > SplitName = Name.split(' '); + assert((SplitName.second.startswith("PTR") || + SplitName.second.startswith("ptr")) && + "Expected PTR/ptr!"); + SplitName = SplitName.second.split('['); + SplitName = SplitName.second.split(']'); + return SplitName.first; + } + return Name; +} + // getIdentifierInfo - Given a Name and a range of tokens, find the associated // IdentifierInfo*. static IdentifierInfo *getIdentifierInfo(StringRef Name, @@ -377,9 +399,11 @@ static bool isSimpleMSAsm(std::vector &Pieces, if (isMSAsmKeyword(Pieces[0])) return false; - for (unsigned i = 1, e = Pieces.size(); i != e; ++i) - if (!TI.isValidGCCRegisterName(Pieces[i])) + for (unsigned i = 1, e = Pieces.size(); i != e; ++i) { + StringRef Op = getMSInlineAsmExprName(Pieces[i]); + if (!TI.isValidGCCRegisterName(Op)) return false; + } return true; } @@ -458,28 +482,6 @@ static bool buildMSAsmStrings(Sema &SemaRef, return false; } -// Check to see if the expression is a substring of the asm operand. -static StringRef getMSInlineAsmExprName(StringRef Name) { - // Strip off the size directives. - // E.g., DWORD PTR [V] -> V - if (Name.startswith("BYTE") || Name.startswith("byte") || - Name.startswith("WORD") || Name.startswith("word") || - Name.startswith("DWORD") || Name.startswith("dword") || - Name.startswith("QWORD") || Name.startswith("qword") || - Name.startswith("XWORD") || Name.startswith("xword") || - Name.startswith("XMMWORD") || Name.startswith("xmmword") || - Name.startswith("YMMWORD") || Name.startswith("ymmword")) { - std::pair< StringRef, StringRef > SplitName = Name.split(' '); - assert((SplitName.second.startswith("PTR") || - SplitName.second.startswith("ptr")) && - "Expected PTR/ptr!"); - SplitName = SplitName.second.split('['); - SplitName = SplitName.second.split(']'); - return SplitName.first; - } - return Name; -} - #define DEF_SIMPLE_MSASM(STR) \ MSAsmStmt *NS = \ new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, /*IsSimple*/ true, \