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
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/CommandLine.h"
18#include "llvm/Support/ManagedStatic.h"
19#include "llvm/TableGen/Record.h"
20
21namespace llvm {
22
23class RecordKeeper;
24class raw_ostream;
25
26namespace TableGen::Emitter {
27using FnT = void (*)(RecordKeeper &Records, raw_ostream &OS);
28
29struct OptCreatorT {
30 static void *call();
31};
32
33extern ManagedStatic<cl::opt<FnT>, OptCreatorT> Action;
34
35struct Opt {
36 Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault = false) {
37 if (ByDefault)
38 Action->setInitialValue(CB);
39 Action->getParser().addLiteralOption(Name, V: CB, HelpStr: Desc);
40 }
41};
42
43template <class EmitterC> class OptClass : Opt {
44 static void run(RecordKeeper &RK, raw_ostream &OS) { EmitterC(RK).run(OS); }
45
46public:
47 OptClass(StringRef Name, StringRef Desc) : Opt(Name, run, Desc) {}
48};
49
50} // namespace TableGen::Emitter
51
52/// emitSourceFileHeader - Output an LLVM style file header to the specified
53/// raw_ostream.
54void emitSourceFileHeader(StringRef Desc, raw_ostream &OS,
55 const RecordKeeper &Record = RecordKeeper());
56
57} // End llvm namespace
58
59#endif
60

source code of llvm/include/llvm/TableGen/TableGenBackend.h