[AsmWriter] Rewrite module asm printing using StringRef::split.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 7 Jun 2015 13:59:33 +0000 (13:59 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 7 Jun 2015 13:59:33 +0000 (13:59 +0000)
No change in output intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/AsmWriter.cpp

index 715aad8b03afd82a2e76d1da13c2e522293cb534..b147f9d79d67e34900762ed660e586e7048725e6 100644 (file)
@@ -2140,27 +2140,20 @@ void AssemblyWriter::printModule(const Module *M) {
     Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
 
   if (!M->getModuleInlineAsm().empty()) {
-    // Split the string into lines, to make it easier to read the .ll file.
-    std::string Asm = M->getModuleInlineAsm();
-    size_t CurPos = 0;
-    size_t NewLine = Asm.find_first_of('\n', CurPos);
     Out << '\n';
-    while (NewLine != std::string::npos) {
+
+    // Split the string into lines, to make it easier to read the .ll file.
+    StringRef Asm(M->getModuleInlineAsm());
+    do {
+      StringRef Front;
+      std::tie(Front, Asm) = Asm.split('\n');
+
       // We found a newline, print the portion of the asm string from the
       // last newline up to this newline.
       Out << "module asm \"";
-      PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.begin()+NewLine),
-                         Out);
+      PrintEscapedString(Front, Out);
       Out << "\"\n";
-      CurPos = NewLine+1;
-      NewLine = Asm.find_first_of('\n', CurPos);
-    }
-    std::string rest(Asm.begin()+CurPos, Asm.end());
-    if (!rest.empty()) {
-      Out << "module asm \"";
-      PrintEscapedString(rest, Out);
-      Out << "\"\n";
-    }
+    } while (!Asm.empty());
   }
 
   printTypeIdentities();