forked from M-Labs/artiq
1
0
Fork 0

coredevice: environment -> runtime

This commit is contained in:
Sebastien Bourdeauducq 2015-07-15 11:20:41 +02:00
parent 84de2fb28b
commit f836465585
6 changed files with 24 additions and 38 deletions

View File

@ -1,24 +1,10 @@
from operator import itemgetter 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: class Comm:
def __init__(self, dmgr): def __init__(self, dmgr):
pass pass
def get_runtime_env(self):
return _RuntimeEnvironment()
def switch_clock(self, external): def switch_clock(self, external):
pass pass

View File

@ -13,7 +13,7 @@ from artiq.transforms.interleave import interleave
from artiq.transforms.lower_time import lower_time from artiq.transforms.lower_time import lower_time
from artiq.transforms.unparse import unparse 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 from artiq.py2llvm import get_runtime_binary
@ -54,7 +54,7 @@ class Core:
self.first_run = True self.first_run = True
self.core = self self.core = self
self.comm.core = self self.comm.core = self
self.runtime_env = Environment() self.runtime = Runtime()
def transform_stack(self, func_def, rpc_map, exception_map, def transform_stack(self, func_def, rpc_map, exception_map,
debug_unparse=_no_debug_unparse): debug_unparse=_no_debug_unparse):
@ -102,7 +102,7 @@ class Core:
debug_unparse("inline", func_def) debug_unparse("inline", func_def)
self.transform_stack(func_def, rpc_map, exception_map, debug_unparse) 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 return binary, rpc_map, exception_map

View File

@ -196,7 +196,7 @@ def _debug_dump_obj(obj):
raise IOError raise IOError
class Environment(LinkInterface): class Runtime(LinkInterface):
def __init__(self): def __init__(self):
self.cpu_type = "or1k" self.cpu_type = "or1k"
# allow 1ms for all initial DDS programming # allow 1ms for all initial DDS programming
@ -209,4 +209,4 @@ class Environment(LinkInterface):
return obj return obj
def __repr__(self): def __repr__(self):
return "<Environment {}>".format(self.cpu_type) return "<Runtime {}>".format(self.cpu_type)

View File

@ -1,6 +1,6 @@
from artiq.py2llvm.module import Module from artiq.py2llvm.module import Module
def get_runtime_binary(env, func_def): def get_runtime_binary(runtime, func_def):
module = Module(env) module = Module(runtime)
module.compile_function(func_def, dict()) module.compile_function(func_def, dict())
return module.emit_object() return module.emit_object()

View File

@ -39,8 +39,8 @@ _ast_cmps = {
class Visitor: class Visitor:
def __init__(self, env, ns, builder=None): def __init__(self, runtime, ns, builder=None):
self.env = env self.runtime = runtime
self.ns = ns self.ns = ns
self.builder = builder self.builder = builder
self._break_stack = [] self._break_stack = []
@ -182,7 +182,7 @@ class Visitor:
self.builder, self.builder,
[self.visit_expression(arg) for arg in node.args]) [self.visit_expression(arg) for arg in node.args])
elif fn == "syscall": elif fn == "syscall":
return self.env.build_syscall( return self.runtime.build_syscall(
node.args[0].s, node.args[0].s,
[self.visit_expression(expr) for expr in node.args[1:]], [self.visit_expression(expr) for expr in node.args[1:]],
self.builder) self.builder)
@ -420,7 +420,7 @@ class Visitor:
def _break_loop_body(self, target_block): def _break_loop_body(self, target_block):
exception_levels = self._exception_level_stack[-1] exception_levels = self._exception_level_stack[-1]
if exception_levels: if exception_levels:
self.env.build_pop(self.builder, exception_levels) self.runtime.build_pop(self.builder, exception_levels)
self.builder.branch(target_block) self.builder.branch(target_block)
def _visit_stmt_Break(self, node): def _visit_stmt_Break(self, node):
@ -436,7 +436,7 @@ class Visitor:
val = self.visit_expression(node.value) val = self.visit_expression(node.value)
exception_levels = sum(self._exception_level_stack) exception_levels = sum(self._exception_level_stack)
if exception_levels: 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): if isinstance(val, base_types.VNone):
self.builder.ret_void() self.builder.ret_void()
else: else:
@ -456,11 +456,11 @@ class Visitor:
self.builder.branch(finally_block) self.builder.branch(finally_block)
else: else:
eid = ll.Constant(ll.IntType(32), node.exc.args[0].n) 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, def _handle_exception(self, function, finally_block,
propagate, propagate_eid, handlers): propagate, propagate_eid, handlers):
eid = self.env.build_getid(self.builder) eid = self.runtime.build_getid(self.builder)
self._active_exception_stack.append( self._active_exception_stack.append(
(finally_block, propagate, propagate_eid)) (finally_block, propagate, propagate_eid))
self.builder.store(ll.Constant(ll.IntType(1), 1), propagate) 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) self.builder.store(ll.Constant(ll.IntType(1), 0), propagate)
propagate_eid = self.builder.alloca(ll.IntType(32), propagate_eid = self.builder.alloca(ll.IntType(32),
name="propagate_eid") 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.cbranch(exception_occured, exc_block, noexc_block)
self.builder.position_at_end(noexc_block) self.builder.position_at_end(noexc_block)
@ -517,7 +517,7 @@ class Visitor:
self.visit_statements(node.body) self.visit_statements(node.body)
self._exception_level_stack[-1] -= 1 self._exception_level_stack[-1] -= 1
if not self._bb_terminated(): if not self._bb_terminated():
self.env.build_pop(self.builder, 1) self.runtime.build_pop(self.builder, 1)
self.visit_statements(node.orelse) self.visit_statements(node.orelse)
if not self._bb_terminated(): if not self._bb_terminated():
self.builder.branch(finally_block) self.builder.branch(finally_block)
@ -534,6 +534,6 @@ class Visitor:
self.builder.load(propagate), self.builder.load(propagate),
propagate_block, merge_block) propagate_block, merge_block)
self.builder.position_at_end(propagate_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.branch(merge_block)
self.builder.position_at_end(merge_block) self.builder.position_at_end(merge_block)

View File

@ -5,12 +5,12 @@ from artiq.py2llvm import infer_types, ast_body, base_types, fractions, tools
class Module: class Module:
def __init__(self, env=None): def __init__(self, runtime=None):
self.llvm_module = ll.Module("main") self.llvm_module = ll.Module("main")
self.env = env self.runtime = runtime
if self.env is not None: if self.runtime is not None:
self.env.init_module(self) self.runtime.init_module(self)
fractions.init_module(self) fractions.init_module(self)
def finalize(self): def finalize(self):
@ -30,10 +30,10 @@ class Module:
def emit_object(self): def emit_object(self):
self.finalize() self.finalize()
return self.env.emit_object() return self.runtime.emit_object()
def compile_function(self, func_def, param_types): 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"] retval = ns["return"]
function_type = ll.FunctionType(retval.get_llvm_type(), 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): for arg_ast, arg_llvm in zip(func_def.args.args, function.args):
ns[arg_ast.arg].auto_store(builder, arg_llvm) 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) visitor.visit_statements(func_def.body)
if not tools.is_terminated(builder.basic_block): if not tools.is_terminated(builder.basic_block):