Skip to content
Snippets Groups Projects
Commit 069d274d authored by Frederik Hennig's avatar Frederik Hennig
Browse files

permit modification of code style and clang-format options through the composer/context

parent d35acf15
Branches
1 merge request!24Extend Support for CUDA and HIP kernel invocations
Pipeline #75793 failed with stages
in 5 minutes and 13 seconds
......@@ -30,8 +30,9 @@ class DocsPatchedGenerator(pystencilssfg.SourceFileGenerator):
def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
self._finish_files()
emitter = self._get_emitter()
header_code = self._emitter.dumps(self._header_file)
header_code = emitter.dumps(self._header_file)
header_ext = splitext(self._header_file.name)[1]
mdcode = ":::::{tab-set}\n"
......@@ -42,7 +43,7 @@ class DocsPatchedGenerator(pystencilssfg.SourceFileGenerator):
mdcode += "\n:::\n::::\n"
if self._impl_file is not None:
impl_code = self._emitter.dumps(self._impl_file)
impl_code = emitter.dumps(self._impl_file)
impl_ext = splitext(self._impl_file.name)[1]
mdcode += f"::::{{tab-item}} Generated Implementation ({impl_ext})\n"
......
......@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import Sequence, Any, Generator
from contextlib import contextmanager
from .config import CodeStyle
from .config import CodeStyle, ClangFormatOptions
from .ir import (
SfgSourceFile,
SfgNamespace,
......@@ -23,6 +23,7 @@ class SfgContext:
impl_file: SfgSourceFile | None,
namespace: str | None = None,
codestyle: CodeStyle | None = None,
clang_format_opts: ClangFormatOptions | None = None,
argv: Sequence[str] | None = None,
project_info: Any = None,
):
......@@ -33,6 +34,9 @@ class SfgContext:
self._inner_namespace: str | None = None
self._codestyle = codestyle if codestyle is not None else CodeStyle()
self._clang_format: ClangFormatOptions = (
clang_format_opts if clang_format_opts is not None else ClangFormatOptions()
)
self._header_file = header_file
self._impl_file = impl_file
......@@ -73,6 +77,10 @@ class SfgContext:
"""The code style object for this generation context."""
return self._codestyle
@property
def clang_format(self) -> ClangFormatOptions:
return self._clang_format
@property
def header_file(self) -> SfgSourceFile:
return self._header_file
......
......@@ -95,9 +95,7 @@ class SourceFileGenerator:
self._impl_file = SfgSourceFile(
output_files[1].name, SfgSourceFileType.TRANSLATION_UNIT
)
self._impl_file.includes.append(
HeaderFile.parse(self._header_file.name)
)
self._impl_file.includes.append(HeaderFile.parse(self._header_file.name))
# TODO: Find a way to not hard-code the restrict qualifier in pystencils
self._header_file.elements.append("#define RESTRICT __restrict__")
......@@ -115,14 +113,11 @@ class SourceFileGenerator:
self._impl_file,
namespace,
config.codestyle,
config.clang_format,
argv=script_args,
project_info=cli_params.get_project_info(),
)
self._emitter = SfgCodeEmitter(
self._output_dir, config.codestyle, config.clang_format
)
sort_key = config.codestyle.get_option("includes_sorting_key")
if sort_key is None:
......@@ -161,6 +156,13 @@ class SourceFileGenerator:
)
self._impl_file.includes.sort(key=self._include_sort_key)
def _get_emitter(self):
return SfgCodeEmitter(
self._output_dir,
self._context.codestyle,
self._context.clang_format,
)
def __enter__(self) -> SfgComposer:
self.clean_files()
return SfgComposer(self._context)
......@@ -169,6 +171,7 @@ class SourceFileGenerator:
if exc_type is None:
self._finish_files()
self._emitter.emit(self._header_file)
emitter = self._get_emitter()
emitter.emit(self._header_file)
if self._impl_file is not None:
self._emitter.emit(self._impl_file)
emitter.emit(self._impl_file)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment