2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 11:18:27 +08:00

coredevice: add compile method

This commit is contained in:
Sebastien Bourdeauducq 2015-04-07 15:40:25 +08:00
parent 5e046dc5ce
commit fda4ee1a83
2 changed files with 13 additions and 9 deletions

View File

@ -103,20 +103,23 @@ class Core(AutoDB):
remove_dead_code(func_def)
debug_unparse("remove_dead_code_2", func_def)
def run(self, k_function, k_args, k_kwargs):
# transform/simplify AST
def compile(self, k_function, k_args, k_kwargs, with_attr_writeback=True):
debug_unparse = _make_debug_unparse("remove_dead_code_2")
func_def, rpc_map, exception_map = inline(
self, k_function, k_args, k_kwargs)
self, k_function, k_args, k_kwargs, with_attr_writeback)
debug_unparse("inline", func_def)
self.transform_stack(func_def, rpc_map, exception_map, debug_unparse)
# compile to machine code and run
binary = get_runtime_binary(self.runtime_env, func_def)
return binary, rpc_map, exception_map
def run(self, k_function, k_args, k_kwargs):
binary, rpc_map, exception_map = self.compile(
k_function, k_args, k_kwargs)
self.comm.load(binary)
self.comm.run(func_def.name)
self.comm.run(k_function.__name__)
self.comm.serve(rpc_map, exception_map)
@kernel

View File

@ -467,7 +467,7 @@ def get_attr_writeback(attribute_namespace, rpc_mapper, loc_node):
return attr_writeback
def inline(core, k_function, k_args, k_kwargs):
def inline(core, k_function, k_args, k_kwargs, with_attr_writeback):
# OrderedDict prevents non-determinism in attribute init
attribute_namespace = OrderedDict()
in_use_names = copy(embeddable_func_names)
@ -486,7 +486,8 @@ def inline(core, k_function, k_args, k_kwargs):
kwargs=k_kwargs)
func_def.body[0:0] = get_attr_init(attribute_namespace, func_def)
func_def.body += get_attr_writeback(attribute_namespace, mappers.rpc,
func_def)
if with_attr_writeback:
func_def.body += get_attr_writeback(attribute_namespace, mappers.rpc,
func_def)
return func_def, mappers.rpc.get_map(), mappers.exception.get_map()