[llvm] r264884 - Restore "[ThinLTO] Serialize the Module SourceFileName to/from LLVM assembly"
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 6 11:23:09 PDT 2016
Teresa,
David noticed on IRC that this is not documented in the LangRef. Can you add it?
Thanks,
Mehdi
> On Mar 30, 2016, at 11:15 AM, Teresa Johnson via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: tejohnson
> Date: Wed Mar 30 13:15:08 2016
> New Revision: 264884
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264884&view=rev
> Log:
> Restore "[ThinLTO] Serialize the Module SourceFileName to/from LLVM assembly"
>
> This restores commit 264869, with a fix for windows bots to properly
> escape '\' in the path when serializing out. Added test.
>
> Added:
> llvm/trunk/test/Assembler/source-filename-backslash.ll
> llvm/trunk/test/Assembler/source-filename.ll
> Modified:
> llvm/trunk/lib/AsmParser/LLLexer.cpp
> llvm/trunk/lib/AsmParser/LLParser.cpp
> llvm/trunk/lib/AsmParser/LLParser.h
> llvm/trunk/lib/AsmParser/LLToken.h
> llvm/trunk/lib/IR/AsmWriter.cpp
>
> Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=264884&r1=264883&r2=264884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLLexer.cpp Wed Mar 30 13:15:08 2016
> @@ -533,6 +533,7 @@ lltok::Kind LLLexer::LexIdentifier() {
> KEYWORD(notail);
> KEYWORD(target);
> KEYWORD(triple);
> + KEYWORD(source_filename);
> KEYWORD(unwind);
> KEYWORD(deplibs); // FIXME: Remove in 4.0.
> KEYWORD(datalayout);
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=264884&r1=264883&r2=264884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Mar 30 13:15:08 2016
> @@ -239,6 +239,10 @@ bool LLParser::ParseTopLevelEntities() {
> case lltok::kw_define: if (ParseDefine()) return true; break;
> case lltok::kw_module: if (ParseModuleAsm()) return true; break;
> case lltok::kw_target: if (ParseTargetDefinition()) return true; break;
> + case lltok::kw_source_filename:
> + if (ParseSourceFileName())
> + return true;
> + break;
> case lltok::kw_deplibs: if (ParseDepLibs()) return true; break;
> case lltok::LocalVarID: if (ParseUnnamedType()) return true; break;
> case lltok::LocalVar: if (ParseNamedType()) return true; break;
> @@ -336,6 +340,19 @@ bool LLParser::ParseTargetDefinition() {
> }
>
> /// toplevelentity
> +/// ::= 'source_filename' '=' STRINGCONSTANT
> +bool LLParser::ParseSourceFileName() {
> + assert(Lex.getKind() == lltok::kw_source_filename);
> + std::string Str;
> + Lex.Lex();
> + if (ParseToken(lltok::equal, "expected '=' after source_filename") ||
> + ParseStringConstant(Str))
> + return true;
> + M->setSourceFileName(Str);
> + return false;
> +}
> +
> +/// toplevelentity
> /// ::= 'deplibs' '=' '[' ']'
> /// ::= 'deplibs' '=' '[' STRINGCONSTANT (',' STRINGCONSTANT)* ']'
> /// FIXME: Remove in 4.0. Currently parse, but ignore.
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=264884&r1=264883&r2=264884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.h (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.h Wed Mar 30 13:15:08 2016
> @@ -261,6 +261,7 @@ namespace llvm {
> bool ValidateEndOfModule();
> bool ParseTargetDefinition();
> bool ParseModuleAsm();
> + bool ParseSourceFileName();
> bool ParseDepLibs(); // FIXME: Remove in 4.0.
> bool ParseUnnamedType();
> bool ParseNamedType();
>
> Modified: llvm/trunk/lib/AsmParser/LLToken.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=264884&r1=264883&r2=264884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLToken.h (original)
> +++ llvm/trunk/lib/AsmParser/LLToken.h Wed Mar 30 13:15:08 2016
> @@ -59,6 +59,7 @@ namespace lltok {
> kw_notail,
> kw_target,
> kw_triple,
> + kw_source_filename,
> kw_unwind,
> kw_deplibs, // FIXME: Remove in 4.0
> kw_datalayout,
>
> Modified: llvm/trunk/lib/IR/AsmWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=264884&r1=264883&r2=264884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/IR/AsmWriter.cpp Wed Mar 30 13:15:08 2016
> @@ -2203,6 +2203,22 @@ void AssemblyWriter::writeOperandBundles
> Out << " ]";
> }
>
> +/// Escape any backslashes in the source file (e.g. Windows paths)
> +/// before emitting, so that it is parsed properly by the lexer on input.
> +static void EscapeBackslashes(std::string Str,
> + SmallVectorImpl<char> &Res) {
> + for (auto C : Str) {
> + switch (C) {
> + default:
> + break;
> + case '\\':
> + Res.push_back('\\');
> + break;
> + }
> + Res.push_back(C);
> + }
> +}
> +
> void AssemblyWriter::printModule(const Module *M) {
> Machine.initialize();
>
> @@ -2215,6 +2231,12 @@ void AssemblyWriter::printModule(const M
> M->getModuleIdentifier().find('\n') == std::string::npos)
> Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
>
> + if (!M->getSourceFileName().empty()) {
> + SmallString<128> EscapedName;
> + EscapeBackslashes(M->getSourceFileName(), EscapedName);
> + Out << "source_filename = \"" << EscapedName << "\"\n";
> + }
> +
> const std::string &DL = M->getDataLayoutStr();
> if (!DL.empty())
> Out << "target datalayout = \"" << DL << "\"\n";
>
> Added: llvm/trunk/test/Assembler/source-filename-backslash.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/source-filename-backslash.ll?rev=264884&view=auto
> ==============================================================================
> --- llvm/trunk/test/Assembler/source-filename-backslash.ll (added)
> +++ llvm/trunk/test/Assembler/source-filename-backslash.ll Wed Mar 30 13:15:08 2016
> @@ -0,0 +1,8 @@
> +
> +; Make sure that llvm-as/llvm-dis properly assemble/disassemble the
> +; source_filename.
> +
> +; RUN: llvm-as < %s | llvm-dis | FileCheck %s
> +
> +; CHECK: source_filename = "C:\\path\\with\\backslashes\\test.cc"
> +source_filename = "C:\\path\\with\\backslashes\\test.cc"
>
> Added: llvm/trunk/test/Assembler/source-filename.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/source-filename.ll?rev=264884&view=auto
> ==============================================================================
> --- llvm/trunk/test/Assembler/source-filename.ll (added)
> +++ llvm/trunk/test/Assembler/source-filename.ll Wed Mar 30 13:15:08 2016
> @@ -0,0 +1,8 @@
> +
> +; Make sure that llvm-as/llvm-dis properly assemble/disassemble the
> +; source_filename.
> +
> +; RUN: llvm-as < %s | llvm-dis | FileCheck %s
> +
> +; CHECK: source_filename = "test.cc"
> +source_filename = "test.cc"
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list