Skip to content
Snippets Groups Projects
Commit d8072b06 authored by Markus Holzer's avatar Markus Holzer
Browse files

Generated C Code only once

parent 1593e3f2
No related branches found
No related tags found
1 merge request!226Fix field size
......@@ -494,12 +494,13 @@ def run_compile_step(command):
class ExtensionModuleCode:
def __init__(self, module_name='generated', custom_backend=None):
def __init__(self, module_name='generated', custom_backend=None, generated_code=None):
self.module_name = module_name
self._ast_nodes = []
self._function_names = []
self._custom_backend = custom_backend
self._generated_code = generated_code
def add_function(self, ast, name=None):
self._ast_nodes.append(ast)
......@@ -523,7 +524,10 @@ class ExtensionModuleCode:
for ast, name in zip(self._ast_nodes, self._function_names):
old_name = ast.function_name
ast.function_name = "kernel_" + name
print(generate_c(ast, custom_backend=self._custom_backend), file=file)
if self._generated_code:
print(self._generated_code, file=file)
else:
print(generate_c(ast, custom_backend=self._custom_backend), file=file)
print(create_function_boilerplate_code(ast.get_parameters(), name, ast), file=file)
ast.function_name = old_name
print(create_module_boilerplate_code(self.module_name, self._function_names), file=file)
......@@ -590,7 +594,7 @@ def compile_and_load(ast, custom_backend=None):
# Also the information of the field size should be contained in the hash string. Due to padding the generated code
# can look similar for different field sizes.
code_hash_str = "mod_" + hashlib.sha256((generated_code + fields_accessed).encode()).hexdigest()
code = ExtensionModuleCode(module_name=code_hash_str, custom_backend=custom_backend)
code = ExtensionModuleCode(module_name=code_hash_str, custom_backend=custom_backend, generated_code=generated_code)
code.add_function(ast, ast.function_name)
if cache_config['object_cache'] is False:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment