Skip to content

Commit 6dfed2e

Browse files
committed
lib.fifo: annotate for use with CLI. (WIP)
1 parent b0e43eb commit 6dfed2e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

amaranth/lib/fifo.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .. import *
44
from ..asserts import *
55
from .._utils import log2_int
6+
from .wiring import Signature, In, Out
67
from .coding import GrayEncoder, GrayDecoder
78
from .cdc import FFSynchronizer, AsyncFFSynchronizer
89

@@ -64,7 +65,7 @@ class FIFOInterface:
6465
w_attributes="",
6566
r_attributes="")
6667

67-
def __init__(self, *, width, depth, fwft):
68+
def __init__(self, *, width: int, depth: int, fwft):
6869
if not isinstance(width, int) or width < 0:
6970
raise TypeError("FIFO width must be a non-negative integer, not {!r}"
7071
.format(width))
@@ -85,6 +86,17 @@ def __init__(self, *, width, depth, fwft):
8586
self.r_en = Signal()
8687
self.r_level = Signal(range(depth + 1))
8788

89+
@property
90+
def signature(self):
91+
return Signature({
92+
"w_data": In(self.width),
93+
"w_rdy": Out(1),
94+
"w_en": In(1),
95+
"r_data": Out(self.width),
96+
"r_rdy": Out(1),
97+
"w_en": In(1),
98+
})
99+
88100

89101
def _incr(signal, modulo):
90102
if modulo == 2 ** len(signal):
@@ -116,7 +128,7 @@ class SyncFIFO(Elaboratable, FIFOInterface):
116128
r_attributes="",
117129
w_attributes="")
118130

119-
def __init__(self, *, width, depth, fwft=True):
131+
def __init__(self, *, width: int, depth: int, fwft=True):
120132
super().__init__(width=width, depth=depth, fwft=fwft)
121133

122134
self.level = Signal(range(depth + 1))
@@ -220,7 +232,7 @@ class SyncFIFOBuffered(Elaboratable, FIFOInterface):
220232
r_attributes="",
221233
w_attributes="")
222234

223-
def __init__(self, *, width, depth):
235+
def __init__(self, *, width: int, depth: int):
224236
super().__init__(width=width, depth=depth, fwft=True)
225237

226238
self.level = Signal(range(depth + 1))
@@ -295,7 +307,7 @@ class AsyncFIFO(Elaboratable, FIFOInterface):
295307
""".strip(),
296308
w_attributes="")
297309

298-
def __init__(self, *, width, depth, r_domain="read", w_domain="write", exact_depth=False):
310+
def __init__(self, *, width: int, depth: int, r_domain="read", w_domain="write", exact_depth=False):
299311
if depth != 0:
300312
try:
301313
depth_bits = log2_int(depth, need_pow2=exact_depth)

amaranth_cli/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def component(reference):
5252
dest="component", type=component)
5353
op_generate.add_argument(
5454
"-p", "--param", metavar=("NAME", "VALUE"), help="parameter(s) for the component",
55-
dest="params", nargs=2, type=str, action="append")
55+
dest="params", nargs=2, type=str, action="append", default=[])
5656
gen_language = op_generate.add_subparsers(
5757
metavar="LANGUAGE", help="language to generate code in",
5858
dest="language", required=True)
@@ -111,8 +111,9 @@ def dep_audit_hook(event, args):
111111
if args.operation in ("generate", "gen", "g"):
112112
if args.language == "verilog":
113113
# Generate Verilog file.
114-
from amaranth.back import verilog
115-
args.verilog_file.write(verilog.convert(component))
114+
if args.verilog_file:
115+
from amaranth.back import verilog
116+
args.verilog_file.write(verilog.convert(component))
116117

117118
# Generate dependency file.
118119
if args.verilog_file and args.dep_file:

0 commit comments

Comments
 (0)