Flatten the output of RecordObject.ports()
authorMichael Nolan <mtnolan2640@gmail.com>
Mon, 4 May 2020 17:07:07 +0000 (13:07 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Mon, 4 May 2020 17:08:57 +0000 (13:08 -0400)
If a record contains records, calling ports on it will give a result
that cannot be passed to the nmigen simulation backend. This flattens
it, so that ports() will just return signals

src/nmutil/iocontrol.py

index 853a1d040d9f6dcdfd48daee06674f94953b2f58..e403da7112cf575b0b74288307ae7b628f8f54f9 100644 (file)
@@ -103,7 +103,15 @@ class RecordObject(Record):
                 yield x
 
     def ports(self): # would be better being called "keys"
-        return list(self)
+        results = []
+        # If the record itself contains records, flatten them
+        for item in list(self):
+            ports_fun = getattr(item, "ports", None)
+            if callable(ports_fun):
+                results.extend(ports_fun())
+            else:
+                results.append(item)
+        return results
 
 
 class PrevControl(Elaboratable):