This document goes briefly over compiler phases in Flang. It focuses on the internal implementation and as such, it is intended for Flang developers rather than end-users.
.. contents:: :local:
Each phase produces either correct output or fatal errors.
See: Preprocessing.md.
Input: Fortran source and header files, command line macro definitions, set of enabled compiler directives (to be treated as directives rather than comments).
Output:
Entry point: parser::Parsing::Prescan
Command: flang-new -fc1 -E src.f90
dumps the cooked character stream
Input: Cooked character stream.
Output: A parse tree representing a syntactically correct program, rooted at a parser::Program
. See: Parsing.md and ParserCombinators.md.
Entry point: parser::Parsing::Parse
Command:
flang-new -fc1 -fdebug-dump-parse-tree src.f90
dumps the parse treeflang-new -fc1 -fdebug-unparse src.f90
converts the parse tree to normalized FortranInput: Parse tree.
Output: The parse tree with label constraints and construct names checked, and each LabelDoStmt
converted to a NonLabelDoStmt
. See: LabelResolution.md.
Entry points: semantics::ValidateLabels
, parser::CanonicalizeDo
Input: Parse tree (without LabelDoStmt
) and .mod
files from compilation of USEd modules.
Output:
parser::Name::symbol
field points to one of the symbolsparser::TypeSpec::declTypeSpec
field points to one of the typesEntry points: semantics::ResolveNames
, semantics::RewriteParseTree
Command: flang-new -fc1 -fdebug-dump-symbols src.f90
dumps the tree of scopes and symbols in each scope
Input: Parse tree with names resolved.
Output: Parse tree with semantically correct DO CONCURRENT loops.
Input: Parse tree with names resolved.
Output: For each module and submodule, a .mod
file containing a minimal Fortran representation suitable for compiling program units that depend on it. See ModFiles.md.
Input: Parse tree with names resolved.
Output: Parse tree with parser::Expr::typedExpr
filled in and semantic checks performed on all expressions and assignment statements.
Entry points: semantics::AnalyzeExpressions
, semantics::AnalyzeAssignments
Input: Parse tree with names and labels resolved.
Output: An intermediate representation of the executable program. See FortranIR.md.