1
1
import inspect
2
2
3
3
from migen .fhdl .structure import *
4
+ from migen .fhdl .specials import Special
4
5
5
6
def from_local ():
6
7
f = Fragment ()
@@ -38,7 +39,7 @@ def _cd_append(d, key, statements):
38
39
l = []
39
40
d [key ] = l
40
41
if isinstance (statements , (list , tuple )):
41
- l += other
42
+ l += statements
42
43
else :
43
44
l .append (statements )
44
45
@@ -71,15 +72,32 @@ def __iadd__(self, other):
71
72
self ._fm ._fragment .specials .add (other )
72
73
return self
73
74
75
+ class _FModuleSubmodules (_FModuleProxy ):
76
+ def __iadd__ (self , other ):
77
+ if isinstance (other , (list , tuple )):
78
+ self ._fm ._submodules += other
79
+ else :
80
+ self ._fm ._submodules .append (other )
81
+ return self
82
+
74
83
class FModule :
75
- def do_simulation (self , s ):
76
- pass
84
+ auto_attr = True
77
85
78
86
def get_fragment (self ):
79
87
assert (not hasattr (self , "_fragment" ))
80
- self ._fragment = Fragment (sim = [self .do_simulation ])
88
+ self ._fragment = Fragment ()
89
+ self ._submodules = []
81
90
self .build_fragment ()
82
- self ._fragment += from_attributes (self )
91
+ if hasattr (self , "do_simulation" ):
92
+ self ._fragment .sim .append (self .do_simulation )
93
+ for submodule in self ._submodules :
94
+ f += submodule .get_fragment ()
95
+ if self .auto_attr :
96
+ for x in self .__dict__ .values ():
97
+ if isinstance (x , Special ):
98
+ self ._fragment .specials .add (x )
99
+ elif hasattr (x , "get_fragment" ):
100
+ self ._fragment += x .get_fragment ()
83
101
return self ._fragment
84
102
85
103
def __getattr__ (self , name ):
@@ -89,11 +107,13 @@ def __getattr__(self, name):
89
107
return _FModuleSync (self )
90
108
elif name == "specials" :
91
109
return _FModuleSpecials (self )
110
+ elif name == "submodules" :
111
+ return _FModuleSubmodules (self )
92
112
else :
93
- raise AttributeError
113
+ raise AttributeError ( "'" + self . __class__ . __name__ + "' object has no attribute '" + name + "'" )
94
114
95
115
def __setattr__ (self , name , value ):
96
- if name in ["comb" , "sync" , "specials" ]:
116
+ if name in ["comb" , "sync" , "specials" , "submodules" ]:
97
117
if not isinstance (value , _FModuleProxy ):
98
118
raise AttributeError ("Attempted to assign special FModule property - use += instead" )
99
119
else :
0 commit comments