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:
parent
4f01bf32d4
commit
761d9a95fd
@ -58,8 +58,11 @@ def _makeName(n, prefixes, namedict):
|
||||
#For attribute references, periods are replaced with '_'.
|
||||
if '.' in n:
|
||||
n = n.replace('.', '_')
|
||||
while n in namedict:
|
||||
n += '_'
|
||||
if n in namedict:
|
||||
i = 0
|
||||
while (n + '_{}'.format(i)) in namedict:
|
||||
i += 1
|
||||
n += '_{}'.format(i)
|
||||
# trim empty prefixes
|
||||
prefixes = [p for p in prefixes if p]
|
||||
if len(prefixes) > 1:
|
||||
@ -1274,8 +1277,10 @@ def _analyzeTopFunc(top_inst, func, *args, **kwargs):
|
||||
continue
|
||||
for attr, attrobj in vars(obj).items():
|
||||
if isinstance(attrobj, _Signal):
|
||||
signame = name + '_' + attr
|
||||
attrobj._name = signame
|
||||
signame = attrobj._name
|
||||
if not signame:
|
||||
signame = name + '_' + attr
|
||||
attrobj._name = signame
|
||||
v.argdict[signame] = attrobj
|
||||
v.argnames.append(signame)
|
||||
|
||||
|
@ -34,7 +34,7 @@ def m_test_intf(clock,reset,a,b,c):
|
||||
intfaa = Intf()
|
||||
|
||||
gen_mod = m_modify(clock,reset,intfaa)
|
||||
|
||||
|
||||
@always_seq(clock.posedge,reset=reset)
|
||||
def rtl_inc():
|
||||
intfa.x.next = intfa.x - 1
|
||||
@ -58,6 +58,25 @@ def m_test_intf(clock,reset,a,b,c):
|
||||
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():
|
||||
clock = Signal(bool(0))
|
||||
reset = ResetSignal(0, active=0, async=False)
|
||||
@ -82,9 +101,9 @@ def c_testbench():
|
||||
for ii in range(17):
|
||||
print("a: x=%d y=%d z=%d"%(a.x,a.y,a.z))
|
||||
print("b: x=%d y=%d z=%d"%(b.x,b.y,b.z))
|
||||
print("c: x=%d y=%d z=%d"%(c.x,c.y,c.z))
|
||||
print("c: x=%d y=%d z=%d"%(c.x,c.y,c.z))
|
||||
yield clock.posedge
|
||||
|
||||
|
||||
raise StopSimulation
|
||||
|
||||
return tb_dut,tb_clk,tb_stim
|
||||
@ -102,4 +121,3 @@ if __name__ == '__main__':
|
||||
verify.simulator = analyze.simulator = sys.argv[1]
|
||||
Simulation(c_testbench()).run()
|
||||
print(verify(c_testbench))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user