[frontend] Began splitting options in CompilerInvocation into separate classes.

Added a new FrontendOptions class, which will eventually contain the options for controlling the behavior of the frontend. (This is similar to Clang’s FrontendOptions class.)
Moved InputFilenames, OutputFilename, ModuleName, and SerializedDiagnosticsPath from CompilerInvocation into FrontendOptions.
Split out argument parsing for options in FrontendOptions into a separate ParseFrontendArgs static function.

Swift SVN r11155
This commit is contained in:
Connor Wakamo
2013-12-11 23:58:55 +00:00
parent 0e81e109b2
commit 59c07ab012
3 changed files with 77 additions and 32 deletions

View File

@@ -20,6 +20,8 @@
#include "llvm/Support/Path.h"
using namespace swift;
using namespace swift::driver;
using namespace llvm::opt;
swift::CompilerInvocation::CompilerInvocation() {
TargetTriple = llvm::sys::getDefaultTargetTriple();
@@ -33,9 +35,32 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
setRuntimeIncludePath(LibPath.str());
}
static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
DiagnosticEngine &Diags) {
using namespace options;
if (const Arg *A = Args.getLastArg(OPT_o)) {
Opts.OutputFilename = A->getValue();
}
if (const Arg *A = Args.getLastArg(OPT_module_name)) {
Opts.ModuleName = A->getValue();
}
if (const Arg *A = Args.getLastArg(OPT_serialize_diagnostics)) {
Opts.SerializedDiagnosticsPath = A->getValue();
}
for (const Arg *A : make_range(Args.filtered_begin(OPT_INPUT),
Args.filtered_end())) {
Opts.InputFilenames.push_back(A->getValue());
}
return false;
}
bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
DiagnosticEngine &Diags) {
using namespace driver;
using namespace driver::options;
if (Args.empty())
@@ -55,6 +80,10 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
return true;
}
if (ParseFrontendArgs(FrontendOpts, *ParsedArgs, Diags)) {
return true;
}
bool HasUnknownArgument = false;
for (auto InputArg : *ParsedArgs) {
@@ -71,10 +100,6 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
FrameworkSearchPaths.push_back(InputArg->getValue());
break;
case OPT_module_name:
setModuleName(InputArg->getValue());
break;
case OPT_sdk:
setSDKPath(InputArg->getValue());
break;
@@ -107,22 +132,10 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
addLinkLibrary(InputArg->getValue(), LibraryKind::Framework);
break;
case OPT_serialize_diagnostics:
setSerializedDiagnosticsPath(InputArg->getValue());
break;
case OPT_module_source_list:
setModuleSourceListPath(InputArg->getValue());
break;
case OPT_o:
setOutputFilename(InputArg->getValue());
break;
case OPT_INPUT:
addInputFilename(InputArg->getValue());
break;
case OPT_UNKNOWN:
HasUnknownArgument = true;
Diags.diagnose(SourceLoc(), diag::error_unknown_arg,