Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fhdl: improve naming of related signals

  • Loading branch information...
commit fdf022a04b445f8bc290f656773337b739ebedf5 1 parent 2c580ff
Sébastien Bourdeauducq authored August 08, 2013
62  migen/fhdl/namer.py
@@ -97,7 +97,7 @@ def _name_signal(tree, signal):
97 97
 			elements.append(elname)
98 98
 	return "_".join(elements)
99 99
 
100  
-def _build_pnd(tree, signals):
  100
+def _build_pnd_from_tree(tree, signals):
101 101
 	return dict((signal, _name_signal(tree, signal)) for signal in signals)
102 102
 
103 103
 def _invert_pnd(pnd):
@@ -124,12 +124,12 @@ def _set_use_number(tree, signals):
124 124
 
125 125
 _debug = False
126 126
 
127  
-def build_namespace(signals):
  127
+def _build_pnd_for_group(group_n, signals):
128 128
 	basic_tree = _build_tree(signals)
129 129
 	_set_use_name(basic_tree)
130 130
 	if _debug:
131  
-		_display_tree("tree_basic.svg", basic_tree)
132  
-	pnd = _build_pnd(basic_tree, signals)
  131
+		_display_tree("tree{0}_basic.svg".format(group_n), basic_tree)
  132
+	pnd = _build_pnd_from_tree(basic_tree, signals)
133 133
 
134 134
 	# If there are conflicts, try splitting the tree by numbers
135 135
 	# on paths taken by conflicting signals.
@@ -137,16 +137,16 @@ def build_namespace(signals):
137 137
 	if conflicting_signals:
138 138
 		_set_use_number(basic_tree, conflicting_signals)
139 139
 		if _debug:
140  
-			print("namer: using split-by-number strategy")
141  
-			_display_tree("tree_marked.svg", basic_tree)
  140
+			print("namer: using split-by-number strategy (group {0})".format(group_n))
  141
+			_display_tree("tree{0}_marked.svg".format(group_n), basic_tree)
142 142
 		numbered_tree = _build_tree(signals, basic_tree)
143 143
 		_set_use_name(numbered_tree)
144 144
 		if _debug:
145  
-			_display_tree("tree_numbered.svg", numbered_tree)
146  
-		pnd = _build_pnd(numbered_tree, signals)
  145
+			_display_tree("tree{0}_numbered.svg".format(group_n), numbered_tree)
  146
+		pnd = _build_pnd_from_tree(numbered_tree, signals)
147 147
 	else:
148 148
 		if _debug:
149  
-			print("namer: using basic strategy")
  149
+			print("namer: using basic strategy (group {0})".format(group_n))
150 150
 	
151 151
 	# ...then add number suffixes by HUID
152 152
 	inv_pnd = _invert_pnd(pnd)
@@ -157,8 +157,50 @@ def build_namespace(signals):
157 157
 			for n, signal in enumerate(sorted(signals, key=lambda x: x.huid)):
158 158
 				pnd[signal] += str(n)
159 159
 	if _debug and huid_suffixed:
160  
-		print("namer: using HUID suffixes")
  160
+		print("namer: using HUID suffixes (group {0})".format(group_n))
  161
+
  162
+	return pnd
  163
+
  164
+def _build_signal_groups(signals):
  165
+	r = []
  166
+	for signal in signals:
  167
+		# build chain of related signals
  168
+		related_list = []
  169
+		cur_signal = signal
  170
+		while cur_signal is not None:
  171
+			related_list.insert(0, cur_signal)
  172
+			cur_signal = cur_signal.related
  173
+		# add to groups
  174
+		r += [set()]*(len(related_list) - len(r))
  175
+		for target_set, source_set in zip(r, related_list):
  176
+			target_set.add(source_set)
  177
+	# with the algorithm above and a list of all signals,
  178
+	# a signal appears in all groups of a lower number than its.
  179
+	# make signals appear only in their group of highest number.
  180
+	for s1, s2 in zip(r, r[1:]):
  181
+		s1 -= s2
  182
+	return r
161 183
 
  184
+def _build_pnd(signals):
  185
+	groups = _build_signal_groups(signals)
  186
+	gpnds = [_build_pnd_for_group(n, gsignals) for n, gsignals in enumerate(groups)]
  187
+
  188
+	pnd = dict()
  189
+	for gn, gpnd in enumerate(gpnds):
  190
+		for signal, name in gpnd.items():
  191
+			result = name
  192
+			cur_gn = gn
  193
+			cur_signal = signal
  194
+			while cur_signal.related is not None:
  195
+				cur_signal = cur_signal.related
  196
+				cur_gn -= 1
  197
+				result = gpnds[cur_gn][cur_signal] + "_" + result
  198
+			pnd[signal] = result
  199
+
  200
+	return pnd
  201
+
  202
+def build_namespace(signals):
  203
+	pnd = _build_pnd(signals)
162 204
 	ns = Namespace(pnd)
163 205
 	# register signals with name_override
164 206
 	for signal in signals:
6  migen/fhdl/structure.py
@@ -139,10 +139,8 @@ def __init__(self, bits_sign=None, name=None, variable=False, reset=0, name_over
139 139
 		self.variable = variable # deprecated
140 140
 		self.reset = reset
141 141
 		self.name_override = name_override
142  
-		self.backtrace = []
143  
-		if related is not None:
144  
-			self.backtrace += related.backtrace
145  
-		self.backtrace += tracer.trace_back(name)
  142
+		self.backtrace = tracer.trace_back(name)
  143
+		self.related = related
146 144
 
147 145
 	def __repr__(self):
148 146
 		return "<Signal " + (self.backtrace[-1][0] or "anonymous") + " at " + hex(id(self)) + ">"

0 notes on commit fdf022a

Please sign in to comment.
Something went wrong with that request. Please try again.