Skip to content

Commit 929fccd

Browse files
committed
[Options] Add prefixes to options.
Each option has a set of prefixes. When matching an argument such as -funroll-loops. First the leading - is removed as it is a prefix. Then a lower_bound search for "funroll-loops" is done against the option table by option name. From there each option prefix + option name combination is tested against the argument. This allows us to support Microsoft style options where both / and - are valid prefixes. It also simplifies the cases we already have where options come in both - and -- forms. Almost every option for gnu-ld happens to have this form. llvm-svn: 166444
1 parent dbeb0f0 commit 929fccd

19 files changed

+1297
-1120
lines changed

clang/include/clang/Driver/Arg.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ namespace driver {
4545
/// argument translation), if any.
4646
const Arg *BaseArg;
4747

48+
/// \brief How this instance of the option was spelled.
49+
StringRef Spelling;
50+
4851
/// \brief The index at which this argument appears in the containing
4952
/// ArgList.
5053
unsigned Index;
@@ -61,14 +64,16 @@ namespace driver {
6164
SmallVector<const char *, 2> Values;
6265

6366
public:
64-
Arg(const Option Opt, unsigned Index, const Arg *BaseArg = 0);
65-
Arg(const Option Opt, unsigned Index,
67+
Arg(const Option Opt, StringRef Spelling, unsigned Index,
68+
const Arg *BaseArg = 0);
69+
Arg(const Option Opt, StringRef Spelling, unsigned Index,
6670
const char *Value0, const Arg *BaseArg = 0);
67-
Arg(const Option Opt, unsigned Index,
71+
Arg(const Option Opt, StringRef Spelling, unsigned Index,
6872
const char *Value0, const char *Value1, const Arg *BaseArg = 0);
6973
~Arg();
7074

7175
const Option getOption() const { return Opt; }
76+
StringRef getSpelling() const { return Spelling; }
7277
unsigned getIndex() const { return Index; }
7378

7479
/// \brief Return the base argument which generated this arg.

clang/include/clang/Driver/CC1AsOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ namespace driver {
1717
namespace cc1asoptions {
1818
enum ID {
1919
OPT_INVALID = 0, // This is not an option ID.
20-
#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
20+
#define PREFIX(NAME, VALUE)
21+
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
2122
HELPTEXT, METAVAR) OPT_##ID,
2223
#include "clang/Driver/CC1AsOptions.inc"
2324
LastOption
2425
#undef OPTION
26+
#undef PREFIX
2527
};
2628
}
2729

clang/include/clang/Driver/CC1AsOptions.td

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ include "OptParser.td"
1818
// Target Options
1919
//===----------------------------------------------------------------------===//
2020

21-
def triple : Separate<"-triple">,
21+
def triple : Separate<["-"], "triple">,
2222
HelpText<"Specify target triple (e.g. x86_64-pc-linux-gnu)">;
23-
def target_cpu : Separate<"-target-cpu">,
23+
def target_cpu : Separate<["-"], "target-cpu">,
2424
HelpText<"Target a specific cpu type">;
25-
def target_feature : Separate<"-target-feature">,
25+
def target_feature : Separate<["-"], "target-feature">,
2626
HelpText<"Target specific attributes">;
2727

2828
//===----------------------------------------------------------------------===//
2929
// Language Options
3030
//===----------------------------------------------------------------------===//
3131

32-
def I : JoinedOrSeparate<"-I">, MetaVarName<"<directory>">,
32+
def I : JoinedOrSeparate<["-"], "I">, MetaVarName<"<directory>">,
3333
HelpText<"Add directory to include search path">;
34-
def n : Flag<"-n">,
34+
def n : Flag<["-"], "n">,
3535
HelpText<"Don't automatically start assembly file with a text section">;
36-
def L : Flag<"-L">,
36+
def L : Flag<["-"], "L">,
3737
HelpText<"Save temporary labels in the symbol table. "
3838
"Note this may change .s semantics, it should almost never be used "
3939
"on compiler generated code!">;
@@ -42,50 +42,49 @@ def L : Flag<"-L">,
4242
// Frontend Options
4343
//===----------------------------------------------------------------------===//
4444

45-
def o : Separate<"-o">, MetaVarName<"<path>">, HelpText<"Specify output file">;
45+
def o : Separate<["-"], "o">, MetaVarName<"<path>">,
46+
HelpText<"Specify output file">;
4647

47-
def filetype : Separate<"-filetype">,
48+
def filetype : Separate<["-"], "filetype">,
4849
HelpText<"Specify the output file type ('asm', 'null', or 'obj')">;
4950

50-
def help : Flag<"-help">,
51+
def help : Flag<["-", "--"], "-help">,
5152
HelpText<"Print this help text">;
52-
def _help : Flag<"--help">, Alias<help>;
5353

54-
def version : Flag<"-version">,
54+
def version : Flag<["-", "--"], "version">,
5555
HelpText<"Print the assembler version">;
56-
def _version : Flag<"--version">, Alias<version>;
57-
def v : Flag<"-v">, Alias<version>;
56+
def v : Flag<["-"], "v">, Alias<version>;
5857

5958
// Generic forwarding to LLVM options. This should only be used for debugging
6059
// and experimental features.
61-
def mllvm : Separate<"-mllvm">,
60+
def mllvm : Separate<["-"], "mllvm">,
6261
HelpText<"Additional arguments to forward to LLVM's option processing">;
6362

6463
//===----------------------------------------------------------------------===//
6564
// Transliterate Options
6665
//===----------------------------------------------------------------------===//
6766

68-
def output_asm_variant : Separate<"-output-asm-variant">,
67+
def output_asm_variant : Separate<["-"], "output-asm-variant">,
6968
HelpText<"Select the asm variant index to use for output">;
70-
def show_encoding : Flag<"-show-encoding">,
69+
def show_encoding : Flag<["-"], "show-encoding">,
7170
HelpText<"Show instruction encoding information in transliterate mode">;
72-
def show_inst : Flag<"-show-inst">,
71+
def show_inst : Flag<["-"], "show-inst">,
7372
HelpText<"Show internal instruction representation in transliterate mode">;
7473

7574
//===----------------------------------------------------------------------===//
7675
// Assemble Options
7776
//===----------------------------------------------------------------------===//
7877

79-
def relax_all : Flag<"-relax-all">,
78+
def relax_all : Flag<["-"], "relax-all">,
8079
HelpText<"Relax all fixups (for performance testing)">;
8180

82-
def no_exec_stack : Flag<"--noexecstack">,
81+
def no_exec_stack : Flag<["-"], "-noexecstack">,
8382
HelpText<"Mark the file as not needing an executable stack">;
8483

85-
def fatal_warnings : Flag<"--fatal-warnings">,
84+
def fatal_warnings : Flag<["--"], "fatal-warnings">,
8685
HelpText<"Consider warnings as errors">;
8786

88-
def g : Flag<"-g">, HelpText<"Generate source level debug information">;
87+
def g : Flag<["-"], "g">, HelpText<"Generate source level debug information">;
8988

90-
def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,
89+
def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
9190
HelpText<"The string to embed in the Dwarf debug flags record.">;

0 commit comments

Comments
 (0)