aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-03-08[flang][driver] Add support for `-debug-dump-pft`Andrzej Warzynski1-0/+3
This patch adds support for dumping the pre-FIR tree in `flang-new -fc1`, i.e. Flang's frontend driver. This flag is functionally identical to `-pft-test` in `bbc` and semantically similar to `-fdebug-dump-parse-tree` from `flang-new -fc1`. Differential Revision: https://reviews.llvm.org/D121198
2022-02-25[flang][driver] Add support for `--target`/`--triple`Andrzej Warzynski1-0/+11
This patch adds support for: * `--target` in the compiler driver (`flang-new`) * `--triple` in the frontend driver (`flang-new -fc1`) The semantics of these flags are inherited from `clangDriver`, i.e. consistent with `clang --target` and `clang -cc1 --triple`, respectively. A new structure is defined, `TargetOptions`, that will hold various Frontend options related to the target. Currently, this is mostly a placeholder that contains the target triple. In the future, it will be used for storing e.g. the CPU to tune for or the target features to enable. Additionally, the following target/triple related options are enabled [*]: `-print-effective-triple`, `-print-target-triple`. Definitions in Options.td are updated accordingly and, to facilated testing, `-emit-llvm` is added to the list of options available in `flang-new` (previously it was only enabled in `flang-new -fc1`). [*] These options were actually available before (like all other options defined in `clangDriver`), but not included in `flang-new --help`. Before this change, `flang-new` would just use `native` for defining the target, so these options were of little value. Differential Revision: https://reviews.llvm.org/D120246
2022-02-17[flang][driver] Add support for `-emit-llvm`Andrzej Warzynski1-0/+3
This patch adds support for the `-emit-llvm` option in the frontend driver (i.e. `flang-new -fc1`). Similarly to Clang, `flang-new -fc1 -emit-llvm file.f` will generate a textual LLVM IR file. Depends on D118985 Differential Revision: https://reviews.llvm.org/D119012
2022-02-09[flang][driver] Add support for `-emit-mlir`Andrzej Warzynski1-0/+3
This patch adds support for generating MLIR files in Flang's frontend driver (i.e. `flang-new -fc1`). `-emit-fir` is added as an alias for `-emit-mlir`. We may want to decide to split the two in the future. A new parent class for code-gen frontend actions is introduced: `CodeGenAction`. We will be using this class to encapsulate logic shared between all code-generation actions, but not required otherwise. For now, it will: * run prescanning, parsing and semantic checks, * lower the input to MLIR. `EmitObjAction` is updated to inherit from this class. This means that the behaviour of `flang-new -fc1 -emit-obj` is also updated (previously, it would just exit immediately). This change required `flang/test/Driver/syntax-only.f90` to be updated. For `-emit-fir`, a specialisation of `CodeGenAction` is introduced: `EmitMLIRAction`. The key logic for this class is implemented in `EmitMLIRAction::ExecuteAction`. Differential Revision: https://reviews.llvm.org/D118985
2022-01-31[flang] Distinguish intrinsic from non-intrinsic modulesPeter Klausler1-2/+3
For "USE, INTRINSIC", search only for intrinsic modules; for "USE, NON_INTRINSIC", do not recognize intrinsic modules. Allow modules of both kinds with the same name to be used in the same source file (but not in the same scoping unit, a constraint of the standard that is now enforced). The symbol table's scope tree now has a single instance of a scope with a new kind, IntrinsicModules, whose children are the USE'd intrinsic modules (explicit or not). This separate "top-level" scope is a child of the single global scope and it allows both intrinsic and non-intrinsic modules of the same name to exist in the symbol table. Intrinsic modules' scopes' symbols now have the INTRINSIC attribute set. The search path directories need to make a distinction between regular directories and the one(s) that point(s) to intrinsic modules. I allow for multiple intrinsic module directories in the second search path, although only one is needed today. Differential Revision: https://reviews.llvm.org/D118631
2022-01-31[flang][driver][nfc] Fix capitalisationAndrzej Warzynski1-4/+4
As pointed out in https://reviews.llvm.org/D93401, some methods in the Flang driver are named inconsistently. The driver strives to follow Flang's C++ style [1] and this patch updates these methods accordingly. [1] https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md Differential Revision: https://reviews.llvm.org/D118381
2022-01-21Include missing "llvm/Support/Path.h" in ↵serge-sans-paille1-0/+1
"flang/lib/Frontend/CompilerInvocation.cpp"
2021-12-17[flang] Make the frontend driver error out when requesting multiple actionsAndrzej Warzynski1-0/+10
With this change, the following invocations will be treated as errors (multiple actions are specified): ``` $ flang-new -fc1 -E -fsyntax-only file.95 $ flang-new -fc1 -fsyntax-only -fdebug-dump-symbols file.95 ``` In the examples above it is not clear whether it is `-fsyntax-only` or the other action that is run (i.e. `-E` or `-fdebug-dump-symbols`). It makes sense to disallow such usage. This should also lead to cleaner and clearer tests (the `RUN` lines using `%flang_fc1` will only allow one action). This change means that `flang-new -fc1` and `clang -cc1` will behave differently when multiple action options are specified. As frontend drivers are mostly used by compiler developers, this shouldn't affect or confuse the compiler end-users. Also, `flang-new` and `clang` remain consistent. Tests are updated accordingly. More specifically, I've made sure that every test specifies only one action. I've also taken the opportunity to simplify "multiple-input-files.f90" a bit. Differential Revision: https://reviews.llvm.org/D111781
2021-11-22[flang] Add -fno-automatic, refine IsSaved()Peter Klausler1-0/+5
This legacy option (available in other Fortran compilers with various spellings) implies the SAVE attribute for local variables on subprograms that are not explicitly RECURSIVE. The SAVE attribute essentially implies static rather than stack storage. This was the default setting in Fortran until surprisingly recently, so explicit SAVE statements & attributes could be and often were omitted from older codes. Note that initialized objects already have an implied SAVE attribute, and objects in COMMON effectively do too, as data overlays are extinct; and since objects that are expected to survive from one invocation of a procedure to the next in static storage should probably be explicit initialized in the first place, so the use cases for this option are somewhat rare, and all of them could be handled with explicit SAVE statements or attributes. This implicit SAVE attribute must not apply to automatic (in the Fortran sense) local objects, whose sizes cannot be known at compilation time. To get the semantics of IsSaved() right, the IsAutomatic() predicate was moved into Evaluate/tools.cpp to allow for dynamic linking of the compiler. The redundant predicate IsAutomatic() was noticed, removed, and its uses replaced. GNU Fortran's spelling of the option (-fno-automatic) was added to the clang-based driver and used for basic sanity testing. Differential Revision: https://reviews.llvm.org/D114209
2021-08-12[flang][driver] Add support for Frontend PluginsStuart Ellis1-0/+12
Introducing a plugin API and a simple HelloWorld Plugin example. This patch adds the `-load` and `-plugin` flags to frontend driver and the code around using custom frontend actions from within a plugin shared library object. It also adds to the Driver-help test to check the help option with the updated driver flags. Additionally, the patch creates a plugin-example test to check the HelloWorld plugin example runs correctly. As part of this, a new CMake flag (`FLANG_BUILD_EXAMPLES`) is added to allow the example to be built and for the test to run. This Plugin API has only been tested on Linux. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D106137
2021-08-05[flang][driver] Delete `f18` (i.e. the old Flang driver)Andrzej Warzynski1-1/+0
This patch removes `f18`, a.k.a. the old driver. It is being replaced with the new driver, `flang-new`, which has reached feature parity with `f18` a while ago. This was discussed in [1] and also in [2]. With this change, `FLANG_BUILD_NEW_DRIVER` is no longer needed and is also deleted. This means that we are making the dependency on Clang permanent (i.e. it cannot be disabled with a CMake flag). LIT set-up is updated accordingly. All references to `f18` or `f18.cpp` are either updated or removed. The `F18_FC` variable from the `flang` bash script is replaced with `FLANG_FC`. The former is still supported for backwards compatibility. [1] https://lists.llvm.org/pipermail/flang-dev/2021-June/000742.html [2] https://reviews.llvm.org/D103177 Differential Revision: https://reviews.llvm.org/D105811
2021-08-05[flang][driver] Refactor boolean optionsAndrzej Warzynski1-31/+25
For boolean options, e.g. `-fxor-operator`/`-fno-xor-operator`, we ought to be using TableGen multi-classes. This way, we only have to write one definition to have both forms auto-generated. This patch refactors all of Flang's boolean options to use two new multi-classes: `OptInFC1FFOption` and `OptOutFC1FFOption`. These multi-classes are based on `OptInFFOption`/`OptOutFFOption`, respectively. I've also simplified the processing of the updated options in CompilerInvocation.cpp. With the new approach, "empty" help text (i.e. no `HelpText`) is now replaced with an empty string (i.e. HelpText<"">). When running flang-new --help, that's considered as non-empty help messages, which is then printed (that's controlled by `printHelp` from llvm/lib/Option/OptTable.cpp). This means that with this patch, flang-new --help will start printing e.g. -fno-backslash, even though there is no actual help text to print for this option (apart from the empty string ""). Tests are updated accordingly. Note that with this patch, both `-fxor-operator` and `-fno-xor-operator` (and other boolean options refactored here) remain available in `flang-new` and `flang-new -fc1`. In this respect, nothing changes. In a forthcoming patch, I will refine this so that `flang-new -fc1` only accepts `-ffoo` (`OptInFC1FFOption`) or `-fno-foo` (`OptOutCC1FFOption`). For clarity, `OptInFFOption`/`OptOutFFOption` are renamed as `OptInCC1FFOption`/`OptOutCC1FFOption`, respectively. Otherwise, this is an NFC from Clang's perspective. Differential Revision: https://reviews.llvm.org/D105881
2021-08-02[flang][nfc] Fix variable names in `FrontendOptions` & `PreprocessorOptions`Andrzej Warzynski1-59/+58
As all member variables in `FrontendOptions` and `PreprocessorOptions` are public, we should be naming them as `variable` rather than `variable_` [1]. This patch fixes that. Also, `FrontendOptions` & `PreprocessorOptions` are re-defined as a structs rather than classes (all fields are meant to be public). [1] https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md#naming Differential Revision: https://reviews.llvm.org/D107062
2021-07-30[flang] Produce proper "preprocessor output" for -E optionpeter klausler1-0/+3
Rename the current -E option to "-E -Xflang -fno-reformat". Add a new Parsing::EmitPreprocessedSource() routine to convert the cooked character stream output of the prescanner back to something more closely resembling output from a traditional preprocessor; call this new routine when -E appears. The new -E output is suitable for use as fixed form Fortran source to compilation by (one hopes) any Fortran compiler. If the original top-level source file had been free form source, the output will be suitable for use as free form source as well; otherwise there may be diagnostics about missing spaces if they were indeed absent in the original fixed form source. Unless the -P option appears, #line directives are interspersed with the output (but be advised, f18 will ignore these if presented with them in a later compilation). An effort has been made to preserve original alphabetic character case and source indentation. Add -P and -fno-reformat to the new drivers. Tweak test options to avoid confusion with prior -E output; use -fno-reformat where needed, but prefer to keep -E, sometimes in concert with -P, on most, updating expected results accordingly. Differential Revision: https://reviews.llvm.org/D106727
2021-07-01[flang] Revert "PoC for Flang Driver Plugins"Andrzej Warzynski1-17/+0
This patch has not been reviewed and was commited by accident. This reverts commit 788a5d4afe6407e647454a9832a7b4a27fba06bf.
2021-07-01PoC for Flang Driver PluginsStuart Ellis1-0/+17
2021-06-25[flang][driver] Add `-fno-analyzed-objects-for-unparse`Andrzej Warzynski1-0/+6
This patch adds a new option for the new Flang driver: `-fno-analyzed-objects-for-unparse`. The semantics are similar to `-funparse-typed-exprs-to-f18-fc` from `f18`. For consistency, the latter is replaced with `-fno-analyzed-objects-for-unparse`. The new option controls the behaviour of the unparser (i.e. the action corresponding to `-fdebug-unparse`). The default behaviour is to use the analyzed objects when unparsing. The new flag can be used to turn this off, so that the original parse-tree objects are used. The analyzed objects are generated during the semantic checks [1]. This patch also updates the semantics of `-fno-analyzed-objects-for-unparse`/`-funparse-typed-exprs-to-f18-fc` in `f18`, so that this flag is always taken into account when `Unparse` is used (this way the semantics in `f18` and `flang-new` are identical). The added test file is based on example from Peter Steinfeld. [1] https://github.com/llvm/llvm-project/blob/main/flang/docs/Semantics.md Differential Revision: https://reviews.llvm.org/D103612
2021-06-16[flang][driver] Add `-fdebug-dump-all`Andrzej Warzynski1-0/+3
The new option will run the semantic checks and then dump the parse tree and all the symbols. This is equivalent to running the driver twice, once with `-fdebug-dump-parse-tree` and then with the `-fdebug-dump-symbols` action flag. Currently we wouldn't be able to achieve the same by simply running: ``` flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols <input-file> ``` That's because the new driver will only run one frontend action per invocation (both of the flags used here are action flags). Diverging from this design would lead to costly compromises and it's best avoided. We may want to consider re-designing our debugging actions (and action options) in the future so that there's more code re-use. For now, I'm focusing on making sure that we support all the major cases requested by our users. Differential Revision: https://reviews.llvm.org/D104305
2021-06-07[flang][driver] Add support for the "-init-only" optionStuart Ellis1-1/+4
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
2021-06-04[flang][driver] Add checks for missing option argumentsAndrzej Warzynski1-0/+7
With this patch, the following invocation of the frontend driver will return an error: ``` flang-new -fc1 input-file.f90 -o ``` Similar logic applies to other options that require arguments. Similar checks are already available in the compiler driver, flang-new (that's implemented in clangDriver). Differential Revision: https://reviews.llvm.org/D103554
2021-06-04[flang][driver] Add support for `-module-suffix`Andrzej Warzynski1-1/+8
This option is supported in `f18`, but not yet available in `flang-new`. It is required in order to call `flang-new` from the `flang` bash script. Differential Revision: https://reviews.llvm.org/D103613
2021-05-05[Clang] remove text extension from diag::err_drv_invalid_value_with_suggestionNick Desaulniers1-6/+4
This hinders translations, as per: https://clang.llvm.org/docs/InternalsManual.html#the-format-string Reviewed By: MaskRay, xbolva00 Differential Revision: https://reviews.llvm.org/D101387
2021-04-21[flang][driver] Add support for `-fget-definition`Andrzej Warzynski1-4/+31
This patch adds `-fget-definition` to `flang-new`. The semantics of this option are identical in both drivers. The error message in the "throwaway" driver is updated so that it matches the one from `flang-new` (which is auto-generated and cannot be changed easily). Tests are updated accordingly. A dedicated test for error handling was added: get-definition.f90 (for the sake of simplicity, getdefinition01.f90 no longer tests for errors). The `ParseFrontendArgs` function is updated so that it can return errors. This change is required in order to report invalid values following `-fget-definition`. The actual implementation of `GetDefinitionAction::ExecuteAction()` was extracted from f18.cpp (i.e. the bit that deals with `-fget-definition`). Depends on: https://reviews.llvm.org/D100556 Differential Revision: https://reviews.llvm.org/D100558
2021-04-20[flang][driver] Refactor methods for parsing options (nfc)Andrzej Warzynski1-18/+21
This is just a small update that makes sure that errors arising from parsing command-line options are captured more visibly. Also, all parsing methods will now consistently return either a bool ("may fail") or void ("never fails"). An instance of `InputKind` coming from `-x` is added to `FrontendOptions` rather then being returned from `ParseFrontendArgs`. It's currently not used, but we will require it shortly. In particular, once code-generation is available we will use it to differentiate between LLVM IR and Fortran input. `FrontendOptions` is a very suitable place to keep it. This changes don't affect the error reporting in the driver. In this respect these are non-functional-changes. However, it will simplify things in the forthcoming patches in which we may need a better error tracking/recovery mechanism. Differential Revision: https://reviews.llvm.org/D100556
2021-04-08[flang][driver] Add debug options not requiring semantic checksAndrzej Warzynski1-0/+6
This patch adds two debugging options in the new Flang driver (flang-new): *fdebug-unparse-no-sema *fdebug-dump-parse-tree-no-sema Each of these options combines two options from the "throwaway" driver (left: f18, right: flang-new): * `-fdebug-uparse -fdebug-no-semantics` --> `-fdebug-unparse-no-sema` * `-fdebug-dump-parse-tree -fdebug-no-semantics` --> `-fdebug-dump-parse-tree-no-sema` There are no plans to implement `-fdebug-no-semantics` in the new driver. Such option would be too powerful. Also, it would only make sense when combined with specific frontend actions (`-fdebug-unparse` and `-fdebug-dump-parse-tree`). Instead, this patch adds 2 specialised options listed above. Each of these is implemented through a dedicated FrontendAction (also added). The new frontend actions are implemented in terms of a new abstract base action: `PrescanAndSemaAction`. This new base class was required so that we can have finer control over what steps within the frontend are executed: * `PrescanAction`: run the _prescanner_ * `PrescanAndSemaAction`: run the _prescanner_ and the _parser_ (new in this patch) * `PrescanAndSemaAction`: run the _prescanner_, _parser_ and run the _semantic checks_ This patch introduces `PrescanAndParseAction::BeginSourceFileAction`. Apart from the semantic checks removed at the end, it is similar to `PrescanAndSemaAction::BeginSourceFileAction`. Differential Revision: https://reviews.llvm.org/D99645
2021-04-07[flang][driver] Fix `-fdebug-dump-provenance`Andrzej Warzynski1-0/+6
The -fdebug-dump-provenance flag is meant to be used with needProvenanceRangeToCharBlockMappings set to true. This way, extra mapping is generated that allows e.g. IDEs to retrieve symbol's scope (offset into cooked character stream) based on symbol's source code location. This patch makes sure that this option is set when using -fdebug-dump-provenance. With this patch, the implementation of -fdebug-dump-provenance in `flang-new -fc1` becomes consistent with `f18`. The corresponding LIT test is updated so that it can be shared with `f18`. I refined it a bit so that: * it becomes a frontend-only test * it's stricter about the expected output Differential Revision: https://reviews.llvm.org/D98847
2021-04-07[flang][driver] Add support for `-cpp/-nocpp`Andrzej Warzynski1-11/+13
This patch adds support for the `-cpp` and `-nocpp` flags. The implemented semantics match f18 (i.e. the "throwaway" driver), but are different to gfortran. In Flang the preprocessor is always run. Instead, `-cpp/-nocpp` are used to control whether predefined and command-line preprocessor macro definitions are enabled or not. In practice this is sufficient to model gfortran`s `-cpp/-nocpp`. In the absence of `-cpp/-nocpp`, the driver will use the extension of the input file to decide whether to include the standard macro predefinitions. gfortran's documentation [1] was used to decide which file extension to use for this. The logic mentioned above was added in FrontendAction::BeginSourceFile. That's relatively late in the driver set-up, but this roughly where the name of the input file becomes available. The logic for deciding between fixed and free form works in a similar way and was also moved to FrontendAction::BeginSourceFile for consistency (and to reduce code-duplication). The `-cpp/-nocpp` flags are respected also when the input is read from stdin. This is different to: * gfortran (behaves as if `-cpp` was used) * f18 (behaves as if `-nocpp` was used) Starting with this patch, file extensions are significant and some test files had to be renamed to reflect that. Where possible, preprocessor tests were updated so that they can be shared between `f18` and `flang-new`. This was implemented on top of adding new test for `-cpp/-nocpp`. [1] https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D99292
2021-04-05[flang][driver] Add options for -WerrorArnamoy Bhattacharyya1-1/+24
With the option given, warnings are treated as error. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D98657
2021-03-25[flang][driver] Fix typos and inconsistent comments (nfc)Andrzej Warzynski1-3/+2
2021-03-25[flang][driver] Add options for -std=f2018Arnamoy Bhattacharyya1-1/+27
Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D97119
2021-03-23[flang][driver] Add -fintrinsic-modules-path optionArnamoy Bhattacharyya1-0/+28
Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D97080
2021-03-18[flang][driver] Add support for `-fget-symbols-sources`Andrzej Warzynski1-0/+3
Adds support for `-fget-symbols-sources` in the new Flang driver. All relevant tests are updated to use the new driver when `FLANG_BUILD_NEW_DRIVER` is set. `RUN` lines in tests are updated so `-fsyntax-only` comes before `-fget-symbols-sources`. That's because: * both `-fsyntax-only` and `-fget-symbols-sources` are action flags, and * the new driver, flang-new, will only consider the right-most action flag. In other words, this change is needed so that the tests work with both `f18` (requires both flags) and `flang-new` (only considers the last action flag). Differential Revision: https://reviews.llvm.org/D98191
2021-03-11[flang][driver] Add -fdebug-module-writer optionArnamoy Bhattacharyya1-5/+10
2021-03-10[flang][driver] Add `-fdebug-dump-parsing-log`Andrzej Warzynski1-0/+18
This patch adds `-fdebug-dump-parsing-log` in the new driver. This option is semantically identical to `-fdebug-instrumented-parse` in `f18` (the former is added as an alias in `f18`). As dumping the parsing log makes only sense for instrumented parses, we set Fortran::parser::Options::instrumentedParse to `True` when `-fdebug-dump-parsing-log` is used. This is consistent with `f18`. To facilitate tweaking the configuration of the frontend based on the action being requested, `setUpFrontendBasedOnAction` is introduced in CompilerInvocation.cpp. Differential Revision: https://reviews.llvm.org/D97457
2021-03-04[flang][driver] Add options for -fdefault* and -flarge-sizesArnamoy Bhattacharyya1-9/+45
Add support for the following Fortran dialect options: - -default* - -flarge-sizes It also adds two test cases: # For checking whether `flang-new` is passing options correctly to `flang-new -fc1`. # For checking if `fdefault-` arguments are processed properly. Also moves the Dialect related option parsing to a dedicated function and adds a member `defaultKinds()` to `CompilerInvocation` Depends on: D96032 Differential Revision: https://reviews.llvm.org/D96344
2021-02-19[flang][driver] Add debug measure-parse-tree and pre-fir-tree optionsFaris Rehman1-0/+6
Add the following options: * -fdebug-measure-parse-tree * -fdebug-pre-fir-tree Summary of changes: - Add 2 new frontend actions: DebugMeasureParseTreeAction and DebugPreFIRTreeAction - Add MeasurementVisitor to FrontendActions.h - Make reportFatalSemanticErrors return true if there are any fatal errors - Port most of the `-fdebug-pre-fir-tree` tests to use the new driver if built, otherwise use f18. Differential Revision: https://reviews.llvm.org/D96884
2021-02-18[flang][driver] Add debug dump optionsFaris Rehman1-0/+9
Add the following options: * -fdebug-dump-symbols * -fdebug-dump-parse-tree * -fdebug-dump-provenance Summary of changes: - Add 3 new frontend actions: DebugDumpSymbolsAction, DebugDumpParseTreeAction and DebugDumpProvenanceAction - Add a unique pointer to the Semantics instance created in PrescanAndSemaAction - Move fatal semantic error reporting to its own method, FrontendActions#reportFatalSemanticErrors - Port most tests using `-fdebug-dump-symbols` and `-fdebug-dump-parse-tree` to the new driver if built, otherwise default to f18 Differential Revision: https://reviews.llvm.org/D96716
2021-02-16[flang][driver] Add extension options and -finput-charsetFaris Rehman1-0/+44
Add the following options: * -fimplicit-none and -fno-implicit-none * -fbackslash and -fno-backslash * -flogical-abbreviations and -fno-logical-abbreviations * -fxor-operator and -fno-xor-operator * -falternative-parameter-statement * -finput-charset=<value> Summary of changes: - Enable extensions in CompilerInvocation#ParseFrontendArgs - Add encoding_ to Fortran::frontend::FrontendOptions - Add encoding to Fortran::parser::Options Differential Revision: https://reviews.llvm.org/D96407
2021-02-16[flang][driver] Add options for unparsingAndrzej Warzynski1-0/+6
This patch adds the following compiler frontend driver options: * -fdebug-unparse (f18 spelling: -funparse) * -fdebug-unparse-with-symbols (f18 spelling: -funparse-with-symbols) The new driver will only accept the new spelling. `f18` will accept both the original and the new spelling. A new base class for frontend actions is added: `PrescanAndSemaAction`. This is added to reduce code duplication that otherwise these new options would lead to. Implementation from * `ParseSyntaxOnlyAction::ExecutionAction` is moved to: * `PrescanAndSemaAction::BeginSourceFileAction` This implementation is now shared between: * PrescanAndSemaAction * ParseSyntaxOnlyAction * DebugUnparseAction * DebugUnparseWithSymbolsAction All tests that don't require other yet unimplemented options are updated. This way `flang-new -fc1` is used instead of `f18` when `FLANG_BUILD_NEW_DRIVER` is set to `On`. In order to facilitate this, `%flang_fc1` is added in the LIT configuration (lit.cfg.py). `asFortran` from f18.cpp is duplicated as `getBasicAsFortran` in FrontendOptions.cpp. At this stage it's hard to find a good place to share this method. I suggest that we revisit this once a switch from `f18` to `flang-new` is complete. Differential Revision: https://reviews.llvm.org/D96483
2021-02-11[flang][driver] Move standard macro predefs to a dedicated method (nfc)Andrzej Warzynski1-9/+8
This patch just addresses one of the outstanding TODOs. More specifically, it moves all the outstanding standard macro predefinitions from `SetDefaultFortranOpts` to `setDefaultPredefinitions`. This dedicated method for standard macro predefs was introduced in: * https://reviews.llvm.org/D96032
2021-02-10[flang][driver] Add support for -fopenmp and -fopenaccFaris Rehman1-4/+37
Add support for the following options: * -fopenmp * -fopenacc Update OpenMP and OpenACC semantics tests to use the new driver if it is built, otherwise use f18. OpenMP tests that include `use omp_lib` or run `test_symbols.sh` have not been updated as they require options `-intrinsic-module-directory` and `-funparse-with-symbols` which are currently not implemented in the new driver. Similarly OpenACC tests that run `test_symbols.sh` have not been updated. This patch also moves semanticsContext to CompilerInvocation and creates it in CompilerInvocation#setSemanticsOpts so that the semantics context can use Fortran::parser::Options#features. Summary of changes: - Move semanticsContext to CompilerInvocation.h - Update OpenMP and OpenACC semantics tests that do not rely on `-intrinsic-module-directory` and `-funparse-with-symbols` to use %flang Differential Revision: https://reviews.llvm.org/D96032
2021-02-04[flang][driver] Add support for `-J/-module-dir`Arnamoy Bhattacharyya1-0/+36
Add support for option -J/-module-dir in the new Flang driver. This will allow for including module files in other directories, as the default search path is currently the working folder. This also provides an option of storing the output module in the specified folder. Differential Revision: https://reviews.llvm.org/D95448
2021-02-04[flang][driver] Add forced form flags and -ffixed-line-lengthFaris Rehman1-0/+41
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
2021-02-02[flang][driver] Disallow non-existent input files in the frontend driverAndrzej Warzynski1-0/+4
This patch adds a check that verifies that the input file used when calling the frontend driver (i.e. `flang-new -fc1`) actually exists. This was not required for the compiler driver, `flang-new`, as that's already handled in libclangDriver. Once all input/output file management is moved to the driver, we should also check that for input from `stdin` the corresponding file descriptor was successfully acquired. This patch also makes sure that the default action in the frontend is `ParseSyntaxOnly`. This is consistent with Clang. Before this change `flang-new -fc1` would do nothing, which makes testing changes like the one introduced here a bit tricky. Reviewed By: SouraVX Differential Revision: https://reviews.llvm.org/D95127
2021-01-25[flang][driver] Remove newline in CompilerInvocationFaris Rehman1-2/+1
Remove a new line in CompilerInvocation, to now follow the style when clang-format is applied.
2021-01-19[flang][driver] Add standard macro predefinitions for compiler versionFaris Rehman1-0/+13
Add the following standard predefinitions that f18 supports: * `__flang__`, * `__flang_major__`, * `__flang_minor__`, * `__flang_patchlevel__` Summary of changes: - Populate Fortran::parser::Options#predefinitions with the default supported predefinitions Differential Revision: https://reviews.llvm.org/D94516
2021-01-19[flang][driver] Add support for `-I` in the new driverFaris Rehman1-0/+9
Add support for option -I in the new Flang driver. This will allow for included headers and module files in other directories, as the default search path is currently the working folder. The behaviour of this is consistent with the current f18 driver, where the current folder (i.e. ".") has the highest priority followed by the order of '-I's taking priority from first to last. Summary of changes: - Add SearchDirectoriesFromDashI to PreprocessorOptions, to be forwarded into the parser's searchDirectories - Add header files and non-functional module files to be used in regression tests. The module files are just text files and are used to demonstrated that paths specified with `-I` are taken into account when searching for .mod files. Differential Revision: https://reviews.llvm.org/D93453
2021-01-07[flang][driver] Add support for `-c` and `-emit-obj`Andrzej Warzynski1-1/+3
This patch adds a frontend action for emitting object files. While Flang does not support code-generation, this action remains a placeholder. This patch simply provides glue-code to connect the compiler driver with the appropriate frontend action. The new action is triggered with the `-c` compiler driver flag, i.e. `flang-new -c`. This is then translated to `flang-new -fc1 -emit-obj`, so `-emit-obj` has to be marked as supported as well. As code-generation is not available yet, `flang-new -c` results in a driver error: ``` error: code-generation is not available yet ``` Hopefully this will help communicating the level of available functionality within Flang. The definition of `emit-obj` is updated so that it can be shared between Clang and Flang. As the original definition was enclosed within a Clang-specific TableGen `let` statement, it is extracted into a new `let` statement. That felt like the cleanest option. I also commented out `-triple` in Flang::ConstructJob and updated some comments there. This is similar to https://reviews.llvm.org/D93027. I wanted to make sure that it's clear that we can't support `-triple` until we have code-generation. However, once code-generation is available we _will need_ `-triple`. As this patch adds `-emit-obj`, the emit-obj.f90 becomes irrelevant and is deleted. Instead, phases.f90 is added to demonstrate that users can control compilation phases (indeed, `-c` is a phase control flag). Reviewed By: SouraVX, clementval Differential Revision: https://reviews.llvm.org/D93301
2021-01-06[flang][driver] Add support for `-D`, `-U`Faris Rehman1-2/+67
Add support for options -D and -U in the new Flang driver. Summary of changes: - Create PreprocessorOptions, to be used by the driver then translated into Fortran::parser::Options - Create CompilerInvocation::setFortranOpts to pass preprocessor options into the parser options - Add a dedicated method, Flang::AddPreprocessingOptions, to extract preprocessing options from the driver arguments into the preprocessor command arguments Macros specified like -DName will default to definition 1. When defining macros, the new driver will drop anything after an end-of-line character. This is consistent with gfortran and clang, but different to what currently f18 does. However, flang (which is a bash wrapper for f18), also drops everything after an end-of-line character. So gfortran-like behaviour felt like the natural choice. Test is added to demonstrate this behaviour. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D93401
2020-12-18[flang][driver] Add support for `-fsyntax-only`Andrzej Warzynski1-0/+3
The behaviour triggered with this flag is consistent with `-fparse-only` in `flang` (i.e. the throwaway driver). This new spelling is consistent with Clang and gfortran, and was proposed and agreed on for the new driver in [1]. This patch also adds some minimal logic to communicate whether the semantic checks have failed or not. When semantic checks fail, a frontend driver error is generated. The return code from the frontend driver is then determined by checking the driver diagnostics - the presence of driver errors means that the compilation has failed. This logic is consistent with `clang -cc1`. [1] http://lists.llvm.org/pipermail/flang-dev/2020-November/000588.html Differential Revision: https://reviews.llvm.org/D92854