19870f6adSJonas Devlieghere //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===// 293f50594SJonas Devlieghere // 393f50594SJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 493f50594SJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information. 593f50594SJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 693f50594SJonas Devlieghere // 793f50594SJonas Devlieghere //===----------------------------------------------------------------------===// 893f50594SJonas Devlieghere // 99870f6adSJonas Devlieghere // This file contains the main function for LLDB's TableGen. 1093f50594SJonas Devlieghere // 1193f50594SJonas Devlieghere //===----------------------------------------------------------------------===// 1293f50594SJonas Devlieghere 1393f50594SJonas Devlieghere #include "LLDBTableGenBackends.h" // Declares all backends. 1493f50594SJonas Devlieghere #include "llvm/Support/CommandLine.h" 1530299b87SNikita Popov #include "llvm/Support/ManagedStatic.h" 1693f50594SJonas Devlieghere #include "llvm/Support/PrettyStackTrace.h" 1793f50594SJonas Devlieghere #include "llvm/Support/Signals.h" 1893f50594SJonas Devlieghere #include "llvm/TableGen/Error.h" 1993f50594SJonas Devlieghere #include "llvm/TableGen/Main.h" 2093f50594SJonas Devlieghere #include "llvm/TableGen/Record.h" 2193f50594SJonas Devlieghere 2293f50594SJonas Devlieghere using namespace llvm; 2393f50594SJonas Devlieghere using namespace lldb_private; 2493f50594SJonas Devlieghere 2593f50594SJonas Devlieghere enum ActionType { 2693f50594SJonas Devlieghere PrintRecords, 2793f50594SJonas Devlieghere DumpJSON, 2893f50594SJonas Devlieghere GenOptionDefs, 29971f9ca6SJonas Devlieghere GenPropertyDefs, 30971f9ca6SJonas Devlieghere GenPropertyEnumDefs, 3193f50594SJonas Devlieghere }; 3293f50594SJonas Devlieghere 33971f9ca6SJonas Devlieghere static cl::opt<ActionType> Action( 34971f9ca6SJonas Devlieghere cl::desc("Action to perform:"), 3593f50594SJonas Devlieghere cl::values(clEnumValN(PrintRecords, "print-records", 3693f50594SJonas Devlieghere "Print all records to stdout (default)"), 3793f50594SJonas Devlieghere clEnumValN(DumpJSON, "dump-json", 3893f50594SJonas Devlieghere "Dump all records as machine-readable JSON"), 3993f50594SJonas Devlieghere clEnumValN(GenOptionDefs, "gen-lldb-option-defs", 40971f9ca6SJonas Devlieghere "Generate lldb option definitions"), 41971f9ca6SJonas Devlieghere clEnumValN(GenPropertyDefs, "gen-lldb-property-defs", 42971f9ca6SJonas Devlieghere "Generate lldb property definitions"), 43971f9ca6SJonas Devlieghere clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs", 44971f9ca6SJonas Devlieghere "Generate lldb property enum definitions"))); 4593f50594SJonas Devlieghere 46*32cef078SRahul Joshi static bool LLDBTableGenMain(raw_ostream &OS, const RecordKeeper &Records) { 4793f50594SJonas Devlieghere switch (Action) { 4893f50594SJonas Devlieghere case PrintRecords: 4993f50594SJonas Devlieghere OS << Records; // No argument, dump all contents 5093f50594SJonas Devlieghere break; 5193f50594SJonas Devlieghere case DumpJSON: 5293f50594SJonas Devlieghere EmitJSON(Records, OS); 5393f50594SJonas Devlieghere break; 5493f50594SJonas Devlieghere case GenOptionDefs: 5593f50594SJonas Devlieghere EmitOptionDefs(Records, OS); 5693f50594SJonas Devlieghere break; 57971f9ca6SJonas Devlieghere case GenPropertyDefs: 58971f9ca6SJonas Devlieghere EmitPropertyDefs(Records, OS); 59971f9ca6SJonas Devlieghere break; 60971f9ca6SJonas Devlieghere case GenPropertyEnumDefs: 61971f9ca6SJonas Devlieghere EmitPropertyEnumDefs(Records, OS); 62971f9ca6SJonas Devlieghere break; 6393f50594SJonas Devlieghere } 6493f50594SJonas Devlieghere return false; 6593f50594SJonas Devlieghere } 6693f50594SJonas Devlieghere 6793f50594SJonas Devlieghere int main(int argc, char **argv) { 6893f50594SJonas Devlieghere sys::PrintStackTraceOnErrorSignal(argv[0]); 6993f50594SJonas Devlieghere PrettyStackTraceProgram X(argc, argv); 7093f50594SJonas Devlieghere cl::ParseCommandLineOptions(argc, argv); 7193f50594SJonas Devlieghere llvm_shutdown_obj Y; 7293f50594SJonas Devlieghere 7393f50594SJonas Devlieghere return TableGenMain(argv[0], &LLDBTableGenMain); 7493f50594SJonas Devlieghere } 7593f50594SJonas Devlieghere 7693f50594SJonas Devlieghere #ifdef __has_feature 7793f50594SJonas Devlieghere #if __has_feature(address_sanitizer) 7893f50594SJonas Devlieghere #include <sanitizer/lsan_interface.h> 7993f50594SJonas Devlieghere // Disable LeakSanitizer for this binary as it has too many leaks that are not 8093f50594SJonas Devlieghere // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h . 8193f50594SJonas Devlieghere int __lsan_is_turned_off() { return 1; } 8293f50594SJonas Devlieghere #endif // __has_feature(address_sanitizer) 8393f50594SJonas Devlieghere #endif // defined(__has_feature) 84