From b4f36868f4577ce1b791dba8ca133b0ac8f4f985 Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Fri, 8 Dec 2023 15:56:07 +0100 Subject: [PATCH] Decoupled generator and composers --- integration/CMakeDemo/kernels.py | 6 ++++-- integration/CMakeDemo/more_kernels.py | 5 +++-- integration/MakeDemo/kernels.py | 6 ++++-- integration/TestSequencing.py | 5 +++-- integration/test_classes.py | 5 +++-- src/pystencilssfg/generator.py | 5 ++--- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/integration/CMakeDemo/kernels.py b/integration/CMakeDemo/kernels.py index 5fcac7c..517c7e0 100644 --- a/integration/CMakeDemo/kernels.py +++ b/integration/CMakeDemo/kernels.py @@ -4,10 +4,12 @@ import sympy as sp from pystencils import fields, kernel -from pystencilssfg import SourceFileGenerator +from pystencilssfg import SourceFileGenerator, SfgComposer -with SourceFileGenerator() as sfg: +with SourceFileGenerator() as ctx: + sfg = SfgComposer(ctx) + src, dst = fields("src, dst(1) : double[2D]") @kernel diff --git a/integration/CMakeDemo/more_kernels.py b/integration/CMakeDemo/more_kernels.py index 75b798f..5fbd6ad 100644 --- a/integration/CMakeDemo/more_kernels.py +++ b/integration/CMakeDemo/more_kernels.py @@ -4,10 +4,11 @@ import sympy as sp from pystencils import fields, kernel, Field -from pystencilssfg import SourceFileGenerator +from pystencilssfg import SourceFileGenerator, SfgComposer +with SourceFileGenerator() as ctx: + sfg = SfgComposer(ctx) -with SourceFileGenerator() as sfg: src: Field = fields("src: double[2D]") h = sp.Symbol('h') diff --git a/integration/MakeDemo/kernels.py b/integration/MakeDemo/kernels.py index 310b9bc..43c0f85 100644 --- a/integration/MakeDemo/kernels.py +++ b/integration/MakeDemo/kernels.py @@ -4,14 +4,16 @@ import sympy as sp from pystencils import fields, kernel -from pystencilssfg import SourceFileGenerator, SfgConfiguration +from pystencilssfg import SourceFileGenerator, SfgConfiguration, SfgComposer from pystencilssfg.source_concepts.cpp import mdspan_ref sfg_config = SfgConfiguration( outer_namespace="make_demo" ) -with SourceFileGenerator(sfg_config) as sfg: +with SourceFileGenerator(sfg_config) as ctx: + sfg = SfgComposer(ctx) + sfg.prelude("""Generated by the pystencils Source File Generator. Author: Frederik Hennig <frederik.hennig@fau.de>""") diff --git a/integration/TestSequencing.py b/integration/TestSequencing.py index 9e97052..3a0e040 100644 --- a/integration/TestSequencing.py +++ b/integration/TestSequencing.py @@ -1,9 +1,10 @@ -from pystencilssfg import SourceFileGenerator +from pystencilssfg import SourceFileGenerator, SfgComposer from lbmpy.advanced_streaming import Timestep from lbmpy import LBMConfig, create_lb_ast -with SourceFileGenerator() as sfg: +with SourceFileGenerator() as ctx: + sfg = SfgComposer(ctx) lb_config = LBMConfig(streaming_pattern='esotwist') diff --git a/integration/test_classes.py b/integration/test_classes.py index 40d7098..ecd6b89 100644 --- a/integration/test_classes.py +++ b/integration/test_classes.py @@ -1,5 +1,5 @@ # type: ignore -from pystencilssfg import SourceFileGenerator, SfgConfiguration +from pystencilssfg import SourceFileGenerator, SfgConfiguration, SfgComposer from pystencilssfg.configuration import SfgCodeStyle from pystencilssfg.source_concepts import SrcObject from pystencilssfg.source_components import SfgClass, SfgMemberVariable, SfgConstructor, SfgMethod, SfgVisibility @@ -17,7 +17,8 @@ sfg_config = SfgConfiguration( f, g = fields("f, g(1): double[2D]") -with SourceFileGenerator(sfg_config) as sfg: +with SourceFileGenerator(sfg_config) as ctx: + sfg = SfgComposer(ctx) @kernel def assignments(): diff --git a/src/pystencilssfg/generator.py b/src/pystencilssfg/generator.py index cea341b..6a2038c 100644 --- a/src/pystencilssfg/generator.py +++ b/src/pystencilssfg/generator.py @@ -7,7 +7,6 @@ from os import path from .configuration import SfgConfiguration, config_from_commandline, merge_configurations from .context import SfgContext -from .composer import SfgComposer class SourceFileGenerator: @@ -35,9 +34,9 @@ class SourceFileGenerator: if path.exists(file): os.remove(file) - def __enter__(self): + def __enter__(self) -> SfgContext: self.clean_files() - return SfgComposer(self._context) + return self._context def __exit__(self, exc_type, exc_value, traceback): if exc_type is None: -- GitLab