aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorFaris Rehman <faris.rehman@arm.com>2021-01-26 16:27:30 +0000
committerFaris Rehman <faris.rehman@arm.com>2021-02-04 12:24:15 +0000
commit3a1513c142f4a1ddb97d882a12c89f90cb2529ac (patch)
tree2dbf85aa6eb404cb2c4fe75e4ba0975eb70c947a /flang/lib/Frontend/CompilerInvocation.cpp
parentfa2cdb81407b9859794e4a47fc65d20a110e338c (diff)
downloadllvm-3a1513c142f4a1ddb97d882a12c89f90cb2529ac.zip
llvm-3a1513c142f4a1ddb97d882a12c89f90cb2529ac.tar.gz
llvm-3a1513c142f4a1ddb97d882a12c89f90cb2529ac.tar.bz2
[flang][driver] Add forced form flags and -ffixed-line-length
Add support for the following layout options: * -ffree-form * -ffixed-form - -ffixed-line-length=n (alias -ffixed-line-length-n) Additionally remove options `-fno-free-form` and `-fno-fixed-form` as they were initially added to forward to gfortran but gfortran does not support these flags. This patch adds the flag FlangOnlyOption to the existing options `-ffixed-form`, `-ffree-form` and `-ffree-line-length-` in Options.td. As of commit 6a75496836ea14bcfd2f4b59d35a1cad4ac58cee, these flags are not currently forwarded to gfortran anyway. The default fixed line length in FrontendOptions is 72, based off the current default in Fortran::parser::Options. The line length cannot be set to a negative integer, or a positive integer less than 7 excluding 0, consistent with the behaviour of gfortran. This patch does not add `-ffree-line-length-n` as Fortran::parser::Options does not have a variable for free form columns. Whilst the `fixedFormColumns` variable is used in f18 for `-ffree-line-length-n`, f18 only allows `-ffree-line-length-none`/`-ffree-line-length-0` and not a user-specified value. `fixedFormcolumns` cannot be used in the new driver as it is ignored in the frontend when dealing with free form files. Summary of changes: - Remove -fno-fixed-form and -fno-free-form from Options.td - Make -ffixed-form, -ffree-form and -ffree-line-length-n FlangOnlyOption in Options.td - Create AddFortranDialectOptions method in Flang.cpp - Create FortranForm enum in FrontendOptions.h - Add fortranForm_ and fixedFormColumns_ to Fortran::frontend::FrontendOptions - Update fixed-form-test.f so that it guarantees that it fails when forced as a free form file to better facilitate testing. Differential Revision: https://reviews.llvm.org/D95460
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 5077d06..563953f7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -162,6 +162,40 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
opts.inputs_.emplace_back(std::move(inputs[i]), ik);
}
+
+ // Set fortranForm_ based on options -ffree-form and -ffixed-form.
+ if (const auto *arg = args.getLastArg(clang::driver::options::OPT_ffixed_form,
+ clang::driver::options::OPT_ffree_form)) {
+ opts.fortranForm_ =
+ arg->getOption().matches(clang::driver::options::OPT_ffixed_form)
+ ? FortranForm::FixedForm
+ : FortranForm::FreeForm;
+ }
+
+ // Set fixedFormColumns_ based on -ffixed-line-length=<value>
+ if (const auto *arg =
+ args.getLastArg(clang::driver::options::OPT_ffixed_line_length_EQ)) {
+ llvm::StringRef argValue = llvm::StringRef(arg->getValue());
+ std::int64_t columns = -1;
+ if (argValue == "none") {
+ columns = 0;
+ } else if (argValue.getAsInteger(/*Radix=*/10, columns)) {
+ columns = -1;
+ }
+ if (columns < 0) {
+ diags.Report(clang::diag::err_drv_invalid_value_with_suggestion)
+ << arg->getOption().getName() << arg->getValue()
+ << "value must be 'none' or a non-negative integer";
+ } else if (columns == 0) {
+ opts.fixedFormColumns_ = 1000000;
+ } else if (columns < 7) {
+ diags.Report(clang::diag::err_drv_invalid_value_with_suggestion)
+ << arg->getOption().getName() << arg->getValue()
+ << "value must be at least seven";
+ } else {
+ opts.fixedFormColumns_ = columns;
+ }
+ }
return dashX;
}
@@ -278,8 +312,15 @@ void CompilerInvocation::SetDefaultFortranOpts() {
void CompilerInvocation::setFortranOpts() {
auto &fortranOptions = fortranOpts();
+ const auto &frontendOptions = frontendOpts();
const auto &preprocessorOptions = preprocessorOpts();
+ if (frontendOptions.fortranForm_ != FortranForm::Unknown) {
+ fortranOptions.isFixedForm =
+ frontendOptions.fortranForm_ == FortranForm::FixedForm;
+ }
+ fortranOptions.fixedFormColumns = frontendOptions.fixedFormColumns_;
+
collectMacroDefinitions(preprocessorOptions, fortranOptions);
fortranOptions.searchDirectories.insert(