Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils-sfg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils-sfg
Commits
069d274d
Commit
069d274d
authored
4 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
permit modification of code style and clang-format options through the composer/context
parent
d35acf15
No related branches found
No related tags found
1 merge request
!24
Extend Support for CUDA and HIP kernel invocations
Pipeline
#75793
failed
4 months ago
Stage: Code Quality
Stage: Tests
Stage: Documentation
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/source/_util/sfg_monkeypatch.py
+3
-2
3 additions, 2 deletions
docs/source/_util/sfg_monkeypatch.py
src/pystencilssfg/context.py
+9
-1
9 additions, 1 deletion
src/pystencilssfg/context.py
src/pystencilssfg/generator.py
+12
-9
12 additions, 9 deletions
src/pystencilssfg/generator.py
with
24 additions
and
12 deletions
docs/source/_util/sfg_monkeypatch.py
+
3
−
2
View file @
069d274d
...
...
@@ -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
"
...
...
This diff is collapsed.
Click to expand it.
src/pystencilssfg/context.py
+
9
−
1
View file @
069d274d
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/pystencilssfg/generator.py
+
12
−
9
View file @
069d274d
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment