diff options
author | Chad Rosier <mcrosier@apple.com> | 2012-08-21 21:56:39 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2012-08-21 21:56:39 +0000 |
commit | 38c71d38e1b2a5f71c086b9c2efa9e8e69fa1bb5 (patch) | |
tree | 2e28bfd6381ee2f5ff968194e7f826146ec62dc4 | |
parent | d9f95b35dc4fc168a167a9b9b61a5f9e1d0462ba (diff) |
[ms-inline asm] Have buildMSAsmString build a vector of unmodified AsmStrings.
Add a new static function, buildMSAsmPieces, that will break these strings down
into mnemonic and operands. Upon a match failure, the idea is to use the
ErrorInfo from MatchInstructionImpl to inspect the mnemonic/operand and
decide a course of action. Unfortunately, there's no easy way to test this at
the moment.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162321 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaStmtAsm.cpp | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index b962d9d4a2..94223e4384 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -459,22 +459,41 @@ static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple, AsmStrings[NumAsmStrings] = Asm.c_str(); } +// Break the AsmSting into pieces. +static void buildMSAsmPieces(StringRef Asm, std::vector<StringRef> &Pieces) { + std::pair<StringRef,StringRef> Split = Asm.split(' '); + + // Mnemonic + Pieces.push_back(Split.first); + Asm = Split.second; + + // Operands + while (!Asm.empty()) { + Split = Asm.split(", "); + Pieces.push_back(Split.first); + Asm = Split.second; + } +} + // Build the unmodified MSAsmString. static std::string buildMSAsmString(Sema &SemaRef, ArrayRef<Token> AsmToks, - unsigned &NumAsmStrings) { + std::vector<std::string> &AsmStrings) { assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!"); - NumAsmStrings = 0; + SmallString<512> Res; SmallString<512> Asm; for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) { bool isNewAsm = i == 0 || AsmToks[i].isAtStartOfLine() || AsmToks[i].is(tok::kw_asm); if (isNewAsm) { - ++NumAsmStrings; - if (i) - Asm += '\n'; + if (i) { + AsmStrings.push_back(Asm.c_str()); + Res += Asm; + Asm.clear(); + Res += '\n'; + } if (AsmToks[i].is(tok::kw_asm)) { i++; // Skip __asm assert (i != e && "Expected another token"); @@ -486,7 +505,9 @@ static std::string buildMSAsmString(Sema &SemaRef, Asm += getSpelling(SemaRef, AsmToks[i]); } - return Asm.c_str(); + AsmStrings.push_back(Asm.c_str()); + Res += Asm; + return Res.c_str(); } StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, @@ -511,7 +532,14 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, } unsigned NumAsmStrings; - std::string AsmString = buildMSAsmString(*this, AsmToks, NumAsmStrings); + std::vector<std::string> AsmStrings; + std::string AsmString = buildMSAsmString(*this, AsmToks, AsmStrings); + NumAsmStrings = AsmStrings.size(); + + std::vector<std::vector<StringRef> > Pieces; + Pieces.resize(NumAsmStrings); + for (unsigned i = 0; i != NumAsmStrings; ++i) + buildMSAsmPieces(AsmStrings[i], Pieces[i]); bool IsSimple; std::vector<llvm::BitVector> Regs; |