Commit graph

881 commits

Author SHA1 Message Date
Tim Keith
f62f8b655d [flang] Implement reading of module files
When a use-stmt is encountered for a module that isn't in the global
scope, search for and read the appropriate `.mod` file. To perform the
search, pass the search directories in to ResolveNames.

For modules that were read from `.mod` files, we have to keep the cooked
source from being deleted so that the names so that references to names
stay valid. So we store the cooked source in the Scope of the module as
a `unique_ptr`.

Add `Symbol::Flag::ModFile` to distinguish module symbols that were read
from a `.mod` file rather than from the current compilation. Use it to
prevent writing those back out.

Fix test_errors.sh to run the compiler in the temp subdirectory --
otherwise tests could be affected by `.mod` files left from previous
tests.

Original-commit: flang-compiler/f18@207065999c
Reviewed-on: https://github.com/flang-compiler/f18/pull/145
2018-07-25 10:11:38 -07:00
Peter Klausler
9381c34f61 [flang] Merge pull request flang-compiler/f18#144 from flang-compiler/pmk0
Checkpoint development of expression analysis

Original-commit: flang-compiler/f18@a32c16f895
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
2018-07-25 09:33:37 -07:00
peter klausler
dda1d4c959 [flang] Fix typo
Original-commit: flang-compiler/f18@b9837c01da
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
2018-07-24 15:50:38 -07:00
peter klausler
7f484d7011 [flang] real expression folding
Original-commit: flang-compiler/f18@8757dc2c90
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:57 -07:00
peter klausler
35ad0036aa [flang] checkpoint
Original-commit: flang-compiler/f18@fc470dc851
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:57 -07:00
peter klausler
943b50289b [flang] Real->Integer conversion folding
Original-commit: flang-compiler/f18@5ad6505e78
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:55 -07:00
peter klausler
61c45394c0 [flang] Parameterize Expr on a type, not category+kind
Original-commit: flang-compiler/f18@f29b065d00
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:55 -07:00
peter klausler
2eac1d0475 [flang] Better folding infrastructure checkpoint
Original-commit: flang-compiler/f18@85d16ace6c
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:55 -07:00
peter klausler
e4f12b087c [flang] Be more clear that constants in expressions are scalars now.
Original-commit: flang-compiler/f18@3181b8d961
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:54 -07:00
peter klausler
9a503392b4 [flang] reformat
Original-commit: flang-compiler/f18@3c93a9edbc
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:53 -07:00
peter klausler
0aae9893a5 [flang] checkpoint
Original-commit: flang-compiler/f18@7fae33797a
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:53 -07:00
peter klausler
aa6c6f97a9 [flang] Begin semantic analysis of expressions.
Original-commit: flang-compiler/f18@34615fdc37
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:52 -07:00
peter klausler
557ba58708 [flang] Use const_cast instead of static_cast for clarity.
Original-commit: flang-compiler/f18@b76ba42af0
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:51 -07:00
peter klausler
efb0fd8753 [flang] More comments about 0**0.
Original-commit: flang-compiler/f18@3e9c0e8894
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:50 -07:00
peter klausler
ac01d216fb [flang] 0**0 case
Original-commit: flang-compiler/f18@fcba49ce6f
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:49 -07:00
peter klausler
ceaff4f498 [flang] Fold integer powers
Original-commit: flang-compiler/f18@6a9ec4d76b
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:48 -07:00
peter klausler
50480bc987 [flang] Better folding.
Original-commit: flang-compiler/f18@4a3117968a
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:47 -07:00
peter klausler
05f0e2f7ec [flang] Finish data hiding in variable.h.
Original-commit: flang-compiler/f18@5979330322
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:46 -07:00
peter klausler
006642f98a [flang] more data hiding
Original-commit: flang-compiler/f18@2dc0d046e3
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:45 -07:00
peter klausler
7dbc09357e [flang] Pull indirection into some constructors.
Original-commit: flang-compiler/f18@074e249499
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:44 -07:00
peter klausler
2f8baf1835 [flang] Data hiding
Original-commit: flang-compiler/f18@d33426637a
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:44 -07:00
peter klausler
f24cd7dd2d [flang] checkpoint once everything builds again
Original-commit: flang-compiler/f18@2075b88772
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:43 -07:00
peter klausler
6c4773012c [flang] issue#134
Original-commit: flang-compiler/f18@a40c38bdb5
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
2018-07-24 14:33:42 -07:00
Peter Klausler
cd8ca3f625 [flang] Merge pull request flang-compiler/f18#143 from flang-compiler/pmk1
issue#142 fix

Original-commit: flang-compiler/f18@69c72ac955
Reviewed-on: https://github.com/flang-compiler/f18/pull/143
2018-07-24 14:30:29 -07:00
peter klausler
997e09bebd [flang] issue#142, some refactoring of common patterns in basic-parsers.h, and reformatting
Original-commit: flang-compiler/f18@1faad40678
Reviewed-on: https://github.com/flang-compiler/f18/pull/143
2018-07-24 13:51:27 -07:00
hsuauthai
d4e5882796 [flang] Merge pull request flang-compiler/f18#140 from flang-compiler/omppar
Add predefined macro _OPENMP to 201511  - yyyymm of the OpenMP 4.5 Spec.

Original-commit: flang-compiler/f18@7b05195132
Reviewed-on: https://github.com/flang-compiler/f18/pull/140
2018-07-23 11:22:30 -07:00
Hongyon Suauthai
9d24bf5f53 [flang] Add predefined macro _OPENMP to 201511 - yyyymm of the OpenMP Spec.
Original-commit: flang-compiler/f18@859912b54e
Reviewed-on: https://github.com/flang-compiler/f18/pull/140
2018-07-23 10:43:44 -07:00
hsuauthai
08b2684271 [flang] Merge pull request flang-compiler/f18#137 from flang-compiler/omppar
Omppar

Original-commit: flang-compiler/f18@d341464e7f
Reviewed-on: https://github.com/flang-compiler/f18/pull/137

Due to a conflicting rebase during the linearizing of flang-compiler/f18, this commit squashes a number of other commits:

flang-compiler/f18@cfbc8bd16b Add OpenMP Block directives and some declarative directive(TBD:declare reduction and declare target)
flang-compiler/f18@d198352f84 Removed extra code from resolveing conflict of the merge.
flang-compiler/f18@85911a0e80 fix some grammar and unparsing.
flang-compiler/f18@43bcfb7cd3 OpenMP declartive directive can be after function declaration line. OpenMP Loop construct will be treated as if statement instead of block because currently parser cannot construct the loop if loop end with Label [Continue] Use DefinedOperator and ProcedureDesignator instead of create a new Parser and postpone the validity of operator in semantic.
flang-compiler/f18@5d83b50ad3 Merge branch 'master' into omppar
flang-compiler/f18@8c666436a5 remove "HEAD" code and resolve conflict.
2018-07-20 15:49:19 -07:00
Tim Keith
698581c784 [flang] Merge pull request flang-compiler/f18#132 from flang-compiler/tsk5
Support writing interfaces in module files.

Original-commit: flang-compiler/f18@7d635193a8
Reviewed-on: https://github.com/flang-compiler/f18/pull/132
2018-07-20 10:58:56 -07:00
Tim Keith
dded0e4bb2 [flang] Correctly resolve generics with forward references
When a procedure is included by name in a generic (either with a
procedure statement in a generic interface or with a generic statement)
we can't immediately resolve it to a subprogram symbol. That is because
the subprogram may be defined later in the specification part. Instead,
collect the names (and whether they should be module procedures) and
resolve them to symbols at the end of the specification part. Also
detect duplicate names then.

This is needed for module file reading as these forward references can
occur there.

Write generics to module file using generic statements. This allows us to
include the access-spec.

Original-commit: flang-compiler/f18@d11d002084
Reviewed-on: https://github.com/flang-compiler/f18/pull/132
2018-07-20 10:46:11 -07:00
Tim Keith
759a405a43 [flang] Support writing interfaces in module files.
Write symbols for external subprogram interfaces as interface-stmts.
Those go in the decls part of the module file, as opposed to contained
subprograms which go in the contains part. See modfile06.f90.

Write symbols with GenericDetails to module files. The specific
procedures of a generic interface are always written as procedure-stmts.
If they also have specific interfaces those are written in a separate
interface-stmt. See modfile07.f90.

Fix a bug where `real, external :: f` was not written like
`real f; external f`. We have to notice the EXTERNAL attribute on the
type-declaration-stmt and convert the entity to a procedure entity.
See modfile08.f90.

Fix a bug where a use-associated symbol is referenced in a
procedure-designator. We were not resolving that correctly.

Change ModFileWriter::PutEntity to include the kind of Details when
it reports an internal error due to a kind it can't handle.
Make DetailsToString public to support that.

Change test_errors.sh to fail if the f18 command exits due to a signal.
We were missing bugs where the correct errors were written out but then
module file writing crashed (due to failure to handle generics mentioned
above). Non-zero exit status is okay because we are expecting
compilation errors.

Change test_modfile.sh to allow for the expected module file contents to
be indented so the tests are easier to read.

Original-commit: flang-compiler/f18@82a7931e51
Reviewed-on: https://github.com/flang-compiler/f18/pull/132
Tree-same-pre-rewrite: false
2018-07-19 13:28:24 -07:00
Peter Klausler
ce3338bcdc [flang] Merge pull request flang-compiler/f18#133 from flang-compiler/pmk1
Fix remaining bugs with backslash escapes in character literals

Original-commit: flang-compiler/f18@8c41f0123d
Reviewed-on: https://github.com/flang-compiler/f18/pull/133
2018-07-20 09:33:15 -07:00
peter klausler
5bd2ac4952 [flang] Pass -Mnobackslash to pgf90 unless f18 -fbackslash is used.
Original-commit: flang-compiler/f18@df5058ff97
Reviewed-on: https://github.com/flang-compiler/f18/pull/133
2018-07-19 15:50:39 -07:00
peter klausler
d7f5aa55e8 [flang] prep for merge
Original-commit: flang-compiler/f18@fa72384520
Reviewed-on: https://github.com/flang-compiler/f18/pull/133
Tree-same-pre-rewrite: false
2018-07-19 15:42:00 -07:00
peter klausler
888786b346 [flang] Really fix backslash escapes.
Original-commit: flang-compiler/f18@a8c702c103
Reviewed-on: https://github.com/flang-compiler/f18/pull/133
Tree-same-pre-rewrite: false
2018-07-19 15:35:55 -07:00
Peter Klausler
d1bf9e1fe2 [flang] Merge pull request flang-compiler/f18#130 from flang-compiler/pmk1
Roll up parsing changes for several topics

Original-commit: flang-compiler/f18@57e051eafa
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
2018-07-19 09:55:24 -07:00
peter klausler
8119fe881d [flang] Ready for merge.
Original-commit: flang-compiler/f18@f39949fc7d
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
2018-07-19 09:54:24 -07:00
peter klausler
d100bcbc9f [flang] Do not enable OpenMP by default, oops.
Original-commit: flang-compiler/f18@7a627ac040
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:24 -07:00
peter klausler
80ece7418a [flang] Define LanguageFeatureControl, use it everywhere.
Original-commit: flang-compiler/f18@9a95107610
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:24 -07:00
peter klausler
f701b42920 [flang] Better language feature enablement and warnings.
Original-commit: flang-compiler/f18@359e4d2c60
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:23 -07:00
peter klausler
31cfbeab42 [flang] Another SUBMODULE unparsing tweak, and restore buildability with gcc < 8.1
Original-commit: flang-compiler/f18@86b5db4b23
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:22 -07:00
peter klausler
1732d043e2 [flang] Fix clang build warning in mod-file.cc
Original-commit: flang-compiler/f18@53ad3bd59c
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:22 -07:00
peter klausler
5b25aad67c [flang] Address issue#125, flang-compiler/f18#115, and improve error recovery on previous issues.
Original-commit: flang-compiler/f18@98e26d6245
Reviewed-on: https://github.com/flang-compiler/f18/pull/130
Tree-same-pre-rewrite: false
2018-07-19 09:54:21 -07:00
Tim Keith
737e6eaf37 [flang] Merge pull request flang-compiler/f18#131 from flang-compiler/tsk2
Update module file documentation

Original-commit: flang-compiler/f18@8981007d1c
Reviewed-on: https://github.com/flang-compiler/f18/pull/131
2018-07-19 07:52:34 -07:00
Tim Keith
6568929bf5 [flang] Update module file documentation
Address some review comments, add more information.

Original-commit: flang-compiler/f18@75c97b6f9b
Reviewed-on: https://github.com/flang-compiler/f18/pull/131
2018-07-18 12:39:34 -07:00
Tim Keith
a695afd042 [flang] Merge pull request flang-compiler/f18#127 from flang-compiler/tsk5
Use brace initialization with auto

Original-commit: flang-compiler/f18@f767ea2e1a
Reviewed-on: https://github.com/flang-compiler/f18/pull/127
2018-07-18 06:58:33 -07:00
Tim Keith
cde0b5cc87 [flang] Use brace initialization in tools/f18
Also reformat dump.cc.

Original-commit: flang-compiler/f18@1cc4fe2788
Reviewed-on: https://github.com/flang-compiler/f18/pull/127
2018-07-17 07:05:35 -07:00
Tim Keith
7400a287a1 [flang] Use brace initialization in lib/semantics
Syntax only, no functional changes.

Original-commit: flang-compiler/f18@8cc9743c9c
Reviewed-on: https://github.com/flang-compiler/f18/pull/127
Tree-same-pre-rewrite: false
2018-07-17 07:02:30 -07:00
Tim Keith
6e3e9bf51e [flang] Merge pull request flang-compiler/f18#129 from flang-compiler/tsk2
Fix test script portability problems.

Original-commit: flang-compiler/f18@e7f83218a3
Reviewed-on: https://github.com/flang-compiler/f18/pull/129
2018-07-17 17:21:55 -07:00
Tim Keith
bfd0703234 [flang] Fix test script portability problems.
Allow for bash anywhere on path.

Allow for utilites to be in /bin as well as /usr/bin.

Don't count on sed understanding '\t'.

The options to mktemp aren't portable. Instead just create a per-test
temp directory in the working directory (i.e. <build-dir>/test/semantics).
Setting the KEEP environment variable causes them all to be kept to help
in investigating failures.

Fixes flang-compiler/f18#128.

Original-commit: flang-compiler/f18@3736ceeca8
Reviewed-on: https://github.com/flang-compiler/f18/pull/129
2018-07-17 16:48:50 -07:00