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