Skip to content

Commit

Permalink
lib.fifo: annotate for use with CLI. (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Sep 6, 2023
1 parent b0e43eb commit 6dfed2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
20 changes: 16 additions & 4 deletions amaranth/lib/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .. import *
from ..asserts import *
from .._utils import log2_int
from .wiring import Signature, In, Out
from .coding import GrayEncoder, GrayDecoder
from .cdc import FFSynchronizer, AsyncFFSynchronizer

Expand Down Expand Up @@ -64,7 +65,7 @@ class FIFOInterface:
w_attributes="",
r_attributes="")

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

@property
def signature(self):
return Signature({

Check warning on line 91 in amaranth/lib/fifo.py

View check run for this annotation

Codecov / codecov/patch

amaranth/lib/fifo.py#L91

Added line #L91 was not covered by tests
"w_data": In(self.width),
"w_rdy": Out(1),
"w_en": In(1),
"r_data": Out(self.width),
"r_rdy": Out(1),
"w_en": In(1),
})


def _incr(signal, modulo):
if modulo == 2 ** len(signal):
Expand Down Expand Up @@ -116,7 +128,7 @@ class SyncFIFO(Elaboratable, FIFOInterface):
r_attributes="",
w_attributes="")

def __init__(self, *, width, depth, fwft=True):
def __init__(self, *, width: int, depth: int, fwft=True):
super().__init__(width=width, depth=depth, fwft=fwft)

self.level = Signal(range(depth + 1))
Expand Down Expand Up @@ -220,7 +232,7 @@ class SyncFIFOBuffered(Elaboratable, FIFOInterface):
r_attributes="",
w_attributes="")

def __init__(self, *, width, depth):
def __init__(self, *, width: int, depth: int):
super().__init__(width=width, depth=depth, fwft=True)

self.level = Signal(range(depth + 1))
Expand Down Expand Up @@ -295,7 +307,7 @@ class AsyncFIFO(Elaboratable, FIFOInterface):
""".strip(),
w_attributes="")

def __init__(self, *, width, depth, r_domain="read", w_domain="write", exact_depth=False):
def __init__(self, *, width: int, depth: int, r_domain="read", w_domain="write", exact_depth=False):
if depth != 0:
try:
depth_bits = log2_int(depth, need_pow2=exact_depth)
Expand Down
7 changes: 4 additions & 3 deletions amaranth_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def component(reference):
dest="component", type=component)
op_generate.add_argument(
"-p", "--param", metavar=("NAME", "VALUE"), help="parameter(s) for the component",
dest="params", nargs=2, type=str, action="append")
dest="params", nargs=2, type=str, action="append", default=[])
gen_language = op_generate.add_subparsers(
metavar="LANGUAGE", help="language to generate code in",
dest="language", required=True)
Expand Down Expand Up @@ -111,8 +111,9 @@ def dep_audit_hook(event, args):
if args.operation in ("generate", "gen", "g"):
if args.language == "verilog":
# Generate Verilog file.
from amaranth.back import verilog
args.verilog_file.write(verilog.convert(component))
if args.verilog_file:
from amaranth.back import verilog
args.verilog_file.write(verilog.convert(component))

# Generate dependency file.
if args.verilog_file and args.dep_file:
Expand Down

0 comments on commit 6dfed2e

Please sign in to comment.