Skip to content

Commit 9b8989e

Browse files
committed
Added supprot for UDP pointing to node within an array
1 parent 0c5f47d commit 9b8989e

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/peakrdl_python/lib/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
from itertools import product
2727
from enum import IntEnum, Enum, auto
2828
import math
29+
import re
2930

3031
from .callbacks import CallbackSet, CallbackSetLegacy
3132

3233
UDPStruct = dict[str, 'UDPType']
3334
UDPType = Union[str, int, bool, IntEnum, UDPStruct]
3435

36+
array_instance_re = re.compile(r'(?P<root_name>[A-Za-z_0-9]*)\[(?P<index>\d+)\]')
37+
3538
class Base(ABC):
3639
"""
3740
base class of for all types
@@ -229,6 +232,18 @@ def get_child_by_system_rdl_name(self, name: Any) -> Any:
229232
"""
230233
if not isinstance(name, str):
231234
raise TypeError(f'name must be a string got {type(name)}')
235+
236+
# check if an array style child pointer
237+
array_name_match = array_instance_re.match(name)
238+
if array_name_match:
239+
root_name = array_name_match.group("root_name")
240+
index = int(array_name_match.group("index"))
241+
child_array = getattr(self, self.systemrdl_python_child_name_map[root_name])
242+
if not isinstance(child_array, NodeArray):
243+
raise ValueError('attempting to use array indexing into a non-array '
244+
f'node: {root_name} of type:{type(child_array)}')
245+
return child_array[index]
246+
232247
return getattr(self, self.systemrdl_python_child_name_map[name])
233248

234249
@property

tests/testcases/udp_with_referencing.rdl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ property regfile_child_pointer {
4949
component = regfile;
5050
};
5151

52+
property mem_child_pointer {
53+
type = reg[];
54+
component = mem;
55+
};
56+
5257
addrmap udp_with_referencing {
5358

5459
reg reg_def {
@@ -74,6 +79,7 @@ addrmap udp_with_referencing {
7479
memwidth = 32;
7580

7681
reg_def reg_value;
82+
mem_child_pointer = '{ reg_value } ;
7783
};
7884

7985
addrmap addrmap_def {
@@ -83,10 +89,10 @@ addrmap udp_with_referencing {
8389
addrmap_child_pointer = addrmap_child'{ reg_children:'{ reg_value }, regfile_children:'{ regfile_value } };
8490
};
8591
reg_def reg_value;
86-
regfile_def regfile_value;
92+
regfile_def addrmap_regfile_value;
8793
external mem_def mem_value;
8894
inner_addrmap_def addrmap_value;
89-
addrmap_child_pointer = addrmap_child'{ reg_children:'{ reg_value }, regfile_children:'{ regfile_value }, addrmap_children:'{ addrmap_value }, mem_children:'{ mem_value } };
95+
addrmap_child_pointer = addrmap_child'{ reg_children:'{ reg_value }, regfile_children:'{ addrmap_regfile_value }, addrmap_children:'{ addrmap_value }, mem_children:'{ mem_value } };
9096
};
9197

9298
addrmap_def main;
@@ -96,4 +102,13 @@ addrmap udp_with_referencing {
96102
view.reg_value.field_a->field_parent_pointer = main.reg_value;
97103

98104
view.reg_value->register_pointer = main.reg_value;
105+
106+
reg basic_reg_def {
107+
// a register def without any UDPs
108+
field { fieldwidth=4; } field_a;
109+
};
110+
111+
basic_reg_def basic_reg_array[3];
112+
main.addrmap_value.reg_value -> register_pointer = basic_reg_array[0];
113+
main.addrmap_value.regfile_value.reg_value -> register_pointer = basic_reg_array[1];
99114
};

0 commit comments

Comments
 (0)