forked from OSchip/llvm-project
[flang][driver] Add support for the "-init-only" option
Adding the `-init-only` option and corresponding frontend action to generate a diagnostic. `-init-only` vs `-test-io`: `-init-only` ignores the input (it never calls the prescanner) `-test-io` is similar to `-init-only`, but does read and print the input without calling the prescanner. This patch also adds a Driver test to check this action. Reviewed By: awarzynski, AMDChirag Differential Revision: https://reviews.llvm.org/D102849
This commit is contained in:
parent
ae3f6de3a8
commit
e1da3297d2
|
@ -5273,8 +5273,6 @@ def analyze : Flag<["-"], "analyze">,
|
||||||
HelpText<"Run static analysis engine">;
|
HelpText<"Run static analysis engine">;
|
||||||
def dump_tokens : Flag<["-"], "dump-tokens">,
|
def dump_tokens : Flag<["-"], "dump-tokens">,
|
||||||
HelpText<"Run preprocessor, dump internal rep of tokens">;
|
HelpText<"Run preprocessor, dump internal rep of tokens">;
|
||||||
def init_only : Flag<["-"], "init-only">,
|
|
||||||
HelpText<"Only execute frontend initialization">;
|
|
||||||
def fixit : Flag<["-"], "fixit">,
|
def fixit : Flag<["-"], "fixit">,
|
||||||
HelpText<"Apply fix-it advice to the input source">;
|
HelpText<"Apply fix-it advice to the input source">;
|
||||||
def fixit_EQ : Joined<["-"], "fixit=">,
|
def fixit_EQ : Joined<["-"], "fixit=">,
|
||||||
|
@ -5740,6 +5738,8 @@ let Group = Action_Group in {
|
||||||
|
|
||||||
def emit_obj : Flag<["-"], "emit-obj">,
|
def emit_obj : Flag<["-"], "emit-obj">,
|
||||||
HelpText<"Emit native object files">;
|
HelpText<"Emit native object files">;
|
||||||
|
def init_only : Flag<["-"], "init-only">,
|
||||||
|
HelpText<"Only execute frontend initialization">;
|
||||||
|
|
||||||
} // let Group = Action_Group
|
} // let Group = Action_Group
|
||||||
} // let Flags = [CC1Option, FC1Option, NoDriverOption]
|
} // let Flags = [CC1Option, FC1Option, NoDriverOption]
|
||||||
|
|
|
@ -38,6 +38,10 @@ class EmitObjAction : public FrontendAction {
|
||||||
void ExecuteAction() override;
|
void ExecuteAction() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InitOnlyAction : public FrontendAction {
|
||||||
|
void ExecuteAction() override;
|
||||||
|
};
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Prescan Actions
|
// Prescan Actions
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -71,7 +71,10 @@ enum ActionKind {
|
||||||
GetDefinition,
|
GetDefinition,
|
||||||
|
|
||||||
/// Parse, run semantics and then dump symbol sources map
|
/// Parse, run semantics and then dump symbol sources map
|
||||||
GetSymbolsSources
|
GetSymbolsSources,
|
||||||
|
|
||||||
|
/// Only execute frontend initialization
|
||||||
|
InitOnly
|
||||||
|
|
||||||
/// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
|
/// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
|
||||||
/// EmitCodeGenOnly, EmitAssembly, (...)
|
/// EmitCodeGenOnly, EmitAssembly, (...)
|
||||||
|
|
|
@ -162,9 +162,12 @@ static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
|
||||||
case clang::driver::options::OPT_fget_definition:
|
case clang::driver::options::OPT_fget_definition:
|
||||||
opts.programAction_ = GetDefinition;
|
opts.programAction_ = GetDefinition;
|
||||||
break;
|
break;
|
||||||
|
case clang::driver::options::OPT_init_only:
|
||||||
|
opts.programAction_ = InitOnly;
|
||||||
|
break;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// case calng::driver::options::OPT_emit_llvm:
|
// case clang::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:
|
||||||
|
|
|
@ -447,3 +447,11 @@ void EmitObjAction::ExecuteAction() {
|
||||||
clang::DiagnosticsEngine::Error, "code-generation is not available yet");
|
clang::DiagnosticsEngine::Error, "code-generation is not available yet");
|
||||||
ci.diagnostics().Report(DiagID);
|
ci.diagnostics().Report(DiagID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitOnlyAction::ExecuteAction() {
|
||||||
|
CompilerInstance &ci = this->instance();
|
||||||
|
unsigned DiagID =
|
||||||
|
ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Warning,
|
||||||
|
"Use `-init-only` for testing purposes only");
|
||||||
|
ci.diagnostics().Report(DiagID);
|
||||||
|
}
|
||||||
|
|
|
@ -73,6 +73,9 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
|
||||||
case GetSymbolsSources:
|
case GetSymbolsSources:
|
||||||
return std::make_unique<GetSymbolsSourcesAction>();
|
return std::make_unique<GetSymbolsSourcesAction>();
|
||||||
break;
|
break;
|
||||||
|
case InitOnly:
|
||||||
|
return std::make_unique<InitOnlyAction>();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
|
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
|
||||||
! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
|
! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
|
||||||
! HELP-FC1-NEXT: -help Display available options
|
! HELP-FC1-NEXT: -help Display available options
|
||||||
|
! HELP-FC1-NEXT: -init-only Only execute frontend initialization
|
||||||
! HELP-FC1-NEXT: -I <dir> Add directory to the end of the list of include search paths
|
! HELP-FC1-NEXT: -I <dir> Add directory to the end of the list of include search paths
|
||||||
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
|
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
|
||||||
! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`)
|
! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
! Verify that -init-only flag generates a diagnostic as expected
|
||||||
|
|
||||||
|
! REQUIRES: new-flang-driver
|
||||||
|
|
||||||
|
! RUN: %flang_fc1 -init-only 2>&1 | FileCheck %s
|
||||||
|
|
||||||
|
! CHECK: warning: Use `-init-only` for testing purposes only
|
Loading…
Reference in New Issue