|
6 | 6 |
|
7 | 7 | from .._utils import bits_for, flatten
|
8 | 8 | from ..hdl import ast, ir, mem, xfrm
|
| 9 | +from ..lib import wiring |
9 | 10 |
|
10 | 11 |
|
11 | 12 | __all__ = ["convert", "convert_fragment"]
|
@@ -1003,7 +1004,18 @@ def convert_fragment(fragment, name="top", *, emit_src=True):
|
1003 | 1004 | return str(builder), name_map
|
1004 | 1005 |
|
1005 | 1006 |
|
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") |
1007 | 1019 | fragment = ir.Fragment.get(elaboratable, platform).prepare(ports=ports, **kwargs)
|
1008 | 1020 | il_text, name_map = convert_fragment(fragment, name, emit_src=emit_src)
|
1009 | 1021 | return il_text
|
0 commit comments