1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

improved handling of name conflicts plus unittest

--HG--
branch : 0.9-dev
This commit is contained in:
Keerthan Jaic 2013-09-29 20:10:50 -04:00
parent 4f01bf32d4
commit 761d9a95fd
2 changed files with 31 additions and 8 deletions

View File

@ -58,8 +58,11 @@ def _makeName(n, prefixes, namedict):
#For attribute references, periods are replaced with '_'. #For attribute references, periods are replaced with '_'.
if '.' in n: if '.' in n:
n = n.replace('.', '_') n = n.replace('.', '_')
while n in namedict: if n in namedict:
n += '_' i = 0
while (n + '_{}'.format(i)) in namedict:
i += 1
n += '_{}'.format(i)
# trim empty prefixes # trim empty prefixes
prefixes = [p for p in prefixes if p] prefixes = [p for p in prefixes if p]
if len(prefixes) > 1: if len(prefixes) > 1:
@ -1274,6 +1277,8 @@ def _analyzeTopFunc(top_inst, func, *args, **kwargs):
continue continue
for attr, attrobj in vars(obj).items(): for attr, attrobj in vars(obj).items():
if isinstance(attrobj, _Signal): if isinstance(attrobj, _Signal):
signame = attrobj._name
if not signame:
signame = name + '_' + attr signame = name + '_' + attr
attrobj._name = signame attrobj._name = signame
v.argdict[signame] = attrobj v.argdict[signame] = attrobj

View File

@ -58,6 +58,25 @@ def m_test_intf(clock,reset,a,b,c):
return gen_mod,rtl_inc,rtl_combine return gen_mod,rtl_inc,rtl_combine
def name_conflict_after_replace(clock, reset, a, a_x):
a_x_0 = [Signal(intbv(0)[len(a_x):]) for i in range(8)]
@always_seq(clock.posedge, reset=reset)
def logic():
a.x.next = a_x
a_x.next = a_x_0[1]
return logic
def test_name_conflict_after_replace():
clock = Signal(False)
reset = ResetSignal(0, active=0, async=False)
a = Intf()
a_x = Signal(intbv(0)[len(a.x):])
assert conversion.analyze(name_conflict_after_replace, clock, reset, a, a_x) == 0
def c_testbench(): def c_testbench():
clock = Signal(bool(0)) clock = Signal(bool(0))
reset = ResetSignal(0, active=0, async=False) reset = ResetSignal(0, active=0, async=False)
@ -102,4 +121,3 @@ if __name__ == '__main__':
verify.simulator = analyze.simulator = sys.argv[1] verify.simulator = analyze.simulator = sys.argv[1]
Simulation(c_testbench()).run() Simulation(c_testbench()).run()
print(verify(c_testbench)) print(verify(c_testbench))