From c917ab56f37bbd0e8cc16f490245f8e325b36c0b Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Tue, 6 Feb 2024 14:52:32 +0100 Subject: [PATCH] Add TableGen-based generator for command line arguments Upstream moved away from manually declaring `*def` and `*inc` files. These are now auto-generated with tablegen. This patch does the same for cling, making it easier to rebase and maintain. --- CMakeLists.txt | 1 + include/cling/Interpreter/CMakeLists.txt | 5 +++ include/cling/Interpreter/ClingOptions.inc | 49 ---------------------- include/cling/Interpreter/ClingOptions.td | 29 +++++++++++++ lib/Interpreter/CMakeLists.txt | 4 +- 5 files changed, 37 insertions(+), 51 deletions(-) create mode 100644 include/cling/Interpreter/CMakeLists.txt delete mode 100644 include/cling/Interpreter/ClingOptions.inc create mode 100644 include/cling/Interpreter/ClingOptions.td diff --git a/CMakeLists.txt b/CMakeLists.txt index 34e0c65c..9775b07f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,6 +546,7 @@ if (TARGET clang-headers) list(APPEND LLVM_COMMON_DEPENDS clang-headers) endif() +add_subdirectory(include/cling/Interpreter) add_subdirectory(lib) if( CLING_INCLUDE_TESTS ) diff --git a/include/cling/Interpreter/CMakeLists.txt b/include/cling/Interpreter/CMakeLists.txt new file mode 100644 index 00000000..59821499 --- /dev/null +++ b/include/cling/Interpreter/CMakeLists.txt @@ -0,0 +1,5 @@ +include_directories(${LLVM_INCLUDE_DIRS}) + +set(LLVM_TARGET_DEFINITIONS ClingOptions.td) +tablegen(LLVM ClingOptions.inc -gen-opt-parser-defs) +add_public_tablegen_target(ClingDriverOptions) diff --git a/include/cling/Interpreter/ClingOptions.inc b/include/cling/Interpreter/ClingOptions.inc deleted file mode 100644 index c630759e..00000000 --- a/include/cling/Interpreter/ClingOptions.inc +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef PREFIX -#error "Define PREFIX prior to including this file!" -#endif - -///////// -// Prefixes - -#define COMMA , -PREFIX(prefix_0, {llvm::StringLiteral("")}) -PREFIX(prefix_1, {llvm::StringLiteral("-") COMMA llvm::StringLiteral("")}) -PREFIX(prefix_3, {llvm::StringLiteral("-") COMMA llvm::StringLiteral("--") COMMA llvm::StringLiteral("")}) -PREFIX(prefix_2, {llvm::StringLiteral("--") COMMA llvm::StringLiteral("")}) -#undef COMMA - -#ifndef OPTION -#error "Define OPTION prior to including this file!" -#endif - -OPTION(prefix_0, "", INPUT, Input, INVALID, INVALID, 0, 0, 0, 0, 0, 0) -OPTION(prefix_0, "", UNKNOWN, Unknown, INVALID, INVALID, 0, 0, 0, 0, 0, 0) -#ifndef NDEBUG -OPTION(prefix_2, "debug-only=", _debugFlags_EQ, Joined, INVALID, INVALID, 0, 0, 0, - "Debug flags to enable", 0, 0) -OPTION(prefix_2, "debug-only", _debugFlags, Separate, INVALID, INVALID, 0, 0, 0, - "Debug flags to enable", 0, 0) -#endif -OPTION(prefix_2, "errorout", _errorout, Flag, INVALID, INVALID, 0, 0, 0, - "Do not recover from input errors", 0, 0) -// Re-implement to forward to our help -OPTION(prefix_3, "help", help, Flag, INVALID, INVALID, 0, 0, 0, - "Print this help text", 0, 0) -OPTION(prefix_1, "L", L, JoinedOrSeparate, INVALID, INVALID, 0, 0, 0, - "Add directory to library search path", "", 0) -OPTION(prefix_1, "l", l, JoinedOrSeparate, INVALID, INVALID, 0, 0, 0, - "Load a library before prompt", "", 0) -OPTION(prefix_2, "metastr=", _metastr_EQ, Joined, INVALID, INVALID, 0, 0, 0, - "Set the meta command tag, default '.'", 0, 0) -OPTION(prefix_2, "metastr", _metastr, Separate, INVALID, INVALID, 0, 0, 0, - "Set the meta command tag, default '.'", 0, 0) -OPTION(prefix_2, "nologo", _nologo, Flag, INVALID, INVALID, 0, 0, 0, - "Do not show startup-banner", 0, 0) -OPTION(prefix_3, "noruntime", noruntime, Flag, INVALID, INVALID, 0, 0, 0, - "Disable runtime support (no null checking, no value printing)", 0, 0) -OPTION(prefix_2, "ptrcheck", _ptrcheck, Flag, INVALID, INVALID, 0, 0, 0, - "Enable injection of pointer validity checks", 0, 0) -OPTION(prefix_3, "version", version, Flag, INVALID, INVALID, 0, 0, 0, - "Print the compiler version", 0, 0) -OPTION(prefix_1, "v", v, Flag, INVALID, INVALID, 0, 0, 0, - "Enable verbose output", 0, 0) diff --git a/include/cling/Interpreter/ClingOptions.td b/include/cling/Interpreter/ClingOptions.td new file mode 100644 index 00000000..69b34aba --- /dev/null +++ b/include/cling/Interpreter/ClingOptions.td @@ -0,0 +1,29 @@ +//===--- ClingOptions.td - Options for cling -----------------------------------===// +// +// CLING - the C++ LLVM-based InterpreterG :) +// +//===----------------------------------------------------------------------===// +// +// This file defines the options accepted by cling. +// +//===----------------------------------------------------------------------===// + +// Include the common option parsing interfaces. +include "llvm/Option/OptParser.td" + +#ifndef NDEBUG +def _debugFlags_EQ : Joined<["--"], "debug-only=">; +def _debugFlags : Flag<["--"], "debug-only">; +#endif +def _errorout : Flag<["--"], "errorout">, HelpText<"Do not recover from input errors">; +// Re-implement to forward to our help +def help : Flag<["-", "--"], "help">, HelpText<"Print this help text">; +def L : JoinedOrSeparate<["-"], "L">, HelpText<"Add directory to library search path">, MetaVarName<"">; +def l : JoinedOrSeparate<["-"], "l">, HelpText<"Load a library before prompt">, MetaVarName<"">; +def _metastr_EQ : Joined<["--"], "metastr=">, HelpText<"Set the meta command tag, default '.'">; +def _metastr : Separate<["--"], "metastr">, HelpText<"Set the meta command tag, default '.'">; +def _nologo : Flag<["--"], "nologo">, HelpText<"Do not show startup-banner">; +def noruntime : Flag<["-", "--"], "noruntime">, HelpText<"Disable runtime support (no null checking, no value printing)">; +def _ptrcheck : Flag<["--"], "ptrcheck">, HelpText<"Enable injection of pointer validity checks">; +def version : Flag<["-", "--"], "version">, HelpText<"Print the compiler version">; +def v : Flag<["-"], "v">, HelpText<"Enable verbose output">; diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 87e83535..e397da97 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -47,9 +47,9 @@ set(LLVM_LINK_COMPONENTS # clingInterpreter depends on Options.inc to be tablegen-ed # (target ClangDriverOptions) from in-tree builds. -set(CLING_DEPENDS) +set(CLING_DEPENDS ClingDriverOptions) if(TARGET ClangDriverOptions) - set(CLING_DEPENDS ClangDriverOptions) + set(CLING_DEPENDS "${CLING_DEPENDS};ClangDriverOptions") endif() # clangSema will make sure all of the dependencies of clingInterpreter are met. if(TARGET clangSema)