Skip to content

Commit 33c2246

Browse files
committed
back.{verilog,rtlil}: in convert(), accept a Component without ports.
Closes #883.
1 parent 87fbced commit 33c2246

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

amaranth/back/rtlil.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .._utils import bits_for, flatten
88
from ..hdl import ast, ir, mem, xfrm
9+
from ..lib import wiring
910

1011

1112
__all__ = ["convert", "convert_fragment"]
@@ -1003,7 +1004,18 @@ def convert_fragment(fragment, name="top", *, emit_src=True):
10031004
return str(builder), name_map
10041005

10051006

1006-
def convert(elaboratable, name="top", platform=None, *, ports, emit_src=True, **kwargs):
1007+
def convert(elaboratable, name="top", platform=None, *, ports=None, emit_src=True, **kwargs):
1008+
if (ports is None and
1009+
hasattr(elaboratable, "signature") and
1010+
isinstance(elaboratable.signature, wiring.Signature)):
1011+
ports = []
1012+
for path, member, value in elaboratable.signature.flatten(elaboratable):
1013+
if isinstance(value, ast.ValueCastable):
1014+
value = value.as_value()
1015+
if isinstance(value, ast.Value):
1016+
ports.append(value)
1017+
elif ports is None:
1018+
raise TypeError("The `convert()` function requires a `ports=` argument")
10071019
fragment = ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
10081020
il_text, name_map = convert_fragment(fragment, name, emit_src=emit_src)
10091021
return il_text

amaranth/back/verilog.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import warnings
22

33
from .._toolchain.yosys import *
4-
from ..hdl import ir
4+
from ..hdl import ast, ir
5+
from ..lib import wiring
56
from . import rtlil
67

78

@@ -45,8 +46,19 @@ def convert_fragment(*args, strip_internal_attrs=False, **kwargs):
4546
return _convert_rtlil_text(rtlil_text, strip_internal_attrs=strip_internal_attrs), name_map
4647

4748

48-
def convert(elaboratable, name="top", platform=None, *, ports, emit_src=True,
49+
def convert(elaboratable, name="top", platform=None, *, ports=None, emit_src=True,
4950
strip_internal_attrs=False, **kwargs):
51+
if (ports is None and
52+
hasattr(elaboratable, "signature") and
53+
isinstance(elaboratable.signature, wiring.Signature)):
54+
ports = []
55+
for path, member, value in elaboratable.signature.flatten(elaboratable):
56+
if isinstance(value, ast.ValueCastable):
57+
value = value.as_value()
58+
if isinstance(value, ast.Value):
59+
ports.append(value)
60+
elif ports is None:
61+
raise TypeError("The `convert()` function requires a `ports=` argument")
5062
fragment = ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
5163
verilog_text, name_map = convert_fragment(fragment, name, emit_src=emit_src, strip_internal_attrs=strip_internal_attrs)
5264
return verilog_text

0 commit comments

Comments
 (0)