# ICON Liskov Architecture
```mermaid
flowchart LR
CMake --> IntegrationClass & PreprocessorDirectives
IntegrationClass & PreprocessorDirectives --> Liskov
Liskov --> IntegrationData
```
- The `Preprocessor` is triggered from within `CMake` from within the `add_gt4py_stencil` function see [Build System Integration](https://hackmd.io/ughej3z0Sfe-AZWBuB5BaQ).
- For the `Preprocessor` to run the annotated `IntegrationFile` must be known (the f90 file with preprocessor directives) which forms one external input into the `Preprocessor`.
- The other possible external input is an `IntegrationClass` which may be a Python module which contains integration information.
```mermaid
flowchart TB
IntegrationData --> IntegrationGenerator & IntegrationWriter
IntegrationGenerator --> IntegrationCode
IntegrationCode --> IntegrationWriter
IntegrationWriter --> F90File
```
- The `Preprocessor` takes any external inputs given, and produces an `IntegrationData` instance, which contains all neccessary information to generate the integration code.
- The `IntegrationGenerator` consumes `IntegrationData` and generates all integration code.
- Finally the original `F90` file is overwritten by the newly generated `F90` file.
### Basic Workflow
**Preprocessor**
1. Main entrypoint needs name of file to preprocess (e.g. `mo_solve_nonhydro.f90`)
2. All `!$DSL` preprocessor directive statements are read along with corresponding locations in the code, this information is used to generate `IntegrationData`.
3. The corresponding stencil is imported from `icon4py` and all required data for generation targets is parsed out from fencil, also used to generate `IntegrationData`.
4. Code generated as string in memory using `IntegrationGenerator` and original file is either overwritten (easiest starting variant), or new file generated with an infix e.g. `mo_solve_nonhydro.dsl.f90`
### Requirements
#### High priority
- A simple grammar for directives (see [Parsing Implementation Notes](https://hackmd.io/aPVBq7egSUChB5-iu_RJQg)).
- Be able to generate all generation targets for simple stencil calls (see [Generation Targets](https://hackmd.io/M9nYjjqHSPK0Ct8YbotRUA)).
- Should be extensible (be able to add additional external inputs or change generation targets).
- Easily executable from within the ICON build system.
#### Future work
- Instead of directives, also allow additional input in the form of an `IntegrationClass`
- Support fusion of different stencils.
- Support more advanced stencils calls, e.g. stencils called inside subroutine).