[PATCH] D18588: [ThinLTO] Serialize the Module SourceFileName to/from LLVM assembly

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 07:05:18 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL264869: [ThinLTO] Serialize the Module SourceFileName to/from LLVM assembly (authored by tejohnson).

Changed prior to commit:
  http://reviews.llvm.org/D18588?vs=52019&id=52054#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18588

Files:
  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
  llvm/trunk/test/Assembler/source-filename.ll

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"
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/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/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.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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18588.52054.patch
Type: text/x-patch
Size: 3582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160330/d63b6de0/attachment-0001.bin>


More information about the llvm-commits mailing list