Skip to content

Source processing flow

Ben Orchard edited this page Jul 28, 2022 · 5 revisions

An overview of the operations fortran-src does on Fortran source.

Current (0.10.0)

fortran-src's default "parse Fortran source code" operation does the following:

  1. Lex & parse (simultaneous)
  2. Post-parse transform

Post-parse transformation alters the AST, but not annotations. Internally, it performs a temporary renaming pass, then a temporary type analysis pass, then runs the transformations in sequence with annotations available, and finally discards the analysis and renamings.

Type checking depends on some post-parse transformations for correctness (the subscript disambiguation, and intrinsics disambiguation) With type checking (--typecheck CLI, analyseTypes library), after parsing:

  1. Type analysis
    • Gathers type information on 4 separate traversals through the entire ProgramFile
    • Uses gathered information to "annotate" Expressions and ProgramUnits: involves evaluating expression types e.g. real + int = real
    • Types are a mix of BaseType + other syntax tags, and fortran-vars SemanticTypes which include kind

Basic block analysis must run after transformations, but is separate from type analysis.

  1. Basic block analysis

Dataflow analyses may run after the basic block analysis.

  1. Dataflow analysis
    1. Live variable analysis
    2. Constant expression analysis
      • Gathers explicit constants (PARAMETER variables)
      • Evaluates a handful of literals and binops

Points of interest

  • The implicit type analysis isn't ideal. We should be able to identify the exact set of syntax analysis required to perform these post-parse transformations, and do only that.
    • Or perhaps these transformations could take place in-line, inside the main syntax analysis?
    • It gets even worse as we do more work during type analysis - perhaps we could make these analyses a bit configurable to work around that.
  • Parts of the constant expression analysis should be done earlier. Explicit constant variables (PARAMETERs) may be used in types as kind parameters, so we should gather that info during type analysis.
Clone this wiki locally