forked from M-Labs/artiq
compiler: generate RPC calls
This commit is contained in:
parent
792ac44245
commit
9db8627081
|
@ -35,6 +35,7 @@ class _ReferenceManager:
|
||||||
self.to_inlined = dict()
|
self.to_inlined = dict()
|
||||||
# inlined_name -> use_count
|
# inlined_name -> use_count
|
||||||
self.use_count = dict()
|
self.use_count = dict()
|
||||||
|
self.rpc_map = defaultdict(lambda: len(self.rpc_map))
|
||||||
|
|
||||||
# reserved names
|
# reserved names
|
||||||
self.use_count["Quantity"] = 1
|
self.use_count["Quantity"] = 1
|
||||||
|
@ -126,9 +127,12 @@ class _ReferenceReplacer(ast.NodeTransformer):
|
||||||
elif hasattr(func, "k_function_info"):
|
elif hasattr(func, "k_function_info"):
|
||||||
print(func.k_function_info)
|
print(func.k_function_info)
|
||||||
# TODO: inline called kernel
|
# TODO: inline called kernel
|
||||||
|
return node
|
||||||
self.generic_visit(node)
|
else:
|
||||||
return node
|
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):
|
class _ListReadOnlyParams(ast.NodeVisitor):
|
||||||
def visit_FunctionDef(self, node):
|
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
|
funcdef.body[0:0] = param_init
|
||||||
|
|
||||||
return funcdef.body
|
return funcdef.body, rm.rpc_map
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
from artiq.compiler.inline import inline
|
from artiq.compiler.inline import inline
|
||||||
from artiq.compiler.unparse import Unparser
|
from artiq.compiler.unparse import Unparser
|
||||||
|
|
||||||
class Core:
|
class Core:
|
||||||
def run(self, k_function, k_args, k_kwargs):
|
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)
|
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)))
|
||||||
|
|
|
@ -6,10 +6,17 @@ my_range = range
|
||||||
class CompilerTest(Experiment):
|
class CompilerTest(Experiment):
|
||||||
channels = "core a b A B"
|
channels = "core a b A B"
|
||||||
|
|
||||||
|
def print_done(self):
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
def print_iter(self, n):
|
||||||
|
print("Iteration: {}".format(n))
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self, n, t2):
|
def run(self, n, t2):
|
||||||
t2 += 1*us
|
t2 += 1*us
|
||||||
for i in my_range(n):
|
for i in my_range(n):
|
||||||
|
self.print_iter(i)
|
||||||
with parallel:
|
with parallel:
|
||||||
with sequential:
|
with sequential:
|
||||||
self.a.pulse(100*MHz, 20*us)
|
self.a.pulse(100*MHz, 20*us)
|
||||||
|
@ -17,6 +24,7 @@ class CompilerTest(Experiment):
|
||||||
with sequential:
|
with sequential:
|
||||||
self.A.pulse(100*MHz, 10*us)
|
self.A.pulse(100*MHz, 10*us)
|
||||||
self.B.pulse(100*MHz, t2)
|
self.B.pulse(100*MHz, t2)
|
||||||
|
self.print_done()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from artiq.devices import core, core_dds
|
from artiq.devices import core, core_dds
|
||||||
|
|
Loading…
Reference in New Issue