Skip to content
Snippets Groups Projects
Commit 995da7fc authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Add option to omit globals when printing C code

parent 9f76ea1d
Branches
No related merge requests found
......@@ -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
......
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