pytholite: forward 'yield call' statements to io module
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 10 Nov 2012 21:59:14 +0000 (22:59 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 10 Nov 2012 21:59:14 +0000 (22:59 +0100)
migen/pytholite/compiler.py
migen/pytholite/io.py

index 240895353577aaf521302c07560091f425eb1c6c..5023f93b6bf54a543cce3800642e12916586b37f 100644 (file)
@@ -7,7 +7,7 @@ from migen.fhdl.structure import _Slice
 from migen.fhdl import visit as fhdl
 from migen.corelogic.fsm import FSM
 from migen.pytholite import transel
-from migen.pytholite.io import *
+from migen.pytholite.io import make_io_object, gen_io
 
 class FinalizeError(Exception):
        pass
@@ -62,7 +62,8 @@ class _AbstractNextState:
                self.target_state = target_state
 
 class _Compiler:
-       def __init__(self, symdict, registers):
+       def __init__(self, ioo, symdict, registers):
+               self.ioo = ioo
                self.symdict = symdict
                self.registers = registers
                self.targetname = ""
@@ -101,7 +102,7 @@ class _Compiler:
                elif isinstance(statement, ast.If):
                        test = self.visit_expr(statement.test)
                        states_t, exit_states_t = self.visit_block(statement.body)
-                       states_f, exit_states_f  = self.visit_block(statement.orelse)
+                       states_f, exit_states_f = self.visit_block(statement.orelse)
                        
                        test_state_stmt = If(test, _AbstractNextState(states_t[0]))
                        test_state = [test_state_stmt]
@@ -141,6 +142,17 @@ class _Compiler:
                                states += states_b
                        exit_states += last_exit_states
                        del self.symdict[target]
+               elif isinstance(statement, ast.Expr):
+                       if isinstance(statement.value, ast.Yield):
+                               yvalue = statement.value.value
+                               if not isinstance(yvalue, ast.Call) or not isinstance(yvalue.func, ast.Name):
+                                       raise NotImplementedError("Unrecognized I/O sequence")
+                               callee = self.symdict[yvalue.func.id]
+                               states_i, exit_states_i = gen_io(self, callee, yvalue.args, [])
+                               states += states_i
+                               exit_states += exit_states_i
+                       else:
+                               raise NotImplementedError
                else:
                        raise NotImplementedError
                return states, exit_states
@@ -321,13 +333,13 @@ def _create_fsm(states):
        return fsm
 
 def make_pytholite(func, **ioresources):
-       pl = make_io_object(**ioresources)
+       ioo = make_io_object(**ioresources)
        
        tree = ast.parse(inspect.getsource(func))
        symdict = func.__globals__.copy()
        registers = []
        
-       states = _Compiler(symdict, registers).visit_top(tree)
+       states = _Compiler(ioo, symdict, registers).visit_top(tree)
        
        regf = Fragment()
        for register in registers:
@@ -337,5 +349,5 @@ def make_pytholite(func, **ioresources):
        fsm = _create_fsm(states)
        fsmf = _LowerAbstractLoad().visit(fsm.get_fragment())
        
-       pl.fragment = regf + fsmf
-       return pl
+       ioo.fragment = regf + fsmf
+       return ioo
index d0ace1db29590fa52dae4a19d5417b566d9e04cc..3d875e3a43fd0543aa778ce682bfa2147e2bf357 100644 (file)
@@ -1,4 +1,7 @@
+import ast
+
 from migen.flow.actor import *
+from migen.actorlib.sim import *
 
 class Pytholite:
        def get_fragment(self):
@@ -13,3 +16,9 @@ def make_io_object(dataflow=None):
        else:
                return DFPytholite(dataflow)
 
+
+def gen_io(compiler, model, to_model, from_model):
+       print(model)
+       for arg in to_model:
+               print(ast.dump(arg))
+       return [], []