1*700637cbSDimitry Andric //===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric //
9*700637cbSDimitry Andric // This file contains the global defintions (mostly command line parameters)
10*700637cbSDimitry Andric // shared between llvm-tblgen and llvm-min-tblgen.
11*700637cbSDimitry Andric //
12*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
13*700637cbSDimitry Andric
14*700637cbSDimitry Andric #include "TableGen.h"
15*700637cbSDimitry Andric #include "llvm/ADT/StringRef.h"
16*700637cbSDimitry Andric #include "llvm/Support/CommandLine.h"
17*700637cbSDimitry Andric #include "llvm/Support/InitLLVM.h"
18*700637cbSDimitry Andric #include "llvm/Support/raw_ostream.h"
19*700637cbSDimitry Andric #include "llvm/TableGen/Main.h"
20*700637cbSDimitry Andric #include "llvm/TableGen/Record.h"
21*700637cbSDimitry Andric #include "llvm/TableGen/SetTheory.h"
22*700637cbSDimitry Andric #include "llvm/TableGen/TableGenBackend.h"
23*700637cbSDimitry Andric #include <cassert>
24*700637cbSDimitry Andric #include <string>
25*700637cbSDimitry Andric #include <vector>
26*700637cbSDimitry Andric
27*700637cbSDimitry Andric using namespace llvm;
28*700637cbSDimitry Andric
29*700637cbSDimitry Andric static cl::OptionCategory PrintEnumsCat("Options for -print-enums");
30*700637cbSDimitry Andric static cl::opt<std::string> Class("class",
31*700637cbSDimitry Andric cl::desc("Print Enum list for this class"),
32*700637cbSDimitry Andric cl::value_desc("class name"),
33*700637cbSDimitry Andric cl::cat(PrintEnumsCat));
34*700637cbSDimitry Andric
printRecords(const RecordKeeper & Records,raw_ostream & OS)35*700637cbSDimitry Andric static void printRecords(const RecordKeeper &Records, raw_ostream &OS) {
36*700637cbSDimitry Andric OS << Records; // No argument, dump all contents
37*700637cbSDimitry Andric }
38*700637cbSDimitry Andric
printEnums(const RecordKeeper & Records,raw_ostream & OS)39*700637cbSDimitry Andric static void printEnums(const RecordKeeper &Records, raw_ostream &OS) {
40*700637cbSDimitry Andric for (const Record *Rec : Records.getAllDerivedDefinitions(Class))
41*700637cbSDimitry Andric OS << Rec->getName() << ", ";
42*700637cbSDimitry Andric OS << "\n";
43*700637cbSDimitry Andric }
44*700637cbSDimitry Andric
printSets(const RecordKeeper & Records,raw_ostream & OS)45*700637cbSDimitry Andric static void printSets(const RecordKeeper &Records, raw_ostream &OS) {
46*700637cbSDimitry Andric SetTheory Sets;
47*700637cbSDimitry Andric Sets.addFieldExpander("Set", "Elements");
48*700637cbSDimitry Andric for (const Record *Rec : Records.getAllDerivedDefinitions("Set")) {
49*700637cbSDimitry Andric OS << Rec->getName() << " = [";
50*700637cbSDimitry Andric const std::vector<const Record *> *Elts = Sets.expand(Rec);
51*700637cbSDimitry Andric assert(Elts && "Couldn't expand Set instance");
52*700637cbSDimitry Andric for (const Record *Elt : *Elts)
53*700637cbSDimitry Andric OS << ' ' << Elt->getName();
54*700637cbSDimitry Andric OS << " ]\n";
55*700637cbSDimitry Andric }
56*700637cbSDimitry Andric }
57*700637cbSDimitry Andric
58*700637cbSDimitry Andric static TableGen::Emitter::Opt X[] = {
59*700637cbSDimitry Andric {"print-records", printRecords, "Print all records to stdout (default)",
60*700637cbSDimitry Andric true},
61*700637cbSDimitry Andric {"print-detailed-records", EmitDetailedRecords,
62*700637cbSDimitry Andric "Print full details of all records to stdout"},
__anon754f012e0102() 63*700637cbSDimitry Andric {"null-backend", [](const RecordKeeper &Records, raw_ostream &OS) {},
64*700637cbSDimitry Andric "Do nothing after parsing (useful for timing)"},
65*700637cbSDimitry Andric {"dump-json", EmitJSON, "Dump all records as machine-readable JSON"},
66*700637cbSDimitry Andric {"print-enums", printEnums, "Print enum values for a class"},
67*700637cbSDimitry Andric {"print-sets", printSets, "Print expanded sets for testing DAG exprs"},
68*700637cbSDimitry Andric };
69*700637cbSDimitry Andric
tblgen_main(int argc,char ** argv)70*700637cbSDimitry Andric int tblgen_main(int argc, char **argv) {
71*700637cbSDimitry Andric InitLLVM X(argc, argv);
72*700637cbSDimitry Andric cl::ParseCommandLineOptions(argc, argv);
73*700637cbSDimitry Andric
74*700637cbSDimitry Andric return TableGenMain(argv[0]);
75*700637cbSDimitry Andric }
76*700637cbSDimitry Andric
77*700637cbSDimitry Andric #ifndef __has_feature
78*700637cbSDimitry Andric #define __has_feature(x) 0
79*700637cbSDimitry Andric #endif
80*700637cbSDimitry Andric
81*700637cbSDimitry Andric #if __has_feature(address_sanitizer) || \
82*700637cbSDimitry Andric (defined(__SANITIZE_ADDRESS__) && defined(__GNUC__)) || \
83*700637cbSDimitry Andric __has_feature(leak_sanitizer)
84*700637cbSDimitry Andric
85*700637cbSDimitry Andric #include <sanitizer/lsan_interface.h>
86*700637cbSDimitry Andric // Disable LeakSanitizer for this binary as it has too many leaks that are not
87*700637cbSDimitry Andric // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()88*700637cbSDimitry Andric LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }
89*700637cbSDimitry Andric
90*700637cbSDimitry Andric #endif
91