Skip to content

[TableGen] Change backend callback to require const RecordKeeper #111064

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 4, 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
9 changes: 5 additions & 4 deletions llvm/include/llvm/TableGen/TableGenBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class RecordKeeper;
class raw_ostream;

namespace TableGen::Emitter {
// Supports const and non-const forms of callback functions.
using FnT = function_ref<void(RecordKeeper &Records, raw_ostream &OS)>;
using FnT = function_ref<void(const RecordKeeper &Records, raw_ostream &OS)>;

/// Creating an `Opt` object registers the command line option \p Name with
/// TableGen backend and associates the callback \p CB with that option. If
Expand All @@ -37,15 +36,17 @@ struct Opt {
/// Convienence wrapper around `Opt` that registers `EmitterClass::run` as the
/// callback.
template <class EmitterC> class OptClass : Opt {
static void run(RecordKeeper &RK, raw_ostream &OS) { EmitterC(RK).run(OS); }
static void run(const RecordKeeper &RK, raw_ostream &OS) {
EmitterC(RK).run(OS);
}

public:
OptClass(StringRef Name, StringRef Desc) : Opt(Name, run, Desc) {}
};

/// Apply callback for any command line option registered above. Returns false
/// is no callback was applied.
bool ApplyCallback(RecordKeeper &Records, raw_ostream &OS);
bool ApplyCallback(const RecordKeeper &Records, raw_ostream &OS);

} // namespace TableGen::Emitter

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/TableGen/TableGenBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Opt::Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault) {

/// Apply callback specified on the command line. Returns true if no callback
/// was applied.
bool llvm::TableGen::Emitter::ApplyCallback(RecordKeeper &Records,
bool llvm::TableGen::Emitter::ApplyCallback(const RecordKeeper &Records,
raw_ostream &OS) {
FnT Fn = CallbackFunction->getValue();
if (!Fn)
Expand Down
Loading