back.{verilog,rtlil}: in convert()
, accept a Component
without ports.
Closes #883.
This commit is contained in:
parent
87fbcedecf
commit
33c2246311
|
@ -6,6 +6,7 @@ import re
|
|||
|
||||
from .._utils import bits_for, flatten
|
||||
from ..hdl import ast, ir, mem, xfrm
|
||||
from ..lib import wiring
|
||||
|
||||
|
||||
__all__ = ["convert", "convert_fragment"]
|
||||
|
@ -1003,7 +1004,18 @@ def convert_fragment(fragment, name="top", *, emit_src=True):
|
|||
return str(builder), name_map
|
||||
|
||||
|
||||
def convert(elaboratable, name="top", platform=None, *, ports, emit_src=True, **kwargs):
|
||||
def convert(elaboratable, name="top", platform=None, *, ports=None, emit_src=True, **kwargs):
|
||||
if (ports is None and
|
||||
hasattr(elaboratable, "signature") and
|
||||
isinstance(elaboratable.signature, wiring.Signature)):
|
||||
ports = []
|
||||
for path, member, value in elaboratable.signature.flatten(elaboratable):
|
||||
if isinstance(value, ast.ValueCastable):
|
||||
value = value.as_value()
|
||||
if isinstance(value, ast.Value):
|
||||
ports.append(value)
|
||||
elif ports is None:
|
||||
raise TypeError("The `convert()` function requires a `ports=` argument")
|
||||
fragment = ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
|
||||
il_text, name_map = convert_fragment(fragment, name, emit_src=emit_src)
|
||||
return il_text
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import warnings
|
||||
|
||||
from .._toolchain.yosys import *
|
||||
from ..hdl import ir
|
||||
from ..hdl import ast, ir
|
||||
from ..lib import wiring
|
||||
from . import rtlil
|
||||
|
||||
|
||||
|
@ -45,8 +46,19 @@ def convert_fragment(*args, strip_internal_attrs=False, **kwargs):
|
|||
return _convert_rtlil_text(rtlil_text, strip_internal_attrs=strip_internal_attrs), name_map
|
||||
|
||||
|
||||
def convert(elaboratable, name="top", platform=None, *, ports, emit_src=True,
|
||||
def convert(elaboratable, name="top", platform=None, *, ports=None, emit_src=True,
|
||||
strip_internal_attrs=False, **kwargs):
|
||||
if (ports is None and
|
||||
hasattr(elaboratable, "signature") and
|
||||
isinstance(elaboratable.signature, wiring.Signature)):
|
||||
ports = []
|
||||
for path, member, value in elaboratable.signature.flatten(elaboratable):
|
||||
if isinstance(value, ast.ValueCastable):
|
||||
value = value.as_value()
|
||||
if isinstance(value, ast.Value):
|
||||
ports.append(value)
|
||||
elif ports is None:
|
||||
raise TypeError("The `convert()` function requires a `ports=` argument")
|
||||
fragment = ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
|
||||
verilog_text, name_map = convert_fragment(fragment, name, emit_src=emit_src, strip_internal_attrs=strip_internal_attrs)
|
||||
return verilog_text
|
||||
|
|
Loading…
Reference in a new issue