[cfe-commits] r161893 - /cfe/trunk/lib/Sema/SemaStmt.cpp

Chad Rosier mcrosier at apple.com
Tue Aug 14 13:58:21 PDT 2012


Author: mcrosier
Date: Tue Aug 14 15:58:21 2012
New Revision: 161893

URL: http://llvm.org/viewvc/llvm-project?rev=161893&view=rev
Log:
[ms-inline asm] Simplify the logic in patchMSAsmString.  We no longer need to
track the LineEnds now that single line asm statments aren't merged.

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

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=161893&r1=161892&r2=161893&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Aug 14 15:58:21 2012
@@ -2797,7 +2797,6 @@
 static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
                               SourceLocation AsmLoc,
                               ArrayRef<Token> AsmToks,
-                              ArrayRef<unsigned> LineEnds,
                               const TargetInfo &TI,
                               std::vector<std::string> &AsmStrings) {
   assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
@@ -2805,57 +2804,60 @@
   // Assume simple asm stmt until we parse a non-register identifer.
   IsSimple = true;
 
-  for (unsigned i = 0, e = LineEnds.size(); i != e; ++i) {
-    SmallString<512> Asm;
+  SmallString<512> Asm;
+  unsigned NumAsmStrings = 0;
+  for (unsigned i = 0, e = AsmToks.size(); i != e; ++i) {
 
-    // Check the operands.
-    for (unsigned j = (i == 0) ? 0 : LineEnds[i-1], e = LineEnds[i]; j != e; ++j) {
+    // Emit the previous asm string.
+    if (i != 0 && AsmToks[i].isAtStartOfLine())
+      AsmStrings[NumAsmStrings++] = Asm.c_str();
+
+    // Start a new asm string with the opcode.
+    if (i == 0 || AsmToks[i].isAtStartOfLine()) {
+      Asm = AsmToks[i].getIdentifierInfo()->getName().str();
+      continue;
+    }
 
-      IdentifierInfo *II;
-      if (j == 0 || (i > 0 && j == LineEnds[i-1])) {
-        II = AsmToks[j].getIdentifierInfo();
-        Asm = II->getName().str();
-        continue;
-      }
+    if (needSpaceAsmToken(AsmToks[i]))
+      Asm += " ";
 
-      if (needSpaceAsmToken(AsmToks[j]))
-        Asm += " ";
+    // Check the operand(s).
+    switch (AsmToks[i].getKind()) {
+    default:
+      //llvm_unreachable("Unknown token.");
+      break;
+    case tok::comma: Asm += ","; break;
+    case tok::colon: Asm += ":"; break;
+    case tok::l_square: Asm += "["; break;
+    case tok::r_square: Asm += "]"; break;
+    case tok::l_brace: Asm += "{"; break;
+    case tok::r_brace: Asm += "}"; break;
+    case tok::numeric_constant: {
+      SmallString<32> TokenBuf;
+      TokenBuf.resize(32);
+      bool StringInvalid = false;
+      Asm += SemaRef.PP.getSpelling(AsmToks[i], TokenBuf, &StringInvalid);
+      assert (!StringInvalid && "Expected valid string!");
+      break;
+    }
+    case tok::identifier: {
+      StringRef Name = AsmToks[i].getIdentifierInfo()->getName();
 
-      switch (AsmToks[j].getKind()) {
-      default:
-        //llvm_unreachable("Unknown token.");
-        break;
-      case tok::comma: Asm += ","; break;
-      case tok::colon: Asm += ":"; break;
-      case tok::l_square: Asm += "["; break;
-      case tok::r_square: Asm += "]"; break;
-      case tok::l_brace: Asm += "{"; break;
-      case tok::r_brace: Asm += "}"; break;
-      case tok::numeric_constant: {
-        SmallString<32> TokenBuf;
-        TokenBuf.resize(32);
-        bool StringInvalid = false;
-        Asm += SemaRef.PP.getSpelling(AsmToks[j], TokenBuf, &StringInvalid);
-        assert (!StringInvalid && "Expected valid string!");
+      // Valid registers don't need modification.
+      if (TI.isValidGCCRegisterName(Name)) {
+        Asm += Name;
         break;
       }
-      case tok::identifier: {
-        II = AsmToks[j].getIdentifierInfo();
-        StringRef Name = II->getName();
-
-        // Valid registers don't need modification.
-        if (TI.isValidGCCRegisterName(Name)) {
-          Asm += Name;
-          break;
-        }
 
-        // TODO: Lookup the identifier.
-        IsSimple = false;
-      }
-      } // AsmToks[i].getKind()
+      // TODO: Lookup the identifier.
+      IsSimple = false;
+      break;
     }
-    AsmStrings[i] = Asm.c_str();
+    } // AsmToks[i].getKind()
   }
+
+  // Emit the final (and possibly only) asm string.
+  AsmStrings[NumAsmStrings] = Asm.c_str();
 }
 
 // Build the unmodified MSAsmString.
@@ -2907,11 +2909,18 @@
 
   bool IsSimple;
   std::vector<std::string> PatchedAsmStrings;
-  PatchedAsmStrings.resize(LineEnds.size());
+
+  // FIXME: Count this while parsing.
+  unsigned NumAsmStrings = 0;
+  for (unsigned i = 0, e = AsmToks.size(); i != e; ++i)
+    if (AsmToks[i].isAtStartOfLine())
+      ++NumAsmStrings;
+
+  PatchedAsmStrings.resize(NumAsmStrings ? NumAsmStrings : 1);
 
   // Rewrite operands to appease the AsmParser.
-  patchMSAsmStrings(*this, IsSimple, AsmLoc, AsmToks, LineEnds, 
-                   Context.getTargetInfo(), PatchedAsmStrings);
+  patchMSAsmStrings(*this, IsSimple, AsmLoc, AsmToks, Context.getTargetInfo(),
+                    PatchedAsmStrings);
 
   // patchMSAsmStrings doesn't correctly patch non-simple asm statements.
   if (!IsSimple) {





More information about the cfe-commits mailing list