[cfe-commits] r90602 - in /cfe/trunk: include/clang/Driver/Options.td lib/Driver/Driver.cpp test/Driver/ccc-add-args.c test/Driver/parsing.c test/Driver/qa_override.c
Daniel Dunbar
daniel at zuster.org
Fri Dec 4 13:55:23 PST 2009
Author: ddunbar
Date: Fri Dec 4 15:55:23 2009
New Revision: 90602
URL: http://llvm.org/viewvc/llvm-project?rev=90602&view=rev
Log:
Driver: Switch -ccc-* options to using the standard options functionality.
- I still want to get rid of them, but manually handling them isn't adding value.
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/ccc-add-args.c
cfe/trunk/test/Driver/parsing.c
cfe/trunk/test/Driver/qa_override.c
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=90602&r1=90601&r2=90602&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Dec 4 15:55:23 2009
@@ -61,6 +61,55 @@
// = => _EQ
// C++ => CXX
+// Developer Driver Options
+
+def ccc_Group : OptionGroup<"<clang internal options>">;
+def ccc_driver_Group : OptionGroup<"<clang driver internal options>">,
+ Group<ccc_Group>, HelpText<"DRIVER OPTIONS">;
+def ccc_debug_Group : OptionGroup<"<clang debug/development internal options>">,
+ Group<ccc_Group>, HelpText<"DEBUG/DEVELOPMENT OPTIONS">;
+
+class CCCDriverOpt : Group<ccc_driver_Group>, Flags<[DriverOption, HelpHidden]>;
+def ccc_cxx : Flag<"-ccc-cxx">, CCCDriverOpt,
+ HelpText<"Act as a C++ driver">;
+def ccc_echo : Flag<"-ccc-echo">, CCCDriverOpt,
+ HelpText<"Echo commands before running them">;
+def ccc_gcc_name : Separate<"-ccc-gcc-name">, CCCDriverOpt,
+ HelpText<"Name for native GCC compiler">,
+ MetaVarName<"<gcc-path>">;
+def ccc_clang_cxx : Flag<"-ccc-clang-cxx">, CCCDriverOpt,
+ HelpText<"Enable the clang compiler for C++">;
+def ccc_no_clang_cxx : Flag<"-ccc-no-clang-cxx">, CCCDriverOpt,
+ HelpText<"Disable the clang compiler for C++">;
+def ccc_no_clang : Flag<"-ccc-no-clang">, CCCDriverOpt,
+ HelpText<"Disable the clang compiler">;
+def ccc_no_clang_cpp : Flag<"-ccc-no-clang-cpp">, CCCDriverOpt,
+ HelpText<"Disable the clang preprocessor">;
+def ccc_clang_archs : Separate<"-ccc-clang-archs">, CCCDriverOpt,
+ HelpText<"Comma separate list of architectures to use the clang compiler for">,
+ MetaVarName<"<arch-list>">;
+def ccc_pch_is_pch : Flag<"-ccc-pch-is-pch">, CCCDriverOpt,
+ HelpText<"Use lazy PCH for precompiled headers">;
+def ccc_pch_is_pth : Flag<"-ccc-pch-is-pth">, CCCDriverOpt,
+ HelpText<"Use pretokenized headers for precompiled headers">;
+
+class CCCDebugOpt : Group<ccc_debug_Group>, Flags<[DriverOption, HelpHidden]>;
+def ccc_host_triple : Separate<"-ccc-host-triple">, CCCDebugOpt,
+ HelpText<"Simulate running on the given target">;
+def ccc_install_dir : Separate<"-ccc-install-dir">, CCCDebugOpt,
+ HelpText<"Simulate installation in the given directory">;
+def ccc_print_options : Flag<"-ccc-print-options">, CCCDebugOpt,
+ HelpText<"Dump parsed command line arguments">;
+def ccc_print_phases : Flag<"-ccc-print-phases">, CCCDebugOpt,
+ HelpText<"Dump list of actions to perform">;
+def ccc_print_bindings : Flag<"-ccc-print-bindings">, CCCDebugOpt,
+ HelpText<"Show bindings of tools to actions">;
+
+// Make sure all other -ccc- options are rejected.
+def ccc_ : Joined<"-ccc-">, Group<ccc_Group>, Flags<[Unsupported]>;
+
+// Standard Options
+
def _HASH_HASH_HASH : Flag<"-###">, Flags<[DriverOption]>,
HelpText<"Print the commands to run for this compilation">;
def A : JoinedOrSeparate<"-A">;
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=90602&r1=90601&r2=90602&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Dec 4 15:55:23 2009
@@ -113,81 +113,53 @@
const char **Start = argv + 1, **End = argv + argc;
const char *HostTriple = DefaultHostTriple.c_str();
- // Read -ccc args.
+ InputArgList *Args = ParseArgStrings(Start, End);
+
+ // Extract -ccc args.
//
// FIXME: We need to figure out where this behavior should live. Most of it
// should be outside in the client; the parts that aren't should have proper
// options, either by introducing new ones or by overloading gcc ones like -V
// or -b.
- for (; Start != End && memcmp(*Start, "-ccc-", 5) == 0; ++Start) {
- const char *Opt = *Start + 5;
-
- if (!strcmp(Opt, "print-options")) {
- CCCPrintOptions = true;
- } else if (!strcmp(Opt, "print-phases")) {
- CCCPrintActions = true;
- } else if (!strcmp(Opt, "print-bindings")) {
- CCCPrintBindings = true;
- } else if (!strcmp(Opt, "cxx")) {
- CCCIsCXX = true;
- } else if (!strcmp(Opt, "echo")) {
- CCCEcho = true;
-
- } else if (!strcmp(Opt, "gcc-name")) {
- assert(Start+1 < End && "FIXME: -ccc- argument handling.");
- CCCGenericGCCName = *++Start;
-
- } else if (!strcmp(Opt, "clang-cxx")) {
- CCCUseClangCXX = true;
- } else if (!strcmp(Opt, "no-clang-cxx")) {
- CCCUseClangCXX = false;
- } else if (!strcmp(Opt, "pch-is-pch")) {
- CCCUsePCH = true;
- } else if (!strcmp(Opt, "pch-is-pth")) {
- CCCUsePCH = false;
- } else if (!strcmp(Opt, "no-clang")) {
- CCCUseClang = false;
- } else if (!strcmp(Opt, "no-clang-cpp")) {
- CCCUseClangCPP = false;
- } else if (!strcmp(Opt, "clang-archs")) {
- assert(Start+1 < End && "FIXME: -ccc- argument handling.");
- llvm::StringRef Cur = *++Start;
-
- CCCClangArchs.clear();
- while (!Cur.empty()) {
- std::pair<llvm::StringRef, llvm::StringRef> Split = Cur.split(',');
-
- if (!Split.first.empty()) {
- llvm::Triple::ArchType Arch =
- llvm::Triple(Split.first, "", "").getArch();
-
- if (Arch == llvm::Triple::UnknownArch) {
- // FIXME: Error handling.
- llvm::errs() << "invalid arch name: " << Split.first << "\n";
- exit(1);
- }
+ CCCPrintOptions = Args->hasArg(options::OPT_ccc_print_options);
+ CCCPrintActions = Args->hasArg(options::OPT_ccc_print_phases);
+ CCCPrintBindings = Args->hasArg(options::OPT_ccc_print_bindings);
+ CCCIsCXX = Args->hasArg(options::OPT_ccc_cxx);
+ CCCEcho = Args->hasArg(options::OPT_ccc_echo);
+ if (const Arg *A = Args->getLastArg(options::OPT_ccc_gcc_name))
+ CCCGenericGCCName = A->getValue(*Args);
+ CCCUseClangCXX = Args->hasFlag(options::OPT_ccc_clang_cxx,
+ options::OPT_ccc_no_clang_cxx);
+ CCCUsePCH = Args->hasFlag(options::OPT_ccc_pch_is_pch,
+ options::OPT_ccc_pch_is_pth);
+ CCCUseClang = !Args->hasArg(options::OPT_ccc_no_clang);
+ CCCUseClangCPP = !Args->hasArg(options::OPT_ccc_no_clang_cpp);
+ if (const Arg *A = Args->getLastArg(options::OPT_ccc_clang_archs)) {
+ llvm::StringRef Cur = A->getValue(*Args);
+
+ CCCClangArchs.clear();
+ while (!Cur.empty()) {
+ std::pair<llvm::StringRef, llvm::StringRef> Split = Cur.split(',');
+
+ if (!Split.first.empty()) {
+ llvm::Triple::ArchType Arch =
+ llvm::Triple(Split.first, "", "").getArch();
- CCCClangArchs.insert(Arch);
+ if (Arch == llvm::Triple::UnknownArch) {
+ Diag(clang::diag::err_drv_invalid_arch_name) << Arch;
+ continue;
}
- Cur = Split.second;
+ CCCClangArchs.insert(Arch);
}
- } else if (!strcmp(Opt, "host-triple")) {
- assert(Start+1 < End && "FIXME: -ccc- argument handling.");
- HostTriple = *++Start;
-
- } else if (!strcmp(Opt, "install-dir")) {
- assert(Start+1 < End && "FIXME: -ccc- argument handling.");
- Dir = *++Start;
- } else {
- // FIXME: Error handling.
- llvm::errs() << "invalid option: " << *Start << "\n";
- exit(1);
+ Cur = Split.second;
}
}
-
- InputArgList *Args = ParseArgStrings(Start, End);
+ if (const Arg *A = Args->getLastArg(options::OPT_ccc_host_triple))
+ HostTriple = A->getValue(*Args);
+ if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
+ Dir = A->getValue(*Args);
Host = GetHostInfo(HostTriple);
@@ -287,112 +259,11 @@
}
}
-static std::string getOptionHelpName(const OptTable &Opts, options::ID Id) {
- std::string Name = Opts.getOptionName(Id);
-
- // Add metavar, if used.
- switch (Opts.getOptionKind(Id)) {
- case Option::GroupClass: case Option::InputClass: case Option::UnknownClass:
- assert(0 && "Invalid option with help text.");
-
- case Option::MultiArgClass: case Option::JoinedAndSeparateClass:
- assert(0 && "Cannot print metavar for this kind of option.");
-
- case Option::FlagClass:
- break;
-
- case Option::SeparateClass: case Option::JoinedOrSeparateClass:
- Name += ' ';
- // FALLTHROUGH
- case Option::JoinedClass: case Option::CommaJoinedClass:
- Name += Opts.getOptionMetaVar(Id);
- break;
- }
-
- return Name;
-}
-
// FIXME: Move -ccc options to real options in the .td file (or eliminate), and
// then move to using OptTable::PrintHelp.
void Driver::PrintHelp(bool ShowHidden) const {
- llvm::raw_ostream &OS = llvm::outs();
-
- OS << "OVERVIEW: clang \"gcc-compatible\" driver\n";
- OS << '\n';
- OS << "USAGE: " << Name << " [options] <input files>\n";
- OS << '\n';
- OS << "OPTIONS:\n";
-
- // Render help text into (option, help) pairs.
- std::vector< std::pair<std::string, const char*> > OptionHelp;
-
- for (unsigned i = 0, e = getOpts().getNumOptions(); i != e; ++i) {
- options::ID Id = (options::ID) (i + 1);
- if (const char *Text = getOpts().getOptionHelpText(Id))
- OptionHelp.push_back(std::make_pair(getOptionHelpName(getOpts(), Id),
- Text));
- }
-
- if (ShowHidden) {
- OptionHelp.push_back(std::make_pair("\nDRIVER OPTIONS:",""));
- OptionHelp.push_back(std::make_pair("-ccc-cxx",
- "Act as a C++ driver"));
- OptionHelp.push_back(std::make_pair("-ccc-gcc-name",
- "Name for native GCC compiler"));
- OptionHelp.push_back(std::make_pair("-ccc-clang-cxx",
- "Enable the clang compiler for C++"));
- OptionHelp.push_back(std::make_pair("-ccc-no-clang-cxx",
- "Disable the clang compiler for C++"));
- OptionHelp.push_back(std::make_pair("-ccc-no-clang",
- "Disable the clang compiler"));
- OptionHelp.push_back(std::make_pair("-ccc-no-clang-cpp",
- "Disable the clang preprocessor"));
- OptionHelp.push_back(std::make_pair("-ccc-clang-archs",
- "Comma separate list of architectures "
- "to use the clang compiler for"));
- OptionHelp.push_back(std::make_pair("-ccc-pch-is-pch",
- "Use lazy PCH for precompiled headers"));
- OptionHelp.push_back(std::make_pair("-ccc-pch-is-pth",
- "Use pretokenized headers for precompiled headers"));
-
- OptionHelp.push_back(std::make_pair("\nDEBUG/DEVELOPMENT OPTIONS:",""));
- OptionHelp.push_back(std::make_pair("-ccc-host-triple",
- "Simulate running on the given target"));
- OptionHelp.push_back(std::make_pair("-ccc-install-dir",
- "Simulate installation in the given directory"));
- OptionHelp.push_back(std::make_pair("-ccc-print-options",
- "Dump parsed command line arguments"));
- OptionHelp.push_back(std::make_pair("-ccc-print-phases",
- "Dump list of actions to perform"));
- OptionHelp.push_back(std::make_pair("-ccc-print-bindings",
- "Show bindings of tools to actions"));
- OptionHelp.push_back(std::make_pair("CCC_ADD_ARGS",
- "(ENVIRONMENT VARIABLE) Comma separated list of "
- "arguments to prepend to the command line"));
- }
-
- // Find the maximum option length.
- unsigned OptionFieldWidth = 0;
- for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
- // Skip titles.
- if (!OptionHelp[i].second)
- continue;
-
- // Limit the amount of padding we are willing to give up for alignment.
- unsigned Length = OptionHelp[i].first.size();
- if (Length <= 23)
- OptionFieldWidth = std::max(OptionFieldWidth, Length);
- }
-
- for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
- const std::string &Option = OptionHelp[i].first;
- OS << " " << Option;
- for (int j = Option.length(), e = OptionFieldWidth; j < e; ++j)
- OS << ' ';
- OS << ' ' << OptionHelp[i].second << '\n';
- }
-
- OS.flush();
+ getOpts().PrintHelp(llvm::outs(), Name.c_str(),
+ "clang \"gcc-compatible\" driver", ShowHidden);
}
void Driver::PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const {
Modified: cfe/trunk/test/Driver/ccc-add-args.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ccc-add-args.c?rev=90602&r1=90601&r2=90602&view=diff
==============================================================================
--- cfe/trunk/test/Driver/ccc-add-args.c (original)
+++ cfe/trunk/test/Driver/ccc-add-args.c Fri Dec 4 15:55:23 2009
@@ -1,3 +1,5 @@
// RUN: env CCC_ADD_ARGS="-ccc-echo,-ccc-print-options,,-v" clang -### 2>&1 | FileCheck %s
-// CHECK: Option 0 - Name: "-v", Values: {}
-// CHECK: Option 1 - Name: "-###", Values: {}
+// CHECK: Option 0 - Name: "-ccc-echo", Values: {}
+// CHECK: Option 1 - Name: "-ccc-print-options", Values: {}
+// CHECK: Option 2 - Name: "-v", Values: {}
+// CHECK: Option 3 - Name: "-###", Values: {}
Modified: cfe/trunk/test/Driver/parsing.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/parsing.c?rev=90602&r1=90601&r2=90602&view=diff
==============================================================================
--- cfe/trunk/test/Driver/parsing.c (original)
+++ cfe/trunk/test/Driver/parsing.c Fri Dec 4 15:55:23 2009
@@ -1,14 +1,15 @@
// RUN: clang -ccc-print-options input -Yunknown -m32 -arch ppc -djoined -A separate -Ajoined -Wp,one,two -Xarch_joined AndSeparate -sectalign 1 2 3 2> %t
-// RUN: grep 'Option 0 - Name: "<input>", Values: {"input"}' %t
-// RUN: grep 'Option 1 - Name: "<unknown>", Values: {"-Yunknown"}' %t
-// RUN: grep 'Option 2 - Name: "-m32", Values: {}' %t
-// RUN: grep 'Option 3 - Name: "-arch", Values: {"ppc"}' %t
-// RUN: grep 'Option 4 - Name: "-d", Values: {"joined"}' %t
-// RUN: grep 'Option 5 - Name: "-A", Values: {"separate"}' %t
-// RUN: grep 'Option 6 - Name: "-A", Values: {"joined"}' %t
-// RUN: grep 'Option 7 - Name: "-Wp,", Values: {"one", "two"}' %t
-// RUN: grep 'Option 8 - Name: "-Xarch_", Values: {"joined", "AndSeparate"}' %t
-// RUN: grep 'Option 9 - Name: "-sectalign", Values: {"1", "2", "3"}' %t
+// RUN: grep 'Option 0 - Name: "-ccc-print-options", Values: {}' %t
+// RUN: grep 'Option 1 - Name: "<input>", Values: {"input"}' %t
+// RUN: grep 'Option 2 - Name: "<unknown>", Values: {"-Yunknown"}' %t
+// RUN: grep 'Option 3 - Name: "-m32", Values: {}' %t
+// RUN: grep 'Option 4 - Name: "-arch", Values: {"ppc"}' %t
+// RUN: grep 'Option 5 - Name: "-d", Values: {"joined"}' %t
+// RUN: grep 'Option 6 - Name: "-A", Values: {"separate"}' %t
+// RUN: grep 'Option 7 - Name: "-A", Values: {"joined"}' %t
+// RUN: grep 'Option 8 - Name: "-Wp,", Values: {"one", "two"}' %t
+// RUN: grep 'Option 9 - Name: "-Xarch_", Values: {"joined", "AndSeparate"}' %t
+// RUN: grep 'Option 10 - Name: "-sectalign", Values: {"1", "2", "3"}' %t
// RUN: not clang -V 2> %t
// RUN: grep "error: argument to '-V' is missing (expected 1 value)" %t
@@ -17,7 +18,8 @@
// Verify that search continues after find the first option.
// RUN: clang -ccc-print-options -Wally 2> %t
-// RUN: grep 'Option 0 - Name: "-W", Values: {"ally"}' %t
+// RUN: grep 'Option 0 - Name: "-ccc-print-options", Values: {}' %t
+// RUN: grep 'Option 1 - Name: "-W", Values: {"ally"}' %t
Modified: cfe/trunk/test/Driver/qa_override.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/qa_override.c?rev=90602&r1=90601&r2=90602&view=diff
==============================================================================
--- cfe/trunk/test/Driver/qa_override.c (original)
+++ cfe/trunk/test/Driver/qa_override.c Fri Dec 4 15:55:23 2009
@@ -1,5 +1,6 @@
// RUN: env QA_OVERRIDE_GCC3_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa Omagic ^-ccc-print-options " clang x -O2 b -O3 2>&1 | FileCheck %s
// CHECK-NOT: ###
-// CHECK: Option 0 - Name: "<input>", Values: {"x"}
-// CHECK-NEXT: Option 1 - Name: "-O", Values: {"ignore"}
-// CHECK-NEXT: Option 2 - Name: "-O", Values: {"magic"}
+// CHECK: Option 0 - Name: "-ccc-print-options", Values: {}
+// CHECK-NEXT: Option 1 - Name: "<input>", Values: {"x"}
+// CHECK-NEXT: Option 2 - Name: "-O", Values: {"ignore"}
+// CHECK-NEXT: Option 3 - Name: "-O", Values: {"magic"}
More information about the cfe-commits
mailing list