Andrzej Warzynski 96d229c9ab [flang][driver] Add options for unparsing
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-16 09:32:51 +00:00

93 lines
1.5 KiB
Fortran

! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
!CHECK-NOT: error:
module mm
interface
module subroutine m(n)
end
end interface
end module mm
program p
use mm
20 print*, 'p'
21 call p1
22 call p2
23 f0 = f(0); print '(f5.1)', f0
24 f1 = f(1); print '(f5.1)', f1
25 call s(0); call s(1)
26 call m(0); call m(1)
27 if (.false.) goto 29
28 print*, 'px'
contains
subroutine p1
print*, 'p1'
goto 29
29 end subroutine p1
subroutine p2
print*, 'p2'
goto 29
29 end subroutine p2
29 end
function f(n)
print*, 'f'
31 call f1
32 call f2
f = 30.
if (n == 0) goto 39
f = f + 3.
print*, 'fx'
contains
subroutine f1
print*, 'f1'
goto 39
39 end subroutine f1
subroutine f2
print*, 'f2'
goto 39
39 end subroutine f2
39 end
subroutine s(n)
print*, 's'
41 call s1
42 call s2
43 call s3
if (n == 0) goto 49
print*, 'sx'
contains
subroutine s1
print*, 's1'
goto 49
49 end subroutine s1
subroutine s2
print*, 's2'
goto 49
49 end subroutine s2
subroutine s3
print*, 's3'
goto 49
49 end subroutine s3
49 end
submodule(mm) mm1
contains
module procedure m
print*, 'm'
50 call m1
51 call m2
if (n == 0) goto 59
print*, 'mx'
contains
subroutine m1
print*, 'm1'
goto 59
59 end subroutine m1
subroutine m2
print*, 'm2'
goto 59
59 end subroutine m2
59 end procedure m
end submodule mm1