-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[TableGen] Change TableGenMain to use const RecordKeeper #110578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Change TableGenMain's `MainFn` argument to be a function that accepts a const reference to RecordKeeper.
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Rahul Joshi (jurahul) ChangesChange TableGenMain's Full diff: https://github.com/llvm/llvm-project/pull/110578.diff 5 Files Affected:
diff --git a/clang/utils/TableGen/TableGen.cpp b/clang/utils/TableGen/TableGen.cpp
index 84afd4c0afb269..39c178bc4f9baf 100644
--- a/clang/utils/TableGen/TableGen.cpp
+++ b/clang/utils/TableGen/TableGen.cpp
@@ -317,7 +317,7 @@ ClangComponent("clang-component",
cl::desc("Only use warnings from specified component"),
cl::value_desc("component"), cl::Hidden);
-bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
+bool ClangTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
switch (Action) {
case PrintRecords:
OS << Records; // No argument, dump all contents
diff --git a/libc/utils/HdrGen/Main.cpp b/libc/utils/HdrGen/Main.cpp
index d3418f206b10e9..f795e96e45c57a 100644
--- a/libc/utils/HdrGen/Main.cpp
+++ b/libc/utils/HdrGen/Main.cpp
@@ -15,42 +15,39 @@
#include <string>
#include <unordered_map>
-namespace {
-
-llvm::cl::opt<std::string>
+static llvm::cl::opt<std::string>
HeaderDefFile("def", llvm::cl::desc("Path to the .h.def file."),
llvm::cl::value_desc("<filename>"), llvm::cl::Required);
-llvm::cl::opt<std::string> StandardHeader(
+static llvm::cl::opt<std::string> StandardHeader(
"header",
llvm::cl::desc("The standard header file which is to be generated."),
llvm::cl::value_desc("<header file>"));
-llvm::cl::list<std::string> EntrypointNamesOption(
+static llvm::cl::list<std::string> EntrypointNamesOption(
"e", llvm::cl::value_desc("<list of entrypoints>"),
llvm::cl::desc(
"Each --e is one entrypoint (generated from entrypoints.txt)"),
llvm::cl::OneOrMore);
-llvm::cl::list<std::string> ReplacementValues(
+static llvm::cl::list<std::string> ReplacementValues(
"args", llvm::cl::desc("Command separated <argument name>=<value> pairs."),
llvm::cl::value_desc("<name=value>[,name=value]"));
-llvm::cl::opt<bool> ExportDecls(
+static llvm::cl::opt<bool> ExportDecls(
"export-decls",
llvm::cl::desc("Output a new header containing only the entrypoints."));
-void ParseArgValuePairs(std::unordered_map<std::string, std::string> &Map) {
+static void
+ParseArgValuePairs(std::unordered_map<std::string, std::string> &Map) {
for (std::string &R : ReplacementValues) {
auto Pair = llvm::StringRef(R).split('=');
Map[std::string(Pair.first)] = std::string(Pair.second);
}
}
-} // anonymous namespace
-
-namespace llvm_libc {
-
-bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
+static bool HeaderGeneratorMain(llvm::raw_ostream &OS,
+ const llvm::RecordKeeper &Records) {
std::unordered_map<std::string, std::string> ArgMap;
ParseArgValuePairs(ArgMap);
- Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader, ArgMap);
+ llvm_libc::Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader,
+ ArgMap);
if (ExportDecls)
G.generateDecls(OS, Records);
else
@@ -59,9 +56,7 @@ bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
return false;
}
-} // namespace llvm_libc
-
int main(int argc, char *argv[]) {
llvm::cl::ParseCommandLineOptions(argc, argv);
- return TableGenMain(argv[0], &llvm_libc::HeaderGeneratorMain);
+ return TableGenMain(argv[0], &HeaderGeneratorMain);
}
diff --git a/llvm/include/llvm/TableGen/Main.h b/llvm/include/llvm/TableGen/Main.h
index 4639ec756e9b17..e8c60e28699022 100644
--- a/llvm/include/llvm/TableGen/Main.h
+++ b/llvm/include/llvm/TableGen/Main.h
@@ -22,7 +22,7 @@ class RecordKeeper;
/// Perform the action using Records, and write output to OS.
/// Returns true on error, false otherwise.
-using TableGenMainFn = bool (raw_ostream &OS, RecordKeeper &Records);
+using TableGenMainFn = bool(raw_ostream &OS, const RecordKeeper &Records);
int TableGenMain(const char *argv0,
std::function<TableGenMainFn> MainFn = nullptr);
diff --git a/llvm/lib/TableGen/TableGenBackendSkeleton.cpp b/llvm/lib/TableGen/TableGenBackendSkeleton.cpp
index 8e65b7a5b300fd..a7c4a8925799a2 100644
--- a/llvm/lib/TableGen/TableGenBackendSkeleton.cpp
+++ b/llvm/lib/TableGen/TableGenBackendSkeleton.cpp
@@ -1,4 +1,4 @@
-//===- SkeletonEmitter.cpp - Skeleton TableGen backend -*- C++ -*-===//
+//===- TableGenBackendSkeleton.cpp - Skeleton TableGen backend --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -29,10 +29,10 @@ namespace {
class SkeletonEmitter {
private:
- RecordKeeper &Records;
+ const RecordKeeper &Records;
public:
- SkeletonEmitter(RecordKeeper &RK) : Records(RK) {}
+ SkeletonEmitter(const RecordKeeper &RK) : Records(RK) {}
void run(raw_ostream &OS);
}; // emitter class
@@ -55,7 +55,7 @@ static TableGen::Emitter::OptClass<SkeletonEmitter>
//===----------------------------------------------------------------------===//
// Option B: Register "EmitSkeleton" directly
// The emitter entry may be private scope.
-static void EmitSkeleton(RecordKeeper &RK, raw_ostream &OS) {
+static void EmitSkeleton(const RecordKeeper &RK, raw_ostream &OS) {
// Instantiate the emitter class and invoke run().
SkeletonEmitter(RK).run(OS);
}
diff --git a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
index 1911b6e3aa3927..7119324dd125d5 100644
--- a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
+++ b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
@@ -126,7 +126,7 @@ static const mlir::GenInfo *generator;
// TableGenMain requires a function pointer so this function is passed in which
// simply wraps the call to the generator.
-static bool mlirTableGenMain(raw_ostream &os, RecordKeeper &records) {
+static bool mlirTableGenMain(raw_ostream &os, const RecordKeeper &records) {
if (actionOnDeprecatedValue != DeprecatedAction::None)
warnOfDeprecatedUses(records);
|
arsenm
approved these changes
Oct 1, 2024
Sterling-Augustine
pushed a commit
to Sterling-Augustine/llvm-project
that referenced
this pull request
Oct 3, 2024
Change TableGenMain's `MainFn` argument to be a function that accepts a const reference to RecordKeeper. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change TableGenMain's
MainFn
argument to be a function that accepts a const reference to RecordKeeper.This is a part of effort to have better const correctness in TableGen backends:
https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089