mirror of https://github.com/m-labs/artiq.git
Add @host_only function decorator (#172).
This commit is contained in:
parent
15039e1d74
commit
127b117113
|
@ -739,6 +739,12 @@ class Stitcher:
|
||||||
# to perform a system call instead of a regular call.
|
# to perform a system call instead of a regular call.
|
||||||
result = self._quote_foreign_function(function, loc,
|
result = self._quote_foreign_function(function, loc,
|
||||||
syscall=function.artiq_embedded.syscall)
|
syscall=function.artiq_embedded.syscall)
|
||||||
|
elif function.artiq_embedded.forbidden is not None:
|
||||||
|
diag = diagnostic.Diagnostic("fatal",
|
||||||
|
"this function cannot be called as an RPC", {},
|
||||||
|
self._function_loc(function),
|
||||||
|
notes=self._call_site_note(loc, is_syscall=True))
|
||||||
|
self.engine.process(diag)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -60,6 +60,7 @@ class DummyScheduler:
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
return dict()
|
return dict()
|
||||||
|
|
||||||
|
@host_only
|
||||||
def pause(self):
|
def pause(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from artiq.coredevice.runtime import source_loader
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["host_int", "int", "host_round", "round",
|
__all__ = ["host_int", "int", "host_round", "round",
|
||||||
"kernel", "portable", "syscall",
|
"kernel", "portable", "syscall", "host_only",
|
||||||
"set_time_manager", "set_watchdog_factory",
|
"set_time_manager", "set_watchdog_factory",
|
||||||
"ARTIQException",
|
"ARTIQException",
|
||||||
"TerminationRequested"]
|
"TerminationRequested"]
|
||||||
|
@ -168,7 +168,7 @@ def round(value, width=32):
|
||||||
|
|
||||||
|
|
||||||
_ARTIQEmbeddedInfo = namedtuple("_ARTIQEmbeddedInfo",
|
_ARTIQEmbeddedInfo = namedtuple("_ARTIQEmbeddedInfo",
|
||||||
"core_name function syscall")
|
"core_name function syscall forbidden")
|
||||||
|
|
||||||
def kernel(arg):
|
def kernel(arg):
|
||||||
"""
|
"""
|
||||||
|
@ -196,7 +196,8 @@ def kernel(arg):
|
||||||
def run_on_core(self, *k_args, **k_kwargs):
|
def run_on_core(self, *k_args, **k_kwargs):
|
||||||
return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
|
return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
|
||||||
run_on_core.artiq_embedded = _ARTIQEmbeddedInfo(
|
run_on_core.artiq_embedded = _ARTIQEmbeddedInfo(
|
||||||
core_name=arg, function=function, syscall=None)
|
core_name=arg, function=function, syscall=None,
|
||||||
|
forbidden=False)
|
||||||
return run_on_core
|
return run_on_core
|
||||||
return inner_decorator
|
return inner_decorator
|
||||||
else:
|
else:
|
||||||
|
@ -213,7 +214,8 @@ def portable(function):
|
||||||
on the core device (no RPC).
|
on the core device (no RPC).
|
||||||
"""
|
"""
|
||||||
function.artiq_embedded = \
|
function.artiq_embedded = \
|
||||||
_ARTIQEmbeddedInfo(core_name=None, function=function, syscall=None)
|
_ARTIQEmbeddedInfo(core_name=None, function=function, syscall=None,
|
||||||
|
forbidden=False)
|
||||||
return function
|
return function
|
||||||
|
|
||||||
def syscall(arg):
|
def syscall(arg):
|
||||||
|
@ -231,12 +233,22 @@ def syscall(arg):
|
||||||
def inner_decorator(function):
|
def inner_decorator(function):
|
||||||
function.artiq_embedded = \
|
function.artiq_embedded = \
|
||||||
_ARTIQEmbeddedInfo(core_name=None, function=None,
|
_ARTIQEmbeddedInfo(core_name=None, function=None,
|
||||||
syscall=function.__name__)
|
syscall=function.__name__, forbidden=False)
|
||||||
return function
|
return function
|
||||||
return inner_decorator
|
return inner_decorator
|
||||||
else:
|
else:
|
||||||
return syscall(arg.__name__)(arg)
|
return syscall(arg.__name__)(arg)
|
||||||
|
|
||||||
|
def host_only(function):
|
||||||
|
"""
|
||||||
|
This decorator marks a function so that it can only be executed
|
||||||
|
in the host Python interpreter.
|
||||||
|
"""
|
||||||
|
function.artiq_embedded = \
|
||||||
|
_ARTIQEmbeddedInfo(core_name=None, function=None, syscall=None,
|
||||||
|
forbidden=True)
|
||||||
|
return function
|
||||||
|
|
||||||
|
|
||||||
class _DummyTimeManager:
|
class _DummyTimeManager:
|
||||||
def _not_implemented(self, *args, **kwargs):
|
def _not_implemented(self, *args, **kwargs):
|
||||||
|
|
|
@ -93,6 +93,7 @@ set_watchdog_factory(Watchdog)
|
||||||
class Scheduler:
|
class Scheduler:
|
||||||
pause_noexc = staticmethod(make_parent_action("pause"))
|
pause_noexc = staticmethod(make_parent_action("pause"))
|
||||||
|
|
||||||
|
@host_only
|
||||||
def pause(self):
|
def pause(self):
|
||||||
if self.pause_noexc():
|
if self.pause_noexc():
|
||||||
raise TerminationRequested
|
raise TerminationRequested
|
||||||
|
|
Loading…
Reference in New Issue