[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
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp
index b962d9d..94223e4 100644
--- a/lib/Sema/SemaStmtAsm.cpp
+++ b/lib/Sema/SemaStmtAsm.cpp
@@ -459,22 +459,41 @@
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 @@
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 @@
}
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;