Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
flang/lib/Frontend/CompilerInvocation.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
// Tweak the frontend configuration based on the frontend action | // Tweak the frontend configuration based on the frontend action | ||||
static void setUpFrontendBasedOnAction(FrontendOptions &opts) { | static void setUpFrontendBasedOnAction(FrontendOptions &opts) { | ||||
assert(opts.programAction_ != Fortran::frontend::InvalidAction && | assert(opts.programAction_ != Fortran::frontend::InvalidAction && | ||||
"Fortran frontend action not set!"); | "Fortran frontend action not set!"); | ||||
if (opts.programAction_ == DebugDumpParsingLog) | if (opts.programAction_ == DebugDumpParsingLog) | ||||
opts.instrumentedParse_ = true; | opts.instrumentedParse_ = true; | ||||
if (opts.programAction_ == DebugDumpProvenance) | if (opts.programAction_ == DebugDumpProvenance || | ||||
opts.programAction_ == Fortran::frontend::GetDefinition) | |||||
opts.needProvenanceRangeToCharBlockMappings_ = true; | opts.needProvenanceRangeToCharBlockMappings_ = true; | ||||
} | } | ||||
static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args, | static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args, | ||||
clang::DiagnosticsEngine &diags) { | clang::DiagnosticsEngine &diags) { | ||||
unsigned numErrorsBefore = diags.getNumErrors(); | |||||
// By default the frontend driver creates a ParseSyntaxOnly action. | // By default the frontend driver creates a ParseSyntaxOnly action. | ||||
opts.programAction_ = ParseSyntaxOnly; | opts.programAction_ = ParseSyntaxOnly; | ||||
// Identify the action (i.e. opts.ProgramAction) | // Identify the action (i.e. opts.ProgramAction) | ||||
if (const llvm::opt::Arg *a = | if (const llvm::opt::Arg *a = | ||||
args.getLastArg(clang::driver::options::OPT_Action_Group)) { | args.getLastArg(clang::driver::options::OPT_Action_Group)) { | ||||
switch (a->getOption().getID()) { | switch (a->getOption().getID()) { | ||||
Show All 40 Lines | case clang::driver::options::OPT_fdebug_measure_parse_tree: | ||||
opts.programAction_ = DebugMeasureParseTree; | opts.programAction_ = DebugMeasureParseTree; | ||||
break; | break; | ||||
case clang::driver::options::OPT_fdebug_pre_fir_tree: | case clang::driver::options::OPT_fdebug_pre_fir_tree: | ||||
opts.programAction_ = DebugPreFIRTree; | opts.programAction_ = DebugPreFIRTree; | ||||
break; | break; | ||||
case clang::driver::options::OPT_fget_symbols_sources: | case clang::driver::options::OPT_fget_symbols_sources: | ||||
opts.programAction_ = GetSymbolsSources; | opts.programAction_ = GetSymbolsSources; | ||||
break; | break; | ||||
case clang::driver::options::OPT_fget_definition: | |||||
opts.programAction_ = GetDefinition; | |||||
break; | |||||
// TODO: | // TODO: | ||||
// case calng::driver::options::OPT_emit_llvm: | // case calng::driver::options::OPT_emit_llvm: | ||||
// case clang::driver::options::OPT_emit_llvm_only: | // case clang::driver::options::OPT_emit_llvm_only: | ||||
// case clang::driver::options::OPT_emit_codegen_only: | // case clang::driver::options::OPT_emit_codegen_only: | ||||
// case clang::driver::options::OPT_emit_module: | // case clang::driver::options::OPT_emit_module: | ||||
// (...) | // (...) | ||||
} | } | ||||
// Parse the values provided with `-fget-definition` (there should be 3 | |||||
// integers) | |||||
if (llvm::opt::OptSpecifier(a->getOption().getID()) == | |||||
clang::driver::options::OPT_fget_definition) { | |||||
unsigned optVals[3] = {0, 0, 0}; | |||||
for (unsigned i = 0; i < 3; i++) { | |||||
llvm::StringRef val = a->getValue(i); | |||||
if (val.getAsInteger(10, optVals[i])) { | |||||
// A non-integer was encountered - that's an error. | |||||
diags.Report(clang::diag::err_drv_invalid_value) | |||||
<< a->getOption().getName() << val; | |||||
break; | |||||
} | |||||
} | |||||
opts.getDefVals_.line = optVals[0]; | |||||
opts.getDefVals_.startColumn = optVals[1]; | |||||
opts.getDefVals_.endColumn = optVals[2]; | |||||
} | |||||
} | } | ||||
opts.outputFile_ = args.getLastArgValue(clang::driver::options::OPT_o); | opts.outputFile_ = args.getLastArgValue(clang::driver::options::OPT_o); | ||||
opts.showHelp_ = args.hasArg(clang::driver::options::OPT_help); | opts.showHelp_ = args.hasArg(clang::driver::options::OPT_help); | ||||
opts.showVersion_ = args.hasArg(clang::driver::options::OPT_version); | opts.showVersion_ = args.hasArg(clang::driver::options::OPT_version); | ||||
// Get the input kind (from the value passed via `-x`) | // Get the input kind (from the value passed via `-x`) | ||||
InputKind dashX(Language::Unknown); | InputKind dashX(Language::Unknown); | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | if (const llvm::opt::Arg *arg = | ||||
} else { | } else { | ||||
diags.Report(clang::diag::err_drv_invalid_value) | diags.Report(clang::diag::err_drv_invalid_value) | ||||
<< arg->getAsString(args) << argValue; | << arg->getAsString(args) << argValue; | ||||
} | } | ||||
} | } | ||||
setUpFrontendBasedOnAction(opts); | setUpFrontendBasedOnAction(opts); | ||||
opts.dashX_ = dashX; | opts.dashX_ = dashX; | ||||
return diags.getNumErrors() == numErrorsBefore; | |||||
} | } | ||||
// Generate the path to look for intrinsic modules | // Generate the path to look for intrinsic modules | ||||
static std::string getIntrinsicDir() { | static std::string getIntrinsicDir() { | ||||
// TODO: Find a system independent API | // TODO: Find a system independent API | ||||
llvm::SmallString<128> driverPath; | llvm::SmallString<128> driverPath; | ||||
driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr)); | driverPath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr)); | ||||
llvm::sys::path::remove_filename(driverPath); | llvm::sys::path::remove_filename(driverPath); | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | for (const auto *a : args.filtered(clang::driver::options::OPT_UNKNOWN)) { | ||||
if (opts.findNearest(argString, nearest, includedFlagsBitmask) > 1) | if (opts.findNearest(argString, nearest, includedFlagsBitmask) > 1) | ||||
diags.Report(clang::diag::err_drv_unknown_argument) << argString; | diags.Report(clang::diag::err_drv_unknown_argument) << argString; | ||||
else | else | ||||
diags.Report(clang::diag::err_drv_unknown_argument_with_suggestion) | diags.Report(clang::diag::err_drv_unknown_argument_with_suggestion) | ||||
<< argString << nearest; | << argString << nearest; | ||||
success = false; | success = false; | ||||
} | } | ||||
// Parse the frontend args | success &= ParseFrontendArgs(res.frontendOpts(), args, diags); | ||||
ParseFrontendArgs(res.frontendOpts(), args, diags); | |||||
parsePreprocessorArgs(res.preprocessorOpts(), args); | parsePreprocessorArgs(res.preprocessorOpts(), args); | ||||
success &= parseSemaArgs(res, args, diags); | success &= parseSemaArgs(res, args, diags); | ||||
success &= parseDialectArgs(res, args, diags); | success &= parseDialectArgs(res, args, diags); | ||||
success &= parseDiagArgs(res, args, diags); | success &= parseDiagArgs(res, args, diags); | ||||
return success; | return success; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |