feat: init functions for address-initialization
This is the first in a series of PRs to enable support for complex initializers (e.g. initializing pointers with hardware addresses/addresses not known before allocation).
This is achieved by lowering these initializers into init-functions for each POU (FUNCTION_BLOCK foo => __init_foo).
Global variables which need initialization are then collected along with init functions for global instances and wrapped in a single __init function, meant to be called by a runtime before starting execution of the main task or, alternatively, called before main. For a more detailed description see tests in src/tests/adr/initializer_functions_adr.rs.
Implemented with this PR:
- generate
__init_<pou>and__initfunctions for programs and function blocks - add support for
REFERENCE TOandx AT yin addition to regularREF_TO/POINTER_TOinitializers - initialize global variables in
__initbody (except for struct-types) - change
ADRbuiltin to behave likeREFwhen assigning the result to a pointer
Since this PR is already quite large, the following features/fixes will be committed separately:
- support for non-POU
STRUCTtypes - pointer references to local members
- stack allocated variable support (
VAR_TEMP, functions) - extend init functionality to generate initializers and subsequent
__init_<pou>calls for each POU instead of relying on the const-evaluator - complex initializers (deeply nested aggregate types, e.g.
ARRAY OF STRUCT, ...) - compiler flag to call
__initbeforemain(use without a dedicated runtime) - add section to book
- additional validation safe-guards
Currently the order in which POUs are declared matters under specific circumstances: when nesting POUs with implicit initializers this can lead to missed instances and will be fixed in a later commit.
In order to support alias pointers (x AT y) their implementation has changed. They are no longer annotated with a StatementAnnotation::ReplacementAst and therefore some of the previously written tests (especially in src/resolver/tests/lowering.rs) might be obsolete now.