Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jonas Plewinski
pystencils
Commits
995da7fc
Commit
995da7fc
authored
Oct 15, 2019
by
Stephan Seitz
Browse files
Add option to omit globals when printing C code
parent
9f76ea1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
pystencils/backends/cbackend.py
View file @
995da7fc
...
...
@@ -26,7 +26,11 @@ __all__ = ['generate_c', 'CustomCodeNode', 'PrintNode', 'get_headers', 'CustomSy
KERNCRAFT_NO_TERNARY_MODE
=
False
def
generate_c
(
ast_node
:
Node
,
signature_only
:
bool
=
False
,
dialect
=
'c'
,
custom_backend
=
None
)
->
str
:
def
generate_c
(
ast_node
:
Node
,
signature_only
:
bool
=
False
,
dialect
=
'c'
,
custom_backend
=
None
,
with_globals
=
True
)
->
str
:
"""Prints an abstract syntax tree node as C or CUDA code.
This function does not need to distinguish between C, C++ or CUDA code, it just prints 'C-like' code as encoded
...
...
@@ -65,9 +69,10 @@ def generate_c(ast_node: Node, signature_only: bool = False, dialect='c', custom
raise
ValueError
(
"Unknown dialect: "
+
str
(
dialect
))
code
=
printer
(
ast_node
)
if
not
signature_only
and
isinstance
(
ast_node
,
KernelFunction
):
code
=
"
\n
"
+
code
for
declaration
in
global_declarations
:
code
=
printer
(
declaration
)
+
"
\n
"
+
code
if
with_globals
and
global_declarations
:
code
=
"
\n
"
+
code
for
declaration
in
global_declarations
:
code
=
printer
(
declaration
)
+
"
\n
"
+
code
return
code
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment