[cfe-commits] r162321 - /cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Chad Rosier mcrosier at apple.com
Tue Aug 21 14:56:39 PDT 2012


Author: mcrosier
Date: Tue Aug 21 16:56:39 2012
New Revision: 162321

URL: http://llvm.org/viewvc/llvm-project?rev=162321&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=162321&r1=162320&r2=162321&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Tue Aug 21 16:56:39 2012
@@ -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;





More information about the cfe-commits mailing list