2021-09-27 22:12:25 +08:00
|
|
|
from inspect import isclass, getmodule
|
2020-12-18 23:44:45 +08:00
|
|
|
from functools import wraps
|
|
|
|
|
2021-09-27 10:30:54 +08:00
|
|
|
import nac3artiq
|
2020-12-18 23:44:45 +08:00
|
|
|
|
2021-09-29 15:33:12 +08:00
|
|
|
import device_db
|
|
|
|
|
2020-12-18 23:44:45 +08:00
|
|
|
|
2021-09-27 10:13:03 +08:00
|
|
|
__all__ = ["extern", "kernel"]
|
2020-12-18 23:44:45 +08:00
|
|
|
|
|
|
|
|
2021-09-29 15:33:12 +08:00
|
|
|
nac3 = nac3artiq.NAC3(device_db.device_db["core"]["arguments"]["target"])
|
2021-09-27 22:12:25 +08:00
|
|
|
allow_module_registration = True
|
2021-09-24 11:39:26 +08:00
|
|
|
|
|
|
|
|
2021-09-27 10:13:03 +08:00
|
|
|
def extern(function):
|
2021-09-27 22:12:25 +08:00
|
|
|
assert allow_module_registration
|
|
|
|
nac3.register_module(getmodule(function))
|
2021-09-24 11:39:26 +08:00
|
|
|
return function
|
2020-12-18 23:44:45 +08:00
|
|
|
|
|
|
|
|
2021-09-27 22:12:25 +08:00
|
|
|
def kernel(class_or_function):
|
|
|
|
global allow_module_registration
|
2021-09-23 19:30:03 +08:00
|
|
|
|
2021-09-27 22:12:25 +08:00
|
|
|
assert allow_module_registration
|
|
|
|
nac3.register_module(getmodule(class_or_function))
|
|
|
|
if isclass(class_or_function):
|
|
|
|
return class_or_function
|
2021-09-23 19:30:03 +08:00
|
|
|
else:
|
2021-09-27 22:12:25 +08:00
|
|
|
@wraps(class_or_function)
|
2021-09-23 19:30:03 +08:00
|
|
|
def run_on_core(self, *args, **kwargs):
|
2021-09-27 22:12:25 +08:00
|
|
|
global allow_module_registration
|
|
|
|
if allow_module_registration:
|
2021-09-23 19:30:03 +08:00
|
|
|
nac3.analyze()
|
2021-09-27 22:12:25 +08:00
|
|
|
allow_module_registration = False
|
|
|
|
nac3.compile_method(self.__class__.__name__, class_or_function.__name__)
|
2021-09-23 19:30:03 +08:00
|
|
|
return run_on_core
|