Skip to content

Commit e32795f

Browse files
committed
lib.wiring: add support for array dimensions to ComponentMetadata.
1 parent e7d328b commit e32795f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

amaranth/lib/wiring.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,18 @@ class ComponentMetadata(Annotation):
17081708
schema = {
17091709
"$schema": "https://json-schema.org/draft/2020-12/schema",
17101710
"$id": "https://amaranth-lang.org/schema/amaranth/0.5/component.json",
1711+
"$defs": {
1712+
"dimensions": {
1713+
"type": "array",
1714+
"items": {
1715+
"type": "integer",
1716+
"minimum": 0,
1717+
},
1718+
},
1719+
"annotations": {
1720+
"type": "object",
1721+
},
1722+
},
17111723
"type": "object",
17121724
"properties": {
17131725
"interface": {
@@ -1742,6 +1754,9 @@ class ComponentMetadata(Annotation):
17421754
"type": "string",
17431755
"pattern": "^[+-]?[0-9]+$",
17441756
},
1757+
"dimensions": {
1758+
"$ref": "#/$defs/dimensions",
1759+
},
17451760
},
17461761
"additionalProperties": False,
17471762
"required": [
@@ -1751,6 +1766,7 @@ class ComponentMetadata(Annotation):
17511766
"width",
17521767
"signed",
17531768
"init",
1769+
"dimensions",
17541770
],
17551771
},
17561772
{
@@ -1762,14 +1778,18 @@ class ComponentMetadata(Annotation):
17621778
"members": {
17631779
"$ref": "#/properties/interface/properties/members",
17641780
},
1781+
"dimensions": {
1782+
"$ref": "#/$defs/dimensions",
1783+
},
17651784
"annotations": {
1766-
"type": "object",
1785+
"$ref": "#/$defs/annotations",
17671786
},
17681787
},
17691788
"additionalProperties": False,
17701789
"required": [
17711790
"type",
17721791
"members",
1792+
"dimensions",
17731793
"annotations",
17741794
],
17751795
},
@@ -1779,7 +1799,7 @@ class ComponentMetadata(Annotation):
17791799
"additionalProperties": False,
17801800
},
17811801
"annotations": {
1782-
"type": "object",
1802+
"$ref": "#/$defs/annotations",
17831803
},
17841804
},
17851805
"additionalProperties": False,
@@ -1839,6 +1859,7 @@ def describe_member(member, *, path):
18391859
"width": cast_shape.width,
18401860
"signed": cast_shape.signed,
18411861
"init": str(member._init_as_const.value),
1862+
"dimensions": list(member.dimensions),
18421863
}
18431864
elif member.is_signature:
18441865
return {
@@ -1847,6 +1868,7 @@ def describe_member(member, *, path):
18471868
name: describe_member(sub_member, path=(*path, name))
18481869
for name, sub_member in member.signature.members.items()
18491870
},
1871+
"dimensions": list(member.dimensions),
18501872
"annotations": {
18511873
annotation.schema["$id"]: annotation.as_json()
18521874
for annotation in member.signature.annotations(member)

tests/test_lib_wiring.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ def as_json(self):
11941194
class Signature1(Signature):
11951195
def __init__(self):
11961196
super().__init__({
1197-
"i": In(unsigned(8), init=42),
1197+
"i": In(unsigned(8), init=42).array(2).array(3),
11981198
"o": Out(signed(4))
11991199
})
12001200

@@ -1205,7 +1205,7 @@ class Signature2(Signature):
12051205
def __init__(self):
12061206
super().__init__({
12071207
"clk": In(1),
1208-
"foo": Out(Signature1()),
1208+
"foo": Out(Signature1()).array(4),
12091209
"oof": In(Signature1())
12101210
})
12111211

@@ -1227,6 +1227,7 @@ def __init__(self):
12271227
"width": 1,
12281228
"signed": False,
12291229
"init": "0",
1230+
"dimensions": [],
12301231
},
12311232
"foo": {
12321233
"type": "interface",
@@ -1238,6 +1239,7 @@ def __init__(self):
12381239
"width": 8,
12391240
"signed": False,
12401241
"init": "42",
1242+
"dimensions": [3, 2],
12411243
},
12421244
"o": {
12431245
"type": "port",
@@ -1246,8 +1248,10 @@ def __init__(self):
12461248
"width": 4,
12471249
"signed": True,
12481250
"init": "0",
1251+
"dimensions": [],
12491252
},
12501253
},
1254+
"dimensions": [4],
12511255
"annotations": {
12521256
"https://example.com/schema/foo/0.1/bar.json": {
12531257
"hello": True,
@@ -1264,6 +1268,7 @@ def __init__(self):
12641268
"width": 8,
12651269
"signed": False,
12661270
"init": "42",
1271+
"dimensions": [3, 2],
12671272
},
12681273
"o": {
12691274
"type": "port",
@@ -1272,8 +1277,10 @@ def __init__(self):
12721277
"width": 4,
12731278
"signed": True,
12741279
"init": "0",
1280+
"dimensions": [],
12751281
},
12761282
},
1283+
"dimensions": [],
12771284
"annotations": {
12781285
"https://example.com/schema/foo/0.1/bar.json": {
12791286
"hello": True,

0 commit comments

Comments
 (0)