diff --git a/artiq/compiler/inline.py b/artiq/compiler/inline.py index 7303e54be..9c45ef484 100644 --- a/artiq/compiler/inline.py +++ b/artiq/compiler/inline.py @@ -35,6 +35,7 @@ class _ReferenceManager: self.to_inlined = dict() # inlined_name -> use_count self.use_count = dict() + self.rpc_map = defaultdict(lambda: len(self.rpc_map)) # reserved names self.use_count["Quantity"] = 1 @@ -126,9 +127,12 @@ class _ReferenceReplacer(ast.NodeTransformer): elif hasattr(func, "k_function_info"): print(func.k_function_info) # TODO: inline called kernel - - self.generic_visit(node) - return node + return node + else: + args = [ast.Str("rpc"), ast.Num(self.rm.rpc_map[func])] + args += [self.visit(arg) for arg in node.args] + return ast.Call(func=ast.Name("syscall", ast.Load()), + args=args, keywords=[], starargs=None, kwargs=None) class _ListReadOnlyParams(ast.NodeVisitor): def visit_FunctionDef(self, node): @@ -180,4 +184,4 @@ def inline(k_function, k_args, k_kwargs, rm=None): funcdef.body[0:0] = param_init - return funcdef.body + return funcdef.body, rm.rpc_map diff --git a/artiq/devices/core.py b/artiq/devices/core.py index 7b7e192f5..8c7fd30eb 100644 --- a/artiq/devices/core.py +++ b/artiq/devices/core.py @@ -1,7 +1,20 @@ +from operator import itemgetter + from artiq.compiler.inline import inline from artiq.compiler.unparse import Unparser class Core: def run(self, k_function, k_args, k_kwargs): - stmts = inline(k_function, k_args, k_kwargs) + stmts, rpc_map = inline(k_function, k_args, k_kwargs) + + print("=========================") + print(" Inlined") + print("=========================") Unparser(stmts) + + print("") + print("=========================") + print(" RPC map") + print("=========================") + for rpc_func, rpc_num in sorted(rpc_map.items(), key=itemgetter(1)): + print("{:3} -> {}".format(rpc_num, str(rpc_func))) diff --git a/examples/compiler_test.py b/examples/compiler_test.py index 5f418cf75..504cd433a 100644 --- a/examples/compiler_test.py +++ b/examples/compiler_test.py @@ -6,10 +6,17 @@ my_range = range class CompilerTest(Experiment): channels = "core a b A B" + def print_done(self): + print("Done!") + + def print_iter(self, n): + print("Iteration: {}".format(n)) + @kernel def run(self, n, t2): t2 += 1*us for i in my_range(n): + self.print_iter(i) with parallel: with sequential: self.a.pulse(100*MHz, 20*us) @@ -17,6 +24,7 @@ class CompilerTest(Experiment): with sequential: self.A.pulse(100*MHz, 10*us) self.B.pulse(100*MHz, t2) + self.print_done() if __name__ == "__main__": from artiq.devices import core, core_dds