Skip to content

[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 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/utils/TableGen/TableGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 12 additions & 17 deletions libc/utils/HdrGen/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion llvm/include/llvm/TableGen/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/TableGen/TableGenBackendSkeleton.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading