Index: llvm/trunk/lib/AsmParser/LLLexer.cpp =================================================================== --- llvm/trunk/lib/AsmParser/LLLexer.cpp +++ llvm/trunk/lib/AsmParser/LLLexer.cpp @@ -533,6 +533,7 @@ KEYWORD(notail); KEYWORD(target); KEYWORD(triple); + KEYWORD(source_filename); KEYWORD(unwind); KEYWORD(deplibs); // FIXME: Remove in 4.0. KEYWORD(datalayout); Index: llvm/trunk/lib/AsmParser/LLParser.h =================================================================== --- llvm/trunk/lib/AsmParser/LLParser.h +++ llvm/trunk/lib/AsmParser/LLParser.h @@ -261,6 +261,7 @@ bool ValidateEndOfModule(); bool ParseTargetDefinition(); bool ParseModuleAsm(); + bool ParseSourceFileName(); bool ParseDepLibs(); // FIXME: Remove in 4.0. bool ParseUnnamedType(); bool ParseNamedType(); Index: llvm/trunk/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/trunk/lib/AsmParser/LLParser.cpp +++ llvm/trunk/lib/AsmParser/LLParser.cpp @@ -239,6 +239,10 @@ 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 @@ } /// 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. Index: llvm/trunk/lib/AsmParser/LLToken.h =================================================================== --- llvm/trunk/lib/AsmParser/LLToken.h +++ llvm/trunk/lib/AsmParser/LLToken.h @@ -59,6 +59,7 @@ kw_notail, kw_target, kw_triple, + kw_source_filename, kw_unwind, kw_deplibs, // FIXME: Remove in 4.0 kw_datalayout, Index: llvm/trunk/lib/IR/AsmWriter.cpp =================================================================== --- llvm/trunk/lib/IR/AsmWriter.cpp +++ llvm/trunk/lib/IR/AsmWriter.cpp @@ -2215,6 +2215,9 @@ M->getModuleIdentifier().find('\n') == std::string::npos) Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; + if (!M->getSourceFileName().empty()) + Out << "source_filename = \"" << M->getSourceFileName() << "\"\n"; + const std::string &DL = M->getDataLayoutStr(); if (!DL.empty()) Out << "target datalayout = \"" << DL << "\"\n"; Index: llvm/trunk/test/Assembler/source-filename.ll =================================================================== --- llvm/trunk/test/Assembler/source-filename.ll +++ llvm/trunk/test/Assembler/source-filename.ll @@ -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"