Skip to content

Commit a86e966

Browse files
authored
[TableGen] Change TableGenMain to use const RecordKeeper (#110578)
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
1 parent bea1c90 commit a86e966

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

clang/utils/TableGen/TableGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ ClangComponent("clang-component",
317317
cl::desc("Only use warnings from specified component"),
318318
cl::value_desc("component"), cl::Hidden);
319319

320-
bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
320+
bool ClangTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
321321
switch (Action) {
322322
case PrintRecords:
323323
OS << Records; // No argument, dump all contents

libc/utils/HdrGen/Main.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,39 @@
1515
#include <string>
1616
#include <unordered_map>
1717

18-
namespace {
19-
20-
llvm::cl::opt<std::string>
18+
static llvm::cl::opt<std::string>
2119
HeaderDefFile("def", llvm::cl::desc("Path to the .h.def file."),
2220
llvm::cl::value_desc("<filename>"), llvm::cl::Required);
23-
llvm::cl::opt<std::string> StandardHeader(
21+
static llvm::cl::opt<std::string> StandardHeader(
2422
"header",
2523
llvm::cl::desc("The standard header file which is to be generated."),
2624
llvm::cl::value_desc("<header file>"));
27-
llvm::cl::list<std::string> EntrypointNamesOption(
25+
static llvm::cl::list<std::string> EntrypointNamesOption(
2826
"e", llvm::cl::value_desc("<list of entrypoints>"),
2927
llvm::cl::desc(
3028
"Each --e is one entrypoint (generated from entrypoints.txt)"),
3129
llvm::cl::OneOrMore);
32-
llvm::cl::list<std::string> ReplacementValues(
30+
static llvm::cl::list<std::string> ReplacementValues(
3331
"args", llvm::cl::desc("Command separated <argument name>=<value> pairs."),
3432
llvm::cl::value_desc("<name=value>[,name=value]"));
35-
llvm::cl::opt<bool> ExportDecls(
33+
static llvm::cl::opt<bool> ExportDecls(
3634
"export-decls",
3735
llvm::cl::desc("Output a new header containing only the entrypoints."));
3836

39-
void ParseArgValuePairs(std::unordered_map<std::string, std::string> &Map) {
37+
static void
38+
ParseArgValuePairs(std::unordered_map<std::string, std::string> &Map) {
4039
for (std::string &R : ReplacementValues) {
4140
auto Pair = llvm::StringRef(R).split('=');
4241
Map[std::string(Pair.first)] = std::string(Pair.second);
4342
}
4443
}
4544

46-
} // anonymous namespace
47-
48-
namespace llvm_libc {
49-
50-
bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
45+
static bool HeaderGeneratorMain(llvm::raw_ostream &OS,
46+
const llvm::RecordKeeper &Records) {
5147
std::unordered_map<std::string, std::string> ArgMap;
5248
ParseArgValuePairs(ArgMap);
53-
Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader, ArgMap);
49+
llvm_libc::Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader,
50+
ArgMap);
5451
if (ExportDecls)
5552
G.generateDecls(OS, Records);
5653
else
@@ -59,9 +56,7 @@ bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {
5956
return false;
6057
}
6158

62-
} // namespace llvm_libc
63-
6459
int main(int argc, char *argv[]) {
6560
llvm::cl::ParseCommandLineOptions(argc, argv);
66-
return TableGenMain(argv[0], &llvm_libc::HeaderGeneratorMain);
61+
return TableGenMain(argv[0], &HeaderGeneratorMain);
6762
}

llvm/include/llvm/TableGen/Main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RecordKeeper;
2222

2323
/// Perform the action using Records, and write output to OS.
2424
/// Returns true on error, false otherwise.
25-
using TableGenMainFn = bool (raw_ostream &OS, RecordKeeper &Records);
25+
using TableGenMainFn = bool(raw_ostream &OS, const RecordKeeper &Records);
2626

2727
int TableGenMain(const char *argv0,
2828
std::function<TableGenMainFn> MainFn = nullptr);

llvm/lib/TableGen/TableGenBackendSkeleton.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- SkeletonEmitter.cpp - Skeleton TableGen backend -*- C++ -*-===//
1+
//===- TableGenBackendSkeleton.cpp - Skeleton TableGen backend --*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -29,10 +29,10 @@ namespace {
2929

3030
class SkeletonEmitter {
3131
private:
32-
RecordKeeper &Records;
32+
const RecordKeeper &Records;
3333

3434
public:
35-
SkeletonEmitter(RecordKeeper &RK) : Records(RK) {}
35+
SkeletonEmitter(const RecordKeeper &RK) : Records(RK) {}
3636

3737
void run(raw_ostream &OS);
3838
}; // emitter class
@@ -55,7 +55,7 @@ static TableGen::Emitter::OptClass<SkeletonEmitter>
5555
//===----------------------------------------------------------------------===//
5656
// Option B: Register "EmitSkeleton" directly
5757
// The emitter entry may be private scope.
58-
static void EmitSkeleton(RecordKeeper &RK, raw_ostream &OS) {
58+
static void EmitSkeleton(const RecordKeeper &RK, raw_ostream &OS) {
5959
// Instantiate the emitter class and invoke run().
6060
SkeletonEmitter(RK).run(OS);
6161
}

mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static const mlir::GenInfo *generator;
126126

127127
// TableGenMain requires a function pointer so this function is passed in which
128128
// simply wraps the call to the generator.
129-
static bool mlirTableGenMain(raw_ostream &os, RecordKeeper &records) {
129+
static bool mlirTableGenMain(raw_ostream &os, const RecordKeeper &records) {
130130
if (actionOnDeprecatedValue != DeprecatedAction::None)
131131
warnOfDeprecatedUses(records);
132132

0 commit comments

Comments
 (0)