LLVM 22.0.0git
TableGenBackend.h
Go to the documentation of this file.
1//===- llvm/TableGen/TableGenBackend.h - Backend utilities ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Useful utilities for TableGen backends.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TABLEGEN_TABLEGENBACKEND_H
14#define LLVM_TABLEGEN_TABLEGENBACKEND_H
15
17#include "llvm/ADT/StringRef.h"
19
20namespace llvm {
21
22class RecordKeeper;
23class raw_ostream;
24
26using FnT = function_ref<void(const RecordKeeper &Records, raw_ostream &OS)>;
27
28/// Creating an `Opt` object registers the command line option \p Name with
29/// TableGen backend and associates the callback \p CB with that option. If
30/// \p ByDefault is true, then that callback is applied by default if no
31/// command line option was specified.
32struct Opt {
33 Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault = false);
34};
35
36/// Convienence wrapper around `Opt` that registers `EmitterClass::run` as the
37/// callback.
38template <class EmitterC> class OptClass : Opt {
39 static void run(const RecordKeeper &RK, raw_ostream &OS) {
40 EmitterC(RK).run(OS);
41 }
42
43public:
44 OptClass(StringRef Name, StringRef Desc) : Opt(Name, run, Desc) {}
45};
46
47/// Apply callback for any command line option registered above. Returns false
48/// is no callback was applied.
49bool ApplyCallback(const RecordKeeper &Records, raw_ostream &OS);
50
51} // namespace TableGen::Emitter
52
53/// emitSourceFileHeader - Output an LLVM style file header to the specified
54/// raw_ostream.
57
58} // namespace llvm
59
60#endif // LLVM_TABLEGEN_TABLEGENBACKEND_H
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
OptClass(StringRef Name, StringRef Desc)
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
function_ref< void(const RecordKeeper &Records, raw_ostream &OS)> FnT
bool ApplyCallback(const RecordKeeper &Records, raw_ostream &OS)
Apply callback for any command line option registered above.
This is an optimization pass for GlobalISel generic memory operations.
Op::Description Desc
void emitSourceFileHeader(StringRef Desc, raw_ostream &OS, const RecordKeeper &Record=RecordKeeper())
emitSourceFileHeader - Output an LLVM style file header to the specified raw_ostream.
Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault=false)