[ms-inline asm] Compute the token range for each instruction within the asm.
Eventually, we'll need a way of mapping tokens (and their IdentifierInfo*) to
the operands computed by buildMSAsmPieces().


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162388 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp
index 732688d..f5852ae 100644
--- a/lib/Sema/SemaStmtAsm.cpp
+++ b/lib/Sema/SemaStmtAsm.cpp
@@ -388,13 +388,14 @@
 }
 
 // Build the unmodified MSAsmString.
-static std::string buildMSAsmString(Sema &SemaRef,
-                                    ArrayRef<Token> AsmToks,
-                                    std::vector<std::string> &AsmStrings) {
+static std::string buildMSAsmString(Sema &SemaRef, ArrayRef<Token> AsmToks,
+                                    std::vector<std::string> &AsmStrings,
+                     std::vector<std::pair<unsigned,unsigned> > &AsmTokRanges) {
   assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
 
   SmallString<512> Res;
   SmallString<512> Asm;
+  unsigned startTok = 0;
   for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
     bool isNewAsm = i == 0 || AsmToks[i].isAtStartOfLine() ||
       AsmToks[i].is(tok::kw_asm);
@@ -402,6 +403,8 @@
     if (isNewAsm) {
       if (i) {
         AsmStrings.push_back(Asm.c_str());
+        AsmTokRanges.push_back(std::make_pair(startTok, i-1));
+        startTok = i;
         Res += Asm;
         Asm.clear();
         Res += '\n';
@@ -418,6 +421,7 @@
     Asm += getSpelling(SemaRef, AsmToks[i]);
   }
   AsmStrings.push_back(Asm.c_str());
+  AsmTokRanges.push_back(std::make_pair(startTok, AsmToks.size()-1));
   Res += Asm;
   return Res.c_str();
 }
@@ -448,7 +452,8 @@
 
   unsigned NumAsmStrings;
   std::vector<std::string> AsmStrings;
-  std::string AsmString = buildMSAsmString(*this, AsmToks, AsmStrings);
+  std::vector<std::pair<unsigned,unsigned> > AsmTokRanges;
+  std::string AsmString = buildMSAsmString(*this, AsmToks, AsmStrings, AsmTokRanges);
   NumAsmStrings = AsmStrings.size();
 
   std::vector<std::vector<StringRef> > Pieces;