19dba64beSDimitry Andric //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
99dba64beSDimitry Andric // This file contains the main function for LLDB's TableGen.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "LLDBTableGenBackends.h" // Declares all backends.
140b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
15*0fca6ea1SDimitry Andric #include "llvm/Support/ManagedStatic.h"
160b57cec5SDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
170b57cec5SDimitry Andric #include "llvm/Support/Signals.h"
180b57cec5SDimitry Andric #include "llvm/TableGen/Error.h"
190b57cec5SDimitry Andric #include "llvm/TableGen/Main.h"
200b57cec5SDimitry Andric #include "llvm/TableGen/Record.h"
210b57cec5SDimitry Andric
220b57cec5SDimitry Andric using namespace llvm;
230b57cec5SDimitry Andric using namespace lldb_private;
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric enum ActionType {
260b57cec5SDimitry Andric PrintRecords,
270b57cec5SDimitry Andric DumpJSON,
280b57cec5SDimitry Andric GenOptionDefs,
299dba64beSDimitry Andric GenPropertyDefs,
309dba64beSDimitry Andric GenPropertyEnumDefs,
310b57cec5SDimitry Andric };
320b57cec5SDimitry Andric
339dba64beSDimitry Andric static cl::opt<ActionType> Action(
349dba64beSDimitry Andric cl::desc("Action to perform:"),
350b57cec5SDimitry Andric cl::values(clEnumValN(PrintRecords, "print-records",
360b57cec5SDimitry Andric "Print all records to stdout (default)"),
370b57cec5SDimitry Andric clEnumValN(DumpJSON, "dump-json",
380b57cec5SDimitry Andric "Dump all records as machine-readable JSON"),
390b57cec5SDimitry Andric clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
409dba64beSDimitry Andric "Generate lldb option definitions"),
419dba64beSDimitry Andric clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
429dba64beSDimitry Andric "Generate lldb property definitions"),
439dba64beSDimitry Andric clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
449dba64beSDimitry Andric "Generate lldb property enum definitions")));
450b57cec5SDimitry Andric
LLDBTableGenMain(raw_ostream & OS,RecordKeeper & Records)460b57cec5SDimitry Andric static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
470b57cec5SDimitry Andric switch (Action) {
480b57cec5SDimitry Andric case PrintRecords:
490b57cec5SDimitry Andric OS << Records; // No argument, dump all contents
500b57cec5SDimitry Andric break;
510b57cec5SDimitry Andric case DumpJSON:
520b57cec5SDimitry Andric EmitJSON(Records, OS);
530b57cec5SDimitry Andric break;
540b57cec5SDimitry Andric case GenOptionDefs:
550b57cec5SDimitry Andric EmitOptionDefs(Records, OS);
560b57cec5SDimitry Andric break;
579dba64beSDimitry Andric case GenPropertyDefs:
589dba64beSDimitry Andric EmitPropertyDefs(Records, OS);
599dba64beSDimitry Andric break;
609dba64beSDimitry Andric case GenPropertyEnumDefs:
619dba64beSDimitry Andric EmitPropertyEnumDefs(Records, OS);
629dba64beSDimitry Andric break;
630b57cec5SDimitry Andric }
640b57cec5SDimitry Andric return false;
650b57cec5SDimitry Andric }
660b57cec5SDimitry Andric
main(int argc,char ** argv)670b57cec5SDimitry Andric int main(int argc, char **argv) {
680b57cec5SDimitry Andric sys::PrintStackTraceOnErrorSignal(argv[0]);
690b57cec5SDimitry Andric PrettyStackTraceProgram X(argc, argv);
700b57cec5SDimitry Andric cl::ParseCommandLineOptions(argc, argv);
710b57cec5SDimitry Andric llvm_shutdown_obj Y;
720b57cec5SDimitry Andric
730b57cec5SDimitry Andric return TableGenMain(argv[0], &LLDBTableGenMain);
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric
760b57cec5SDimitry Andric #ifdef __has_feature
770b57cec5SDimitry Andric #if __has_feature(address_sanitizer)
780b57cec5SDimitry Andric #include <sanitizer/lsan_interface.h>
790b57cec5SDimitry Andric // Disable LeakSanitizer for this binary as it has too many leaks that are not
800b57cec5SDimitry Andric // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()810b57cec5SDimitry Andric int __lsan_is_turned_off() { return 1; }
820b57cec5SDimitry Andric #endif // __has_feature(address_sanitizer)
830b57cec5SDimitry Andric #endif // defined(__has_feature)
84