rpc: add public Records as module ports.
authorJean-François Nguyen <jf@lambdaconcept.com>
Sun, 29 Sep 2019 22:12:17 +0000 (00:12 +0200)
committerwhitequark <cz@m-labs.hk>
Mon, 30 Sep 2019 18:28:21 +0000 (18:28 +0000)
nmigen/rpc.py

index ac193958fa2268fc5c58f524c0a030a18272c362..a03ec23c44d64cf8e5c2be31e1bdf402776abdff 100644 (file)
@@ -3,7 +3,7 @@ import json
 import argparse
 import importlib
 
-from .hdl import Signal, Elaboratable
+from .hdl import Signal, Record, Elaboratable
 from .back import rtlil
 
 
@@ -68,13 +68,12 @@ def _serve_yosys(modules):
 
             try:
                 elaboratable = modules[module_name](*args, **kwargs)
-                def has_port(elaboratable, port_name):
-                    # By convention, any public attribute that is a Signal is considered a port.
-                    return (not port_name.startswith("_") and
-                            isinstance(getattr(elaboratable, port_name), Signal))
-                ports = [getattr(elaboratable, port_name)
-                         for port_name in dir(elaboratable)
-                         if has_port(elaboratable, port_name)]
+                ports = []
+                # By convention, any public attribute that is a Signal or a Record is
+                # considered a port.
+                for port_name, port in vars(elaboratable).items():
+                    if not port_name.startswith("_") and isinstance(port, (Signal, Record)):
+                        ports += port._lhs_signals()
                 rtlil_text = rtlil.convert(elaboratable, name=module_name, ports=ports)
                 response = {"frontend": "ilang", "source": rtlil_text}
             except Exception as error: