forked from M-Labs/artiq
1
0
Fork 0

inline: check inlined functions are on the same core device

This commit is contained in:
Sebastien Bourdeauducq 2014-06-17 18:52:48 +02:00
parent 08ab99d33e
commit 0d9bdc101c
2 changed files with 7 additions and 6 deletions

View File

@ -107,7 +107,8 @@ _embeddable_calls = {
} }
class _ReferenceReplacer(ast.NodeTransformer): class _ReferenceReplacer(ast.NodeTransformer):
def __init__(self, rm, obj, funcname): def __init__(self, core, rm, obj, funcname):
self.core = core
self.rm = rm self.rm = rm
self.obj = obj self.obj = obj
self.funcname = funcname self.funcname = funcname
@ -131,9 +132,9 @@ class _ReferenceReplacer(ast.NodeTransformer):
new_func = ast.Name(func.__name__, ast.Load()) new_func = ast.Name(func.__name__, ast.Load())
return ast.Call(func=new_func, args=new_args, return ast.Call(func=new_func, args=new_args,
keywords=[], starargs=None, kwargs=None) keywords=[], starargs=None, kwargs=None)
elif hasattr(func, "k_function_info"): elif hasattr(func, "k_function_info") and getattr(func.__self__, func.k_function_info.core_name) is self.core:
args = [func.__self__] + new_args args = [func.__self__] + new_args
inlined, _ = inline(func.k_function_info.k_function, args, dict(), self.rm) inlined, _ = inline(self.core, func.k_function_info.k_function, args, dict(), self.rm)
return inlined return inlined
else: else:
args = [ast.Str("rpc"), ast.Num(self.rm.rpc_map[func])] args = [ast.Str("rpc"), ast.Num(self.rm.rpc_map[func])]
@ -192,7 +193,7 @@ def _initialize_function_params(funcdef, k_args, k_kwargs, rm):
param_init.append(ast.Assign(targets=[target], value=value)) param_init.append(ast.Assign(targets=[target], value=value))
return param_init return param_init
def inline(k_function, k_args, k_kwargs, rm=None): def inline(core, k_function, k_args, k_kwargs, rm=None):
if rm is None: if rm is None:
rm = _ReferenceManager() rm = _ReferenceManager()
@ -202,7 +203,7 @@ def inline(k_function, k_args, k_kwargs, rm=None):
obj = k_args[0] obj = k_args[0]
funcname = funcdef.name funcname = funcdef.name
rr = _ReferenceReplacer(rm, obj, funcname) rr = _ReferenceReplacer(core, rm, obj, funcname)
rr.visit(funcdef) rr.visit(funcdef)
funcdef.body[0:0] = param_init funcdef.body[0:0] = param_init

View File

@ -5,7 +5,7 @@ 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, rpc_map = inline(k_function, k_args, k_kwargs) stmts, rpc_map = inline(self, k_function, k_args, k_kwargs)
print("=========================") print("=========================")
print(" Inlined") print(" Inlined")