Skip to content

Commit bb5ee8d

Browse files
author
Sebastien Bourdeauducq
committedMar 3, 2013
fhdl/autofragment: bugfixes + add auto_attr
1 parent cc8118d commit bb5ee8d

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed
 

‎migen/fhdl/autofragment.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import inspect
22

33
from migen.fhdl.structure import *
4+
from migen.fhdl.specials import Special
45

56
def from_local():
67
f = Fragment()
@@ -38,7 +39,7 @@ def _cd_append(d, key, statements):
3839
l = []
3940
d[key] = l
4041
if isinstance(statements, (list, tuple)):
41-
l += other
42+
l += statements
4243
else:
4344
l.append(statements)
4445

@@ -71,15 +72,32 @@ def __iadd__(self, other):
7172
self._fm._fragment.specials.add(other)
7273
return self
7374

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+
7483
class FModule:
75-
def do_simulation(self, s):
76-
pass
84+
auto_attr = True
7785

7886
def get_fragment(self):
7987
assert(not hasattr(self, "_fragment"))
80-
self._fragment = Fragment(sim=[self.do_simulation])
88+
self._fragment = Fragment()
89+
self._submodules = []
8190
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()
83101
return self._fragment
84102

85103
def __getattr__(self, name):
@@ -89,11 +107,13 @@ def __getattr__(self, name):
89107
return _FModuleSync(self)
90108
elif name == "specials":
91109
return _FModuleSpecials(self)
110+
elif name == "submodules":
111+
return _FModuleSubmodules(self)
92112
else:
93-
raise AttributeError
113+
raise AttributeError("'"+self.__class__.__name__+"' object has no attribute '"+name+"'")
94114

95115
def __setattr__(self, name, value):
96-
if name in ["comb", "sync", "specials"]:
116+
if name in ["comb", "sync", "specials", "submodules"]:
97117
if not isinstance(value, _FModuleProxy):
98118
raise AttributeError("Attempted to assign special FModule property - use += instead")
99119
else:

0 commit comments

Comments
 (0)