forked from M-Labs/artiq
1
0
Fork 0

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) remove_dead_code(func_def)
debug_unparse("remove_dead_code_2", func_def) debug_unparse("remove_dead_code_2", func_def)
def run(self, k_function, k_args, k_kwargs): def compile(self, k_function, k_args, k_kwargs, with_attr_writeback=True):
# transform/simplify AST
debug_unparse = _make_debug_unparse("remove_dead_code_2") debug_unparse = _make_debug_unparse("remove_dead_code_2")
func_def, rpc_map, exception_map = inline( 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) debug_unparse("inline", func_def)
self.transform_stack(func_def, rpc_map, exception_map, debug_unparse) 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) 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.load(binary)
self.comm.run(func_def.name) self.comm.run(k_function.__name__)
self.comm.serve(rpc_map, exception_map) self.comm.serve(rpc_map, exception_map)
@kernel @kernel

View File

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