Skip to content
Snippets Groups Projects
Commit 49ea0d3d authored by Martin Bauer's avatar Martin Bauer
Browse files

Merge branch 'omit-globals-when-printing-c-code' into 'master'

Add option to omit globals when printing C code

See merge request !75
parents 09a59f7f 995da7fc
1 merge request!75Add option to omit globals when printing C code
Pipeline #19041 canceled with stages
......@@ -25,7 +25,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
......@@ -64,9 +68,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
......
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