1 //===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains the main function for LLVM's TableGen.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/InitLLVM.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include "llvm/TableGen/Main.h"
18 #include "llvm/TableGen/Record.h"
19 #include "llvm/TableGen/SetTheory.h"
20 #include "llvm/TableGen/TableGenBackend.h"
28 cl::opt
<bool> EmitLongStrLiterals(
29 "long-string-literals",
30 cl::desc("when emitting large string tables, prefer string literals over "
31 "comma-separated char literals. This can be a readability and "
32 "compile-time performance win, but upsets some compilers"),
33 cl::Hidden
, cl::init(true));
34 } // end namespace llvm
38 cl::OptionCategory
PrintEnumsCat("Options for -print-enums");
39 cl::opt
<std::string
> Class("class", cl::desc("Print Enum list for this class"),
40 cl::value_desc("class name"),
41 cl::cat(PrintEnumsCat
));
43 void PrintRecords(RecordKeeper
&Records
, raw_ostream
&OS
) {
44 OS
<< Records
; // No argument, dump all contents
47 void PrintEnums(RecordKeeper
&Records
, raw_ostream
&OS
) {
48 for (Record
*Rec
: Records
.getAllDerivedDefinitions(Class
))
49 OS
<< Rec
->getName() << ", ";
53 void PrintSets(RecordKeeper
&Records
, raw_ostream
&OS
) {
55 Sets
.addFieldExpander("Set", "Elements");
56 for (Record
*Rec
: Records
.getAllDerivedDefinitions("Set")) {
57 OS
<< Rec
->getName() << " = [";
58 const std::vector
<Record
*> *Elts
= Sets
.expand(Rec
);
59 assert(Elts
&& "Couldn't expand Set instance");
60 for (Record
*Elt
: *Elts
)
61 OS
<< ' ' << Elt
->getName();
66 TableGen::Emitter::Opt X
[] = {
67 {"print-records", PrintRecords
, "Print all records to stdout (default)",
69 {"print-detailed-records", EmitDetailedRecords
,
70 "Print full details of all records to stdout"},
71 {"null-backend", [](RecordKeeper
&Records
, raw_ostream
&OS
) {},
72 "Do nothing after parsing (useful for timing)"},
73 {"dump-json", EmitJSON
, "Dump all records as machine-readable JSON"},
74 {"print-enums", PrintEnums
, "Print enum values for a class"},
75 {"print-sets", PrintSets
, "Print expanded sets for testing DAG exprs"},
80 int main(int argc
, char **argv
) {
81 InitLLVM
X(argc
, argv
);
82 cl::ParseCommandLineOptions(argc
, argv
);
84 return TableGenMain(argv
[0]);
88 #define __has_feature(x) 0
91 #if __has_feature(address_sanitizer) || \
92 (defined(__SANITIZE_ADDRESS__) && defined(__GNUC__)) || \
93 __has_feature(leak_sanitizer)
95 #include <sanitizer/lsan_interface.h>
96 // Disable LeakSanitizer for this binary as it has too many leaks that are not
97 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
98 LLVM_ATTRIBUTE_USED
int __lsan_is_turned_off() { return 1; }