Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
3  migen/bus/csr.py
@@ -13,7 +13,8 @@
13 13
 
14 14
 class Interface(Record):
15 15
 	def __init__(self, data_width=8):
16  
-		Record.__init__(self, _layout, data_width=data_width)
  16
+		Record.__init__(self, set_layout_parameters(_layout,
  17
+			data_width=data_width))
17 18
 
18 19
 class Interconnect(Module):
19 20
 	def __init__(self, master, slaves):
5  migen/bus/wishbone.py
@@ -22,8 +22,9 @@
22 22
 
23 23
 class Interface(Record):
24 24
 	def __init__(self, data_width=32):
25  
-		Record.__init__(self, _layout, data_width=data_width,
26  
-			sel_width=data_width//8)
  25
+		Record.__init__(self, set_layout_parameters(_layout,
  26
+			data_width=data_width,
  27
+			sel_width=data_width//8))
27 28
 
28 29
 class InterconnectPointToPoint(Module):
29 30
 	def __init__(self, master, slave):
14  migen/genlib/fifo.py
@@ -19,18 +19,18 @@ def __init__(self, width_or_layout, depth):
19 19
 		self.re = Signal()
20 20
 		self.readable = Signal() # not empty
21 21
 
22  
-		if isinstance(width_or_layout, (int, tuple)):
23  
-			self.din = Signal(width_or_layout)
24  
-			self.dout = Signal(width_or_layout)
25  
-			self.din_bits = self.din
26  
-			self.dout_bits = self.dout
27  
-			self.width = width_or_layout
28  
-		else:
  22
+		if isinstance(width_or_layout, list):
29 23
 			self.din = Record(width_or_layout)
30 24
 			self.dout = Record(width_or_layout)
31 25
 			self.din_bits = self.din.raw_bits()
32 26
 			self.dout_bits = self.dout.raw_bits()
33 27
 			self.width = layout_len(width_or_layout)
  28
+		else:
  29
+			self.din = Signal(width_or_layout)
  30
+			self.dout = Signal(width_or_layout)
  31
+			self.din_bits = self.din
  32
+			self.dout_bits = self.dout
  33
+			self.width = width_or_layout
34 34
 
35 35
 class SyncFIFO(Module, _FIFOInterface):
36 36
 	def __init__(self, width_or_layout, depth):
54  migen/genlib/record.py
@@ -11,21 +11,42 @@
11 11
 # size can be an int, or a (int, bool) tuple for signed numbers
12 12
 # sublayout must be a list
13 13
 
14  
-def layout_len(layout, **layout_dict):
15  
-	r = 0
  14
+def set_layout_parameters(layout, **layout_dict):
  15
+	def resolve(p):
  16
+		if isinstance(p, str):
  17
+			try:
  18
+				return layout_dict[p]
  19
+			except KeyError:
  20
+				return p
  21
+		else:
  22
+			return p
  23
+
  24
+	r = []
16 25
 	for f in layout:
17 26
 		if isinstance(f[1], (int, tuple, str)): # cases 1/2
18  
-			if(len(f) == 3):
  27
+			if len(f) == 3:
  28
+				r.append((f[0], resolve(f[1]), f[2]))
  29
+			else:
  30
+				r.append((f[0], resolve(f[1])))
  31
+		elif isinstance(f[1], list): # case 3
  32
+			r.append((f[0], set_layout_parameters(f[1], **layout_dict)))
  33
+		else:
  34
+			raise TypeError
  35
+	return r
  36
+
  37
+def layout_len(layout):
  38
+	r = 0
  39
+	for f in layout:
  40
+		if isinstance(f[1], (int, tuple)): # cases 1/2
  41
+			if len(f) == 3:
19 42
 				fname, fsize, fdirection = f
20 43
 			else:
21 44
 				fname, fsize = f
22 45
 		elif isinstance(f[1], list): # case 3
23 46
 			fname, fsublayout = f
24  
-			fsize = layout_len(fsublayout, **layout_dict)
  47
+			fsize = layout_len(fsublayout)
25 48
 		else:
26 49
 			raise TypeError
27  
-		if isinstance(fsize, str):
28  
-			fsize = layout_dict[fsize]
29 50
 		if isinstance(fsize, tuple):
30 51
 			r += fsize[0]
31 52
 		else:
@@ -56,34 +77,21 @@ def layout_partial(layout, *elements):
56 77
 		insert_ref.append(layout_get(copy_ref, last))
57 78
 	return r
58 79
 
59  
-class LayoutP:
60  
-	def __init__(self, layout, **layout_dict):
61  
-		self.layout = layout
62  
-		self.layout_dict = layout_dict
63  
-
64 80
 class Record:
65  
-	def __init__(self, layout, name=None, **layout_dict):
  81
+	def __init__(self, layout, name=None):
66 82
 		self.name = get_obj_var_name(name, "")
67  
-		if isinstance(layout, LayoutP):
68  
-			self.layout = layout.layout
69  
-			self.layout_dict = layout.layout_dict
70  
-			assert(not layout_dict)
71  
-		else:
72  
-			self.layout = layout
73  
-			self.layout_dict = layout_dict
  83
+		self.layout = layout
74 84
 
75 85
 		if self.name:
76 86
 			prefix = self.name + "_"
77 87
 		else:
78 88
 			prefix = ""
79 89
 		for f in self.layout:
80  
-			if isinstance(f[1], (int, tuple, str)): # cases 1/2
  90
+			if isinstance(f[1], (int, tuple)): # cases 1/2
81 91
 				if(len(f) == 3):
82 92
 					fname, fsize, fdirection = f
83 93
 				else:
84 94
 					fname, fsize = f
85  
-				if isinstance(fsize, str):
86  
-					fsize = layout_dict[fsize]
87 95
 				finst = Signal(fsize, name=prefix + fname)
88 96
 			elif isinstance(f[1], list): # case 3
89 97
 				fname, fsublayout = f
@@ -154,7 +162,7 @@ def connect_flat(self, *slaves):
154 162
 		return r
155 163
 
156 164
 	def __len__(self):
157  
-		return layout_len(self.layout, **self.layout_dict)
  165
+		return layout_len(self.layout)
158 166
 
159 167
 	def __repr__(self):
160 168
 		return "<Record " + ":".join(f[0] for f in self.layout) + " at " + hex(id(self)) + ">"

No commit comments for this range

Something went wrong with that request. Please try again.