1*0b57cec5SDimitry Andric //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file contains the main function for LLDB's TableGen.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric
13*0b57cec5SDimitry Andric #include "LLDBTableGenBackends.h" // Declares all backends.
14*0b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
15*0b57cec5SDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
16*0b57cec5SDimitry Andric #include "llvm/Support/Signals.h"
17*0b57cec5SDimitry Andric #include "llvm/TableGen/Error.h"
18*0b57cec5SDimitry Andric #include "llvm/TableGen/Main.h"
19*0b57cec5SDimitry Andric #include "llvm/TableGen/Record.h"
20*0b57cec5SDimitry Andric
21*0b57cec5SDimitry Andric using namespace llvm;
22*0b57cec5SDimitry Andric using namespace lldb_private;
23*0b57cec5SDimitry Andric
24*0b57cec5SDimitry Andric enum ActionType {
25*0b57cec5SDimitry Andric PrintRecords,
26*0b57cec5SDimitry Andric DumpJSON,
27*0b57cec5SDimitry Andric GenOptionDefs,
28*0b57cec5SDimitry Andric GenPropertyDefs,
29*0b57cec5SDimitry Andric GenPropertyEnumDefs,
30*0b57cec5SDimitry Andric };
31*0b57cec5SDimitry Andric
32*0b57cec5SDimitry Andric static cl::opt<ActionType> Action(
33*0b57cec5SDimitry Andric cl::desc("Action to perform:"),
34*0b57cec5SDimitry Andric cl::values(clEnumValN(PrintRecords, "print-records",
35*0b57cec5SDimitry Andric "Print all records to stdout (default)"),
36*0b57cec5SDimitry Andric clEnumValN(DumpJSON, "dump-json",
37*0b57cec5SDimitry Andric "Dump all records as machine-readable JSON"),
38*0b57cec5SDimitry Andric clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
39*0b57cec5SDimitry Andric "Generate lldb option definitions"),
40*0b57cec5SDimitry Andric clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
41*0b57cec5SDimitry Andric "Generate lldb property definitions"),
42*0b57cec5SDimitry Andric clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
43*0b57cec5SDimitry Andric "Generate lldb property enum definitions")));
44*0b57cec5SDimitry Andric
LLDBTableGenMain(raw_ostream & OS,RecordKeeper & Records)45*0b57cec5SDimitry Andric static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
46*0b57cec5SDimitry Andric switch (Action) {
47*0b57cec5SDimitry Andric case PrintRecords:
48*0b57cec5SDimitry Andric OS << Records; // No argument, dump all contents
49*0b57cec5SDimitry Andric break;
50*0b57cec5SDimitry Andric case DumpJSON:
51*0b57cec5SDimitry Andric EmitJSON(Records, OS);
52*0b57cec5SDimitry Andric break;
53*0b57cec5SDimitry Andric case GenOptionDefs:
54*0b57cec5SDimitry Andric EmitOptionDefs(Records, OS);
55*0b57cec5SDimitry Andric break;
56*0b57cec5SDimitry Andric case GenPropertyDefs:
57*0b57cec5SDimitry Andric EmitPropertyDefs(Records, OS);
58*0b57cec5SDimitry Andric break;
59*0b57cec5SDimitry Andric case GenPropertyEnumDefs:
60*0b57cec5SDimitry Andric EmitPropertyEnumDefs(Records, OS);
61*0b57cec5SDimitry Andric break;
62*0b57cec5SDimitry Andric }
63*0b57cec5SDimitry Andric return false;
64*0b57cec5SDimitry Andric }
65*0b57cec5SDimitry Andric
main(int argc,char ** argv)66*0b57cec5SDimitry Andric int main(int argc, char **argv) {
67*0b57cec5SDimitry Andric sys::PrintStackTraceOnErrorSignal(argv[0]);
68*0b57cec5SDimitry Andric PrettyStackTraceProgram X(argc, argv);
69*0b57cec5SDimitry Andric cl::ParseCommandLineOptions(argc, argv);
70*0b57cec5SDimitry Andric
71*0b57cec5SDimitry Andric llvm_shutdown_obj Y;
72
73 return TableGenMain(argv[0], &LLDBTableGenMain);
74 }
75
76 #ifdef __has_feature
77 #if __has_feature(address_sanitizer)
78 #include <sanitizer/lsan_interface.h>
79 // Disable LeakSanitizer for this binary as it has too many leaks that are not
80 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()81 int __lsan_is_turned_off() { return 1; }
82 #endif // __has_feature(address_sanitizer)
83 #endif // defined(__has_feature)
84