stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
102 stars 27 forks source link

Use the PSyIR Fortran backend for the NEMO API #435

Closed arporter closed 2 years ago

arporter commented 5 years ago

Currently the NEMO API works by manipulating the fparser2 parse tree and then using the de-parsing functionality of that tree to produce the final Fortran code. Although this has enabled us to get up and running fairly quickly it has limitations. Once the Fortran backend to the PSyIR is sufficiently complete we will migrate the NEMO API to use that.

arporter commented 5 years ago

This Issue will also fix #396.

arporter commented 4 years ago

In #500 I've done some experimentation by adding the following to NemoPSy.gen():

    from psyclone.psyir.backend.fortran import FortranWriter
    fvisitor = FortranWriter()
    result = fvisitor(self._invokes._container)
    return result
arporter commented 4 years ago

In sbcblk.f90 we get a CodeBlock within a WHERE/ELSEWHERE block which results in the script attempting to put KERNELS around the individual statements within the WHERE. This is wrong because they are not implicit loops.

CodeBlock[[<class 'fparser.two.Fortran2003.Masked_Elsewhere_Stmt'>]] comes from:

    ELSEWHERE(phs(:, :, :) <= 0._wp .AND. phi(:, :, :) >= 0.1_wp)
arporter commented 3 years ago

If I do what I said earlier (and allow for cases with a missing Container) then test_api_no_alg shows that we get the body of the routine OK but we have no surrounding Subroutine or Module declaration. Probably the problem is that we have no Container.

arporter commented 3 years ago

We have no Container because this particular test is for a Program which then of course has no enclosing module. We generate an Invoke for the Program and this Invoke has a Schedule which is what enables us to generate the body of the routine. (That Schedule also has an associated symbol table.) However, we have no way of generating the Program declaration.

arporter commented 3 years ago

I now realise this is precisely the problem that #430 is addressing!