From fda4ee1a8389bd57158ce6f1f9b3263f36fb4a2d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 7 Apr 2015 15:40:25 +0800 Subject: [PATCH] coredevice: add compile method --- artiq/coredevice/core.py | 15 +++++++++------ artiq/transforms/inline.py | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py index 80e41b260..2cceb4a98 100644 --- a/artiq/coredevice/core.py +++ b/artiq/coredevice/core.py @@ -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 diff --git a/artiq/transforms/inline.py b/artiq/transforms/inline.py index 24924a773..0804578d3 100644 --- a/artiq/transforms/inline.py +++ b/artiq/transforms/inline.py @@ -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()