[llvm] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

Shao-Ce SUN via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 8 05:18:59 PDT 2023


https://github.com/sunshaoce created https://github.com/llvm/llvm-project/pull/65744:

I think this is very helpful for reading generated `.inc` files.

>From fc7ab81fd986e7a5a5d03fcfc53d23064a168ef1 Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN <sunshaoce at gmail.com>
Date: Fri, 8 Sep 2023 20:16:12 +0800
Subject: [PATCH] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader`

---
 llvm/include/llvm/TableGen/TableGenBackend.h | 3 ++-
 llvm/lib/TableGen/TableGenBackend.cpp        | 4 +++-
 llvm/utils/TableGen/VTEmitter.cpp            | 3 ++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/TableGen/TableGenBackend.h b/llvm/include/llvm/TableGen/TableGenBackend.h
index 39f1e14bc950841..7bbd163b0433aca 100644
--- a/llvm/include/llvm/TableGen/TableGenBackend.h
+++ b/llvm/include/llvm/TableGen/TableGenBackend.h
@@ -50,7 +50,8 @@ template <class EmitterC> class OptClass : Opt {
 
 /// emitSourceFileHeader - Output an LLVM style file header to the specified
 /// raw_ostream.
-void emitSourceFileHeader(StringRef Desc, raw_ostream &OS);
+void emitSourceFileHeader(StringRef Desc, raw_ostream &OS,
+                          StringRef SourcePath = "");
 
 } // End llvm namespace
 
diff --git a/llvm/lib/TableGen/TableGenBackend.cpp b/llvm/lib/TableGen/TableGenBackend.cpp
index 135ec643bc3a7df..fbbd5338f8d2609 100644
--- a/llvm/lib/TableGen/TableGenBackend.cpp
+++ b/llvm/lib/TableGen/TableGenBackend.cpp
@@ -40,7 +40,8 @@ static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
   OS << Suffix << '\n';
 }
 
-void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) {
+void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS,
+                                StringRef SourcePath) {
   printLine(OS, "/*===- TableGen'erated file ", '-', "*- C++ -*-===*\\");
   StringRef Prefix("|* ");
   StringRef Suffix(" *|");
@@ -56,6 +57,7 @@ void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS) {
   printLine(OS, Prefix, ' ', Suffix);
   printLine(OS, Prefix + "Automatically generated file, do not edit!", ' ',
     Suffix);
+  printLine(OS, Prefix + "From: " + SourcePath, ' ', Suffix);
   printLine(OS, Prefix, ' ', Suffix);
   printLine(OS, "\\*===", '-', "===*/");
   OS << '\n';
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index d398a7e7b58f40a..9a969a6fd3f802a 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -30,7 +30,8 @@ class VTEmitter {
 } // End anonymous namespace.
 
 void VTEmitter::run(raw_ostream &OS) {
-  emitSourceFileHeader("ValueTypes Source Fragment", OS);
+  emitSourceFileHeader("ValueTypes Source Fragment", OS,
+                       "llvm/include/llvm/CodeGen/ValueTypes.td");
 
   std::array<const Record *, 256> VTsByNumber = {};
   auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");



More information about the llvm-commits mailing list