[llvm] r239251 - [AsmWriter] Rewrite module asm printing using StringRef::split.

David Blaikie dblaikie at gmail.com
Mon Jun 8 10:37:08 PDT 2015


On Sun, Jun 7, 2015 at 6:59 AM, Benjamin Kramer <benny.kra at googlemail.com>
wrote:

> Author: d0k
> Date: Sun Jun  7 08:59:33 2015
> New Revision: 239251
>
> URL: http://llvm.org/viewvc/llvm-project?rev=239251&view=rev
> Log:
> [AsmWriter] Rewrite module asm printing using StringRef::split.
>
> No change in output intended.
>
> Modified:
>     llvm/trunk/lib/IR/AsmWriter.cpp
>
> Modified: llvm/trunk/lib/IR/AsmWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=239251&r1=239250&r2=239251&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/IR/AsmWriter.cpp Sun Jun  7 08:59:33 2015
> @@ -2140,27 +2140,20 @@ void AssemblyWriter::printModule(const 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());
>

Prefer copy init over direct init (since direct init can invoke explicit
conversions that might be more interesting/powerful - though I don't think
there are any for StringRef?)?


> +    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);
> -      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);
> +      PrintEscapedString(Front, Out);
>        Out << "\"\n";
> -    }
> +    } while (!Asm.empty());
>    }
>
>    printTypeIdentities();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150608/bfd7e1bd/attachment.html>


More information about the llvm-commits mailing list