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
36 static cl::OptionCategory
PrintEnumsCat("Options for -print-enums");
37 static cl::opt
<std::string
> Class("class",
38 cl::desc("Print Enum list for this class"),
39 cl::value_desc("class name"),
40 cl::cat(PrintEnumsCat
));
42 static void printRecords(const RecordKeeper
&Records
, raw_ostream
&OS
) {
43 OS
<< Records
; // No argument, dump all contents
46 static void printEnums(const RecordKeeper
&Records
, raw_ostream
&OS
) {
47 for (const Record
*Rec
: Records
.getAllDerivedDefinitions(Class
))
48 OS
<< Rec
->getName() << ", ";
52 static void printSets(const RecordKeeper
&Records
, raw_ostream
&OS
) {
54 Sets
.addFieldExpander("Set", "Elements");
55 for (const Record
*Rec
: Records
.getAllDerivedDefinitions("Set")) {
56 OS
<< Rec
->getName() << " = [";
57 const std::vector
<const Record
*> *Elts
= Sets
.expand(Rec
);
58 assert(Elts
&& "Couldn't expand Set instance");
59 for (const Record
*Elt
: *Elts
)
60 OS
<< ' ' << Elt
->getName();
65 static TableGen::Emitter::Opt X
[] = {
66 {"print-records", printRecords
, "Print all records to stdout (default)",
68 {"print-detailed-records", EmitDetailedRecords
,
69 "Print full details of all records to stdout"},
70 {"null-backend", [](const RecordKeeper
&Records
, raw_ostream
&OS
) {},
71 "Do nothing after parsing (useful for timing)"},
72 {"dump-json", EmitJSON
, "Dump all records as machine-readable JSON"},
73 {"print-enums", printEnums
, "Print enum values for a class"},
74 {"print-sets", printSets
, "Print expanded sets for testing DAG exprs"},
77 int main(int argc
, char **argv
) {
78 InitLLVM
X(argc
, argv
);
79 cl::ParseCommandLineOptions(argc
, argv
);
81 return TableGenMain(argv
[0]);
85 #define __has_feature(x) 0
88 #if __has_feature(address_sanitizer) || \
89 (defined(__SANITIZE_ADDRESS__) && defined(__GNUC__)) || \
90 __has_feature(leak_sanitizer)
92 #include <sanitizer/lsan_interface.h>
93 // Disable LeakSanitizer for this binary as it has too many leaks that are not
94 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
95 LLVM_ATTRIBUTE_USED
int __lsan_is_turned_off() { return 1; }