Change loops to derive the number of tables automatically
[oota-llvm.git] / utils / TableGen / StringMatcher.cpp
index 1c43b6d1c8aadaabcc733a0a3584267231696657..6aedcbf458a86b3fcb6b3828cc4d015047aafa88 100644 (file)
@@ -51,9 +51,18 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
   if (CharNo == Matches[0]->first.size()) {
     assert(Matches.size() == 1 && "Had duplicate keys to match on");
     
-    // FIXME: If Matches[0].first has embeded \n, this will be bad.
-    OS << Indent << Matches[0]->second << "\t // \"" << Matches[0]->first
-    << "\"\n";
+    // If the to-execute code has \n's in it, indent each subsequent line.
+    StringRef Code = Matches[0]->second;
+    
+    std::pair<StringRef, StringRef> Split = Code.split('\n');
+    OS << Indent << Split.first << "\t // \"" << Matches[0]->first << "\"\n";
+
+    Code = Split.second;
+    while (!Code.empty()) {
+      Split = Code.split('\n');
+      OS << Indent << Split.first << "\n";
+      Code = Split.second;
+    }
     return false;
   }