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