forked from M-Labs/artiq
1
0
Fork 0

compiler: generate RPC calls

This commit is contained in:
Sebastien Bourdeauducq 2014-06-16 22:56:08 +02:00
parent 792ac44245
commit 9db8627081
3 changed files with 30 additions and 5 deletions

View File

@ -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

View File

@ -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)))

View File

@ -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