mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
coredevice: environment -> runtime
This commit is contained in:
parent
84de2fb28b
commit
f836465585
@ -1,24 +1,10 @@
|
||||
from operator import itemgetter
|
||||
|
||||
from artiq.language.units import ms
|
||||
from artiq.coredevice.runtime import LinkInterface
|
||||
|
||||
|
||||
class _RuntimeEnvironment(LinkInterface):
|
||||
def __init__(self):
|
||||
self.warmup_time = 1*ms
|
||||
|
||||
def emit_object(self):
|
||||
return str(self.llvm_module)
|
||||
|
||||
|
||||
class Comm:
|
||||
def __init__(self, dmgr):
|
||||
pass
|
||||
|
||||
def get_runtime_env(self):
|
||||
return _RuntimeEnvironment()
|
||||
|
||||
def switch_clock(self, external):
|
||||
pass
|
||||
|
||||
|
@ -13,7 +13,7 @@ from artiq.transforms.interleave import interleave
|
||||
from artiq.transforms.lower_time import lower_time
|
||||
from artiq.transforms.unparse import unparse
|
||||
|
||||
from artiq.coredevice.runtime import Environment
|
||||
from artiq.coredevice.runtime import Runtime
|
||||
|
||||
from artiq.py2llvm import get_runtime_binary
|
||||
|
||||
@ -54,7 +54,7 @@ class Core:
|
||||
self.first_run = True
|
||||
self.core = self
|
||||
self.comm.core = self
|
||||
self.runtime_env = Environment()
|
||||
self.runtime = Runtime()
|
||||
|
||||
def transform_stack(self, func_def, rpc_map, exception_map,
|
||||
debug_unparse=_no_debug_unparse):
|
||||
@ -102,7 +102,7 @@ class Core:
|
||||
debug_unparse("inline", func_def)
|
||||
self.transform_stack(func_def, rpc_map, exception_map, debug_unparse)
|
||||
|
||||
binary = get_runtime_binary(self.runtime_env, func_def)
|
||||
binary = get_runtime_binary(self.runtime, func_def)
|
||||
|
||||
return binary, rpc_map, exception_map
|
||||
|
||||
|
@ -196,7 +196,7 @@ def _debug_dump_obj(obj):
|
||||
raise IOError
|
||||
|
||||
|
||||
class Environment(LinkInterface):
|
||||
class Runtime(LinkInterface):
|
||||
def __init__(self):
|
||||
self.cpu_type = "or1k"
|
||||
# allow 1ms for all initial DDS programming
|
||||
@ -209,4 +209,4 @@ class Environment(LinkInterface):
|
||||
return obj
|
||||
|
||||
def __repr__(self):
|
||||
return "<Environment {}>".format(self.cpu_type)
|
||||
return "<Runtime {}>".format(self.cpu_type)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from artiq.py2llvm.module import Module
|
||||
|
||||
def get_runtime_binary(env, func_def):
|
||||
module = Module(env)
|
||||
def get_runtime_binary(runtime, func_def):
|
||||
module = Module(runtime)
|
||||
module.compile_function(func_def, dict())
|
||||
return module.emit_object()
|
||||
|
@ -39,8 +39,8 @@ _ast_cmps = {
|
||||
|
||||
|
||||
class Visitor:
|
||||
def __init__(self, env, ns, builder=None):
|
||||
self.env = env
|
||||
def __init__(self, runtime, ns, builder=None):
|
||||
self.runtime = runtime
|
||||
self.ns = ns
|
||||
self.builder = builder
|
||||
self._break_stack = []
|
||||
@ -182,7 +182,7 @@ class Visitor:
|
||||
self.builder,
|
||||
[self.visit_expression(arg) for arg in node.args])
|
||||
elif fn == "syscall":
|
||||
return self.env.build_syscall(
|
||||
return self.runtime.build_syscall(
|
||||
node.args[0].s,
|
||||
[self.visit_expression(expr) for expr in node.args[1:]],
|
||||
self.builder)
|
||||
@ -420,7 +420,7 @@ class Visitor:
|
||||
def _break_loop_body(self, target_block):
|
||||
exception_levels = self._exception_level_stack[-1]
|
||||
if exception_levels:
|
||||
self.env.build_pop(self.builder, exception_levels)
|
||||
self.runtime.build_pop(self.builder, exception_levels)
|
||||
self.builder.branch(target_block)
|
||||
|
||||
def _visit_stmt_Break(self, node):
|
||||
@ -436,7 +436,7 @@ class Visitor:
|
||||
val = self.visit_expression(node.value)
|
||||
exception_levels = sum(self._exception_level_stack)
|
||||
if exception_levels:
|
||||
self.env.build_pop(self.builder, exception_levels)
|
||||
self.runtime.build_pop(self.builder, exception_levels)
|
||||
if isinstance(val, base_types.VNone):
|
||||
self.builder.ret_void()
|
||||
else:
|
||||
@ -456,11 +456,11 @@ class Visitor:
|
||||
self.builder.branch(finally_block)
|
||||
else:
|
||||
eid = ll.Constant(ll.IntType(32), node.exc.args[0].n)
|
||||
self.env.build_raise(self.builder, eid)
|
||||
self.runtime.build_raise(self.builder, eid)
|
||||
|
||||
def _handle_exception(self, function, finally_block,
|
||||
propagate, propagate_eid, handlers):
|
||||
eid = self.env.build_getid(self.builder)
|
||||
eid = self.runtime.build_getid(self.builder)
|
||||
self._active_exception_stack.append(
|
||||
(finally_block, propagate, propagate_eid))
|
||||
self.builder.store(ll.Constant(ll.IntType(1), 1), propagate)
|
||||
@ -509,7 +509,7 @@ class Visitor:
|
||||
self.builder.store(ll.Constant(ll.IntType(1), 0), propagate)
|
||||
propagate_eid = self.builder.alloca(ll.IntType(32),
|
||||
name="propagate_eid")
|
||||
exception_occured = self.env.build_catch(self.builder)
|
||||
exception_occured = self.runtime.build_catch(self.builder)
|
||||
self.builder.cbranch(exception_occured, exc_block, noexc_block)
|
||||
|
||||
self.builder.position_at_end(noexc_block)
|
||||
@ -517,7 +517,7 @@ class Visitor:
|
||||
self.visit_statements(node.body)
|
||||
self._exception_level_stack[-1] -= 1
|
||||
if not self._bb_terminated():
|
||||
self.env.build_pop(self.builder, 1)
|
||||
self.runtime.build_pop(self.builder, 1)
|
||||
self.visit_statements(node.orelse)
|
||||
if not self._bb_terminated():
|
||||
self.builder.branch(finally_block)
|
||||
@ -534,6 +534,6 @@ class Visitor:
|
||||
self.builder.load(propagate),
|
||||
propagate_block, merge_block)
|
||||
self.builder.position_at_end(propagate_block)
|
||||
self.env.build_raise(self.builder, self.builder.load(propagate_eid))
|
||||
self.runtime.build_raise(self.builder, self.builder.load(propagate_eid))
|
||||
self.builder.branch(merge_block)
|
||||
self.builder.position_at_end(merge_block)
|
||||
|
@ -5,12 +5,12 @@ from artiq.py2llvm import infer_types, ast_body, base_types, fractions, tools
|
||||
|
||||
|
||||
class Module:
|
||||
def __init__(self, env=None):
|
||||
def __init__(self, runtime=None):
|
||||
self.llvm_module = ll.Module("main")
|
||||
self.env = env
|
||||
self.runtime = runtime
|
||||
|
||||
if self.env is not None:
|
||||
self.env.init_module(self)
|
||||
if self.runtime is not None:
|
||||
self.runtime.init_module(self)
|
||||
fractions.init_module(self)
|
||||
|
||||
def finalize(self):
|
||||
@ -30,10 +30,10 @@ class Module:
|
||||
|
||||
def emit_object(self):
|
||||
self.finalize()
|
||||
return self.env.emit_object()
|
||||
return self.runtime.emit_object()
|
||||
|
||||
def compile_function(self, func_def, param_types):
|
||||
ns = infer_types.infer_function_types(self.env, func_def, param_types)
|
||||
ns = infer_types.infer_function_types(self.runtime, func_def, param_types)
|
||||
retval = ns["return"]
|
||||
|
||||
function_type = ll.FunctionType(retval.get_llvm_type(),
|
||||
@ -50,7 +50,7 @@ class Module:
|
||||
for arg_ast, arg_llvm in zip(func_def.args.args, function.args):
|
||||
ns[arg_ast.arg].auto_store(builder, arg_llvm)
|
||||
|
||||
visitor = ast_body.Visitor(self.env, ns, builder)
|
||||
visitor = ast_body.Visitor(self.runtime, ns, builder)
|
||||
visitor.visit_statements(func_def.body)
|
||||
|
||||
if not tools.is_terminated(builder.basic_block):
|
||||
|
Loading…
Reference in New Issue
Block a user