def cxx_isystem : JoinedOrSeparate<["-"], "cxx-isystem">, Group<clang_i_Group>,
HelpText<"Add directory to the C++ SYSTEM include search path">, Flags<[CC1Option]>,
MetaVarName<"<directory>">;
-def c : Flag<["-"], "c">, Flags<[NoXarchOption]>, Group<Action_Group>,
+def c : Flag<["-"], "c">, Flags<[NoXarchOption, FlangOption]>, Group<Action_Group>,
HelpText<"Only run preprocess, compile, and assemble steps">;
def fconvergent_functions : Flag<["-"], "fconvergent-functions">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Assume functions may be convergent">;
HelpText<"Build ASTs and convert to LLVM, discarding output">;
def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
HelpText<"Generate machine code, but discard output">;
-def emit_obj : Flag<["-"], "emit-obj">,
- HelpText<"Emit native object files">;
def rewrite_test : Flag<["-"], "rewrite-test">,
HelpText<"Rewriter playground">;
def rewrite_macros : Flag<["-"], "rewrite-macros">,
} // let Flags = [CC1Option, NoDriverOption]
//===----------------------------------------------------------------------===//
+// Frontend Options - cc1 + fc1
+//===----------------------------------------------------------------------===//
+let Flags = [CC1Option, FC1Option, NoDriverOption] in {
+let Group = Action_Group in {
+
+def emit_obj : Flag<["-"], "emit-obj">,
+ HelpText<"Emit native object files">;
+
+} // let Group = Action_Group
+} // let Flags = [CC1Option, FC1Option, NoDriverOption]
+
+//===----------------------------------------------------------------------===//
// cc1as-only Options
//===----------------------------------------------------------------------===//
const InputInfo &Output, const InputInfoList &Inputs,
const ArgList &Args, const char *LinkingOutput) const {
const auto &TC = getToolChain();
- const llvm::Triple &Triple = TC.getEffectiveTriple();
- const std::string &TripleStr = Triple.getTriple();
+ // TODO: Once code-generation is available, this will need to be commented
+ // out.
+ // const llvm::Triple &Triple = TC.getEffectiveTriple();
+ // const std::string &TripleStr = Triple.getTriple();
ArgStringList CmdArgs;
+ // Invoke ourselves in -fc1 mode.
CmdArgs.push_back("-fc1");
- // TODO: Eventually all actions will require a triple (e.g. `-triple
- // aarch64-unknown-linux-gnu`). However, `-triple` is currently not supported
- // by `flang-new -fc1`, so we only add it selectively to actions that we
- // don't support/execute just yet.
+ // TODO: Once code-generation is available, this will need to be commented
+ // out.
+ // Add the "effective" target triple.
+ // CmdArgs.push_back("-triple");
+ // CmdArgs.push_back(Args.MakeArgString(TripleStr));
+
if (isa<PreprocessJobAction>(JA)) {
if (C.getArgs().hasArg(options::OPT_test_io))
CmdArgs.push_back("-test-io");
assert(false && "Unexpected output type!");
}
} else if (isa<AssembleJobAction>(JA)) {
- CmdArgs.push_back("-triple");
- CmdArgs.push_back(Args.MakeArgString(TripleStr));
CmdArgs.push_back("-emit-obj");
} else {
assert(false && "Unexpected action class for Flang tool.");
void ExecuteAction() override;
};
+class EmitObjAction : public FrontendAction {
+ void ExecuteAction() override;
+};
+
} // namespace Fortran::frontend
#endif // LLVM_FLANG_FRONTEND_FRONTENDACTIONS_H
/// -fsyntax-only
ParseSyntaxOnly,
+ /// Emit a .o file.
+ EmitObj,
+
/// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
/// EmitCodeGenOnly, EmitAssembly, (...)
};
case clang::driver::options::OPT_fsyntax_only:
opts.programAction_ = ParseSyntaxOnly;
break;
+ case clang::driver::options::OPT_emit_obj:
+ opts.programAction_ = EmitObj;
+ break;
// TODO:
- // case clang::driver::options::OPT_emit_obj:
// case calng::driver::options::OPT_emit_llvm:
// case clang::driver::options::OPT_emit_llvm_only:
// case clang::driver::options::OPT_emit_codegen_only:
ci.diagnostics().Report(DiagID) << GetCurrentFileOrBufferName();
}
}
+
+void EmitObjAction::ExecuteAction() {
+ CompilerInstance &ci = this->instance();
+ unsigned DiagID = ci.diagnostics().getCustomDiagID(
+ clang::DiagnosticsEngine::Error, "code-generation is not available yet");
+ ci.diagnostics().Report(DiagID);
+}
break;
case ParseSyntaxOnly:
return std::make_unique<ParseSyntaxOnlyAction>();
+ case EmitObj:
+ return std::make_unique<EmitObjAction>();
break;
default:
break;
--- /dev/null
+! RUN: not %flang-new %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: not %flang-new -c %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: not %flang-new -emit-obj %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: not %flang-new -fc1 -emit-obj %s 2>&1 | FileCheck %s --check-prefix=ERROR
+
+! REQUIRES: new-flang-driver
+
+! Although code-generation is not yet available, we do have frontend actions
+! that correspond to `-c` and `-emit-obj`. For now these actions are just a
+! placeholder and running them leads to a driver error. This test makes sure
+! that these actions are indeed run (rather than `-c` or `-emit-obj` being
+! rejected earlier).
+! TODO: Replace this file with a proper test once code-generation is available.
+
+! ERROR: code-generation is not available yet
! CHECK-EMPTY:
! CHECK-NEXT:OPTIONS:
! CHECK-NEXT: -### Print (but do not run) the commands to run for this compilation
+! CHECK-NEXT: -c Only run preprocess, compile, and assemble steps
! CHECK-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
! CHECK-NEXT: -E Only run the preprocessor
! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics
! HELP-EMPTY:
! HELP-NEXT:OPTIONS:
! HELP-NEXT: -### Print (but do not run) the commands to run for this compilation
+! HELP-NEXT: -c Only run preprocess, compile, and assemble steps
! HELP-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
! HELP-NEXT: -E Only run the preprocessor
! HELP-NEXT: -fcolor-diagnostics Enable colors in diagnostics
! HELP-FC1-EMPTY:
! HELP-FC1-NEXT:OPTIONS:
! HELP-FC1-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
+! HELP-FC1-NEXT: -emit-obj Emit native object files
! HELP-FC1-NEXT: -E Only run the preprocessor
! HELP-FC1-NEXT: -help Display available options
! HELP-FC1-NEXT: -o <file> Write output to <file>
+++ /dev/null
-! RUN: not %flang-new %s 2>&1 | FileCheck %s --check-prefix=ERROR
-! RUN: not %flang-new -emit-obj %s 2>&1 | FileCheck %s --check-prefix=ERROR
-! RUN: not %flang-new -fc1 -emit-obj %s 2>&1 | FileCheck %s --check-prefix=ERROR-FC1
-
-! REQUIRES: new-flang-driver
-
-! By default (e.g. when no options like `-E` are passed) flang-new
-! creates a job that corresponds to `-emit-obj`. This option/action is
-! not yet supported. Verify that this is correctly reported as error.
-
-! ERROR: error: unknown argument: '-triple'
-! ERROR: error: unknown argument: '-emit-obj'
-
-! ERROR-FC1: error: unknown argument: '-emit-obj'
--- /dev/null
+! RUN: %flang-new -E -ccc-print-phases %s 2>&1 | FileCheck %s --check-prefix=PP
+! RUN: %flang-new -fsyntax-only -ccc-print-phases %s 2>&1 | FileCheck %s --check-prefix=COMPILE
+! RUN: %flang-new -c -ccc-print-phases %s 2>&1 | FileCheck %s --check-prefix=EMIT_OBJ
+
+! REQUIRES: new-flang-driver
+
+! This test verifies the phase control in Flang compiler driver.
+
+! PP: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
+! PP-NEXT: 1: preprocessor, {0}, f95
+
+! COMPILE: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
+! COMPILE-NEXT: 1: preprocessor, {0}, f95
+! COMPILE-NEXT: 2: compiler, {1}, none
+
+! EMIT_OBJ: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
+! EMIT_OBJ-NEXT: 1: preprocessor, {0}, f95
+! EMIT_OBJ-NEXT: 2: compiler, {1}, ir
+! EMIT_OBJ-NEXT: +- 3: backend, {2}, assembler
+! EMIT_OBJ-NEXT: 4: assembler, {3}, object