hdl.ast: allow Signals to be privately named using name=""
* Given a private name `$\d+` in RTLIL (as they are not named in the IR) * Not automatically added to VCD files (as they are not named in the IR) * Cannot be traced to a VCD (as they have no name to put in the file) * Cannot be used with an unnamed top-level port (as there is no name)
This commit is contained in:
parent
6ffafef794
commit
c7f719ab93
6 changed files with 56 additions and 6 deletions
|
|
@ -1180,6 +1180,8 @@ class SignalTestCase(FHDLTestCase):
|
|||
self.assertEqual(s1.name, "s1")
|
||||
s2 = Signal(name="sig")
|
||||
self.assertEqual(s2.name, "sig")
|
||||
s3 = Signal(name="")
|
||||
self.assertEqual(s3.name, "")
|
||||
|
||||
def test_init(self):
|
||||
s1 = Signal(4, init=0b111, reset_less=True)
|
||||
|
|
@ -1294,6 +1296,8 @@ class SignalTestCase(FHDLTestCase):
|
|||
def test_repr(self):
|
||||
s1 = Signal()
|
||||
self.assertEqual(repr(s1), "(sig s1)")
|
||||
s2 = Signal(name="")
|
||||
self.assertEqual(repr(s2), "(sig)")
|
||||
|
||||
def test_like(self):
|
||||
s1 = Signal.like(Signal(4))
|
||||
|
|
|
|||
|
|
@ -962,6 +962,7 @@ class NamesTestCase(FHDLTestCase):
|
|||
o1 = Signal()
|
||||
o2 = Signal()
|
||||
o3 = Signal()
|
||||
o4 = Signal(name="")
|
||||
i1 = Signal(name="i")
|
||||
|
||||
f = Fragment()
|
||||
|
|
@ -980,6 +981,7 @@ class NamesTestCase(FHDLTestCase):
|
|||
"o1": (o1, PortDirection.Output),
|
||||
"o2": (o2, PortDirection.Output),
|
||||
"o3": (o3, PortDirection.Output),
|
||||
"o4": (o4, PortDirection.Output),
|
||||
}
|
||||
design = f.prepare(ports)
|
||||
self.assertEqual(design.fragments[design.fragment].signal_names, SignalDict([
|
||||
|
|
@ -988,12 +990,20 @@ class NamesTestCase(FHDLTestCase):
|
|||
(o1, "o1"),
|
||||
(o2, "o2"),
|
||||
(o3, "o3"),
|
||||
# (o4, "o4"), # Signal has a private name.
|
||||
(cd_sync.clk, "clk"),
|
||||
(cd_sync.rst, "rst$6"),
|
||||
(cd_sync.rst, "rst$7"),
|
||||
(cd_sync_norst.clk, "sync_norst_clk"),
|
||||
(i1, "i$7"),
|
||||
(i1, "i$8"),
|
||||
]))
|
||||
|
||||
def test_wrong_private_unnamed_toplevel_ports(self):
|
||||
s = Signal(name="")
|
||||
f = Fragment()
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
r"^Signals with private names cannot be used in unnamed top-level ports$"):
|
||||
Design(f, ports=((None, s, None),), hierarchy=("top",))
|
||||
|
||||
def test_assign_names_to_fragments(self):
|
||||
f = Fragment()
|
||||
f.add_subfragment(a := Fragment())
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from amaranth.hdl._dsl import *
|
|||
from amaranth.hdl._ir import *
|
||||
from amaranth.sim import *
|
||||
from amaranth.lib.memory import Memory
|
||||
from amaranth.lib.data import View, StructLayout
|
||||
|
||||
from .utils import *
|
||||
from amaranth._utils import _ignore_deprecated
|
||||
|
|
@ -1042,6 +1043,21 @@ class SimulatorIntegrationTestCase(FHDLTestCase):
|
|||
with sim.write_vcd(f):
|
||||
pass
|
||||
|
||||
def test_vcd_private_signal(self):
|
||||
sim = Simulator(Module())
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
r"^Cannot trace signal with private name$"):
|
||||
with open(os.path.devnull, "w") as f:
|
||||
with sim.write_vcd(f, traces=(Signal(name=""),)):
|
||||
pass
|
||||
|
||||
sim = Simulator(Module())
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
r"^Cannot trace signal with private name \(within \(cat \(sig x\) \(sig\)\)\)$"):
|
||||
with open(os.path.devnull, "w") as f:
|
||||
with sim.write_vcd(f, traces=(Cat(Signal(name="x"), Signal(name="")),)):
|
||||
pass
|
||||
|
||||
def test_no_negated_boolean_warning(self):
|
||||
m = Module()
|
||||
a = Signal()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue