aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-09-19 17:17:53 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-09-19 17:17:53 +0000
commit30ea79295cc2a5eee141d42b064a7170dc816e5f (patch)
treefe6a110942259f3d79a5b4e61ec75c298eb0635f
parentbc9477c1e1e269b892d68ad400a383e3bbc53a84 (diff)
downloadsrc-vendor/lldb-90.tar.gz
src-vendor/lldb-90.zip
Vendor import of lldb 9.0.0 release r372316:vendor/lldb/lldb-release_900-r372316vendor/lldb-90
Notes
Notes: svn path=/vendor/lldb/dist-release_90/; revision=352530 svn path=/vendor/lldb/lldb-release_900-r372316/; revision=352531; tag=vendor/lldb/lldb-release_900-r372316
-rw-r--r--utils/TableGen/LLDBOptionDefEmitter.cpp151
-rw-r--r--utils/TableGen/LLDBTableGen.cpp71
-rw-r--r--utils/TableGen/LLDBTableGenBackends.h34
3 files changed, 256 insertions, 0 deletions
diff --git a/utils/TableGen/LLDBOptionDefEmitter.cpp b/utils/TableGen/LLDBOptionDefEmitter.cpp
new file mode 100644
index 000000000000..4e62197d3989
--- /dev/null
+++ b/utils/TableGen/LLDBOptionDefEmitter.cpp
@@ -0,0 +1,151 @@
+//===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// These tablegen backends emits LLDB's OptionDefinition values for different
+// LLDB commands.
+//
+//===----------------------------------------------------------------------===//
+
+#include "LLDBTableGenBackends.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
+#include "llvm/TableGen/TableGenBackend.h"
+#include <map>
+#include <vector>
+
+using namespace llvm;
+
+/// Map of command names to their associated records. Also makes sure our
+/// commands are sorted in a deterministic way.
+typedef std::map<std::string, std::vector<Record *>> RecordsByCommand;
+
+/// Groups all records by their command.
+static RecordsByCommand getCommandList(std::vector<Record *> Options) {
+ RecordsByCommand result;
+ for (Record *Option : Options)
+ result[Option->getValueAsString("Command").str()].push_back(Option);
+ return result;
+}
+
+static void emitOption(Record *Option, raw_ostream &OS) {
+ OS << " {";
+
+ // List of option groups this option is in.
+ std::vector<std::string> GroupsArg;
+
+ if (Option->getValue("Groups")) {
+ // The user specified a list of groups.
+ auto Groups = Option->getValueAsListOfInts("Groups");
+ for (int Group : Groups)
+ GroupsArg.push_back("LLDB_OPT_SET_" + std::to_string(Group));
+ } else if (Option->getValue("GroupStart")) {
+ // The user specified a range of groups (with potentially only one element).
+ int GroupStart = Option->getValueAsInt("GroupStart");
+ int GroupEnd = Option->getValueAsInt("GroupEnd");
+ for (int i = GroupStart; i <= GroupEnd; ++i)
+ GroupsArg.push_back("LLDB_OPT_SET_" + std::to_string(i));
+ }
+
+ // If we have any groups, we merge them. Otherwise we move this option into
+ // the all group.
+ if (GroupsArg.empty())
+ OS << "LLDB_OPT_SET_ALL";
+ else
+ OS << llvm::join(GroupsArg.begin(), GroupsArg.end(), " | ");
+
+ OS << ", ";
+
+ // Check if this option is required.
+ OS << (Option->getValue("Required") ? "true" : "false");
+
+ // Add the full and short name for this option.
+ OS << ", \"" << Option->getValueAsString("FullName") << "\", ";
+ OS << '\'' << Option->getValueAsString("ShortName") << "'";
+
+ auto ArgType = Option->getValue("ArgType");
+ bool IsOptionalArg = Option->getValue("OptionalArg") != nullptr;
+
+ // Decide if we have either an option, required or no argument for this
+ // option.
+ OS << ", OptionParser::";
+ if (ArgType) {
+ if (IsOptionalArg)
+ OS << "eOptionalArgument";
+ else
+ OS << "eRequiredArgument";
+ } else
+ OS << "eNoArgument";
+ OS << ", nullptr, ";
+
+ if (Option->getValue("ArgEnum"))
+ OS << Option->getValueAsString("ArgEnum");
+ else
+ OS << "{}";
+ OS << ", ";
+
+ // Read the tab completions we offer for this option (if there are any)
+ if (Option->getValue("Completions")) {
+ auto Completions = Option->getValueAsListOfStrings("Completions");
+ std::vector<std::string> CompletionArgs;
+ for (llvm::StringRef Completion : Completions)
+ CompletionArgs.push_back("CommandCompletions::e" + Completion.str() +
+ "Completion");
+
+ OS << llvm::join(CompletionArgs.begin(), CompletionArgs.end(), " | ");
+ } else {
+ OS << "CommandCompletions::eNoCompletion";
+ }
+
+ // Add the argument type.
+ OS << ", eArgType";
+ if (ArgType) {
+ OS << ArgType->getValue()->getAsUnquotedString();
+ } else
+ OS << "None";
+ OS << ", ";
+
+ // Add the description if there is any.
+ if (auto D = Option->getValue("Description"))
+ OS << D->getValue()->getAsString();
+ else
+ OS << "\"\"";
+ OS << "},\n";
+}
+
+/// Emits all option initializers to the raw_ostream.
+static void emitOptions(std::string Command, std::vector<Record *> Option,
+ raw_ostream &OS) {
+ // Generate the macro that the user needs to define before including the
+ // *.inc file.
+ std::string NeededMacro = "LLDB_OPTIONS_" + Command;
+ std::replace(NeededMacro.begin(), NeededMacro.end(), ' ', '_');
+
+ // All options are in one file, so we need put them behind macros and ask the
+ // user to define the macro for the options that are needed.
+ OS << "// Options for " << Command << "\n";
+ OS << "#ifdef " << NeededMacro << "\n";
+ for (Record *R : Option)
+ emitOption(R, OS);
+ // We undefine the macro for the user like Clang's include files are doing it.
+ OS << "#undef " << NeededMacro << "\n";
+ OS << "#endif // " << Command << " command\n\n";
+}
+
+void lldb_private::EmitOptionDefs(RecordKeeper &Records, raw_ostream &OS) {
+
+ std::vector<Record *> Options = Records.getAllDerivedDefinitions("Option");
+
+ emitSourceFileHeader("Options for LLDB command line commands.", OS);
+
+ RecordsByCommand ByCommand = getCommandList(Options);
+
+ for (auto &CommandRecordPair : ByCommand) {
+ emitOptions(CommandRecordPair.first, CommandRecordPair.second, OS);
+ }
+}
diff --git a/utils/TableGen/LLDBTableGen.cpp b/utils/TableGen/LLDBTableGen.cpp
new file mode 100644
index 000000000000..9325fe038561
--- /dev/null
+++ b/utils/TableGen/LLDBTableGen.cpp
@@ -0,0 +1,71 @@
+//===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the main function for Clang's TableGen.
+//
+//===----------------------------------------------------------------------===//
+
+#include "LLDBTableGenBackends.h" // Declares all backends.
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Main.h"
+#include "llvm/TableGen/Record.h"
+
+using namespace llvm;
+using namespace lldb_private;
+
+enum ActionType {
+ PrintRecords,
+ DumpJSON,
+ GenOptionDefs,
+};
+
+static cl::opt<ActionType>
+ Action(cl::desc("Action to perform:"),
+ cl::values(clEnumValN(PrintRecords, "print-records",
+ "Print all records to stdout (default)"),
+ clEnumValN(DumpJSON, "dump-json",
+ "Dump all records as machine-readable JSON"),
+ clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
+ "Generate clang attribute clases")));
+
+static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
+ switch (Action) {
+ case PrintRecords:
+ OS << Records; // No argument, dump all contents
+ break;
+ case DumpJSON:
+ EmitJSON(Records, OS);
+ break;
+ case GenOptionDefs:
+ EmitOptionDefs(Records, OS);
+ break;
+ }
+ return false;
+}
+
+int main(int argc, char **argv) {
+ sys::PrintStackTraceOnErrorSignal(argv[0]);
+ PrettyStackTraceProgram X(argc, argv);
+ cl::ParseCommandLineOptions(argc, argv);
+
+ llvm_shutdown_obj Y;
+
+ return TableGenMain(argv[0], &LLDBTableGenMain);
+}
+
+#ifdef __has_feature
+#if __has_feature(address_sanitizer)
+#include <sanitizer/lsan_interface.h>
+// Disable LeakSanitizer for this binary as it has too many leaks that are not
+// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
+int __lsan_is_turned_off() { return 1; }
+#endif // __has_feature(address_sanitizer)
+#endif // defined(__has_feature)
diff --git a/utils/TableGen/LLDBTableGenBackends.h b/utils/TableGen/LLDBTableGenBackends.h
new file mode 100644
index 000000000000..eb14d80c5627
--- /dev/null
+++ b/utils/TableGen/LLDBTableGenBackends.h
@@ -0,0 +1,34 @@
+//===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the declarations for all of the LLDB TableGen
+// backends. A "TableGen backend" is just a function. See
+// "$LLVM_ROOT/utils/TableGen/TableGenBackends.h" for more info.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LLDB_UTILS_TABLEGEN_TABLEGENBACKENDS_H
+#define LLVM_LLDB_UTILS_TABLEGEN_TABLEGENBACKENDS_H
+
+#include <string>
+
+namespace llvm {
+class raw_ostream;
+class RecordKeeper;
+} // namespace llvm
+
+using llvm::raw_ostream;
+using llvm::RecordKeeper;
+
+namespace lldb_private {
+
+void EmitOptionDefs(RecordKeeper &RK, raw_ostream &OS);
+
+} // namespace lldb_private
+
+#endif