diff --git a/clang/include/clang/CMakeLists.txt b/clang/include/clang/CMakeLists.txt index 39e3698a1655..61d2bf602d9a 100644 --- a/clang/include/clang/CMakeLists.txt +++ b/clang/include/clang/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(Basic) +add_subdirectory(Driver) diff --git a/clang/include/clang/Driver/CMakeLists.txt b/clang/include/clang/Driver/CMakeLists.txt new file mode 100644 index 000000000000..18b291c3712f --- /dev/null +++ b/clang/include/clang/Driver/CMakeLists.txt @@ -0,0 +1,5 @@ +set(LLVM_TARGET_DEFINITIONS Options.td) +tablegen(Options.inc + -gen-opt-parser-defs) +add_custom_target(ClangDriverOptions + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Options.inc) diff --git a/clang/include/clang/Driver/Makefile b/clang/include/clang/Driver/Makefile new file mode 100644 index 000000000000..d263fbe5c291 --- /dev/null +++ b/clang/include/clang/Driver/Makefile @@ -0,0 +1,12 @@ +LEVEL = ../../../../.. +BUILT_SOURCES = Options.inc + +TABLEGEN_INC_FILES_COMMON = 1 + +include $(LEVEL)/Makefile.common + +$(ObjDir)/Options.inc.tmp : Options.td OptParser.td $(ObjDir)/.dir + $(Echo) "Building Clang Driver Option tables with tblgen" + $(Verb) $(TableGen) -gen-opt-parser-defs -o $(call SYSPATH, $@) $< + + diff --git a/clang/include/clang/Driver/OptParser.td b/clang/include/clang/Driver/OptParser.td new file mode 100644 index 000000000000..70b59c69c264 --- /dev/null +++ b/clang/include/clang/Driver/OptParser.td @@ -0,0 +1,116 @@ +//===--- OptParser.td - Common Option Parsing Interfaces ------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the common interfaces used by the option parsing TableGen +// backend. +// +//===----------------------------------------------------------------------===// + +// Define the kinds of options. + +class OptionKind { + string Name = name; + // The kind precedence, kinds with lower precedence are matched first. + int Precedence = predecence; +} + +// An option group. +def KIND_GROUP : OptionKind<"Group">; +// A flag with no values. +def KIND_FLAG : OptionKind<"Flag">; +// An option which prefixes its (single) value. +def KIND_JOINED : OptionKind<"Joined", 1>; +// An option which is followed by its value. +def KIND_SEPARATE : OptionKind<"Separate">; +// An option followed by its values, which are separated by commas. +def KIND_COMMAJOINED : OptionKind<"CommaJoined">; +// An option which is which takes multiple (separate) arguments. +def KIND_MULTIARG : OptionKind<"MultiArg">; +// An option which is either joined to its (non-empty) value, or followed by its +// value. +def KIND_JOINED_OR_SEPARATE : OptionKind<"JoinedOrSeparate">; +// An option which is both joined to its (first) value, and followed by its +// (second) value. +def KIND_JOINED_AND_SEPARATE : OptionKind<"JoinedAndSeparate">; + +// Define the option flags. + +class OptionFlag {} + +// DriverOption - The option is a "driver" option, and should not be forwarded +// to gcc. +def DriverOption : OptionFlag; + +// LinkerInput - The option is a linker input. +def LinkerInput : OptionFlag; + +// NoArgumentUnused - Don't report argument unused warnings for this option; this +// is useful for options like -static or -dynamic which a user may always end up +// passing, even if the platform defaults to (or only supports) that option. +def NoArgumentUnused : OptionFlag; + +// RenderAsInput - The option should not render the name when rendered as an +// input (i.e., the option is rendered as values). +def RenderAsInput : OptionFlag; + +// RenderJoined - The option should be rendered joined, even if separate (only +// sensible on single value separate options). +def RenderJoined : OptionFlag; + +// RenderSeparate - The option should be rendered separately, even if joined +// (only sensible on joined options). +def RenderSeparate : OptionFlag; + +// Unsupported - The option is unsupported, and the driver will reject command +// lines that use it. +def Unsupported : OptionFlag; + +// Define the option group class. + +class OptionGroup { + string EnumName = ?; // Uses the def name if undefined. + string Name = name; + OptionGroup Group = ?; +} + +// Define the option class. + +class Option { + string EnumName = ?; // Uses the def name if undefined. + string Name = name; + OptionKind Kind = kind; + // Used by MultiArg option kind. + int NumArgs = 0; + string HelpText = ?; + string MetaVarName = ?; + list Flags = []; + OptionGroup Group = ?; + Option Alias = ?; +} + +// Helpers for defining options. + +class Flag : Option; +class Joined : Option; +class Separate : Option; +class CommaJoined : Option; +class MultiArg : Option { + int NumArgs = numargs; +} +class JoinedOrSeparate : Option; +class JoinedAndSeparate : Option; + +// Mix-ins for adding optional attributes. + +class Alias