Skip to content

Commit 7b48374

Browse files
committed
Rename ArrayPlaceholder class to ArrayedType. Added some more UDP testcases
1 parent 75180db commit 7b48374

File tree

14 files changed

+60
-31
lines changed

14 files changed

+60
-31
lines changed

systemrdl/ast/cast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def is_castable(src: Any, dst: Any) -> bool:
142142
if ((src in [int, bool]) or rdltypes.is_user_enum(src)) and (dst in [int, bool]):
143143
# Pure numeric or enum can be cast to a numeric
144144
return True
145-
elif isinstance(src, rdltypes.ArrayPlaceholder) and isinstance(dst, rdltypes.ArrayPlaceholder):
145+
elif isinstance(src, rdltypes.ArrayedType) and isinstance(dst, rdltypes.ArrayedType):
146146
# Check that array element types also match
147147
if src.element_type is None:
148148
# indeterminate array type. Is castable

systemrdl/ast/literals.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,25 @@ def __init__(self, env: 'RDLEnvironment', src_ref: 'OptionalSourceRef', elements
120120
super().__init__(env, src_ref)
121121
self.elements = elements
122122

123-
def predict_type(self) -> rdltypes.ArrayPlaceholder:
123+
def predict_type(self) -> rdltypes.ArrayedType:
124124

125125
if not self.elements:
126126
# Empty array. Element type is indeterminate
127-
return rdltypes.ArrayPlaceholder(None)
127+
return rdltypes.ArrayedType(None)
128128

129129
# Get type of first element
130130
element_iter = iter(self.elements)
131131
uniform_type = next(element_iter).predict_type()
132132

133133
# RDL does not allow directly nested arrays
134-
assert not isinstance(uniform_type, rdltypes.ArrayPlaceholder)
134+
assert not isinstance(uniform_type, rdltypes.ArrayedType)
135135

136136
# All elements of the array shall have a uniform type
137137
for element in element_iter:
138138
this_type = element.predict_type()
139139

140140
# RDL does not allow directly nested arrays
141-
assert not isinstance(this_type, rdltypes.ArrayPlaceholder)
141+
assert not isinstance(this_type, rdltypes.ArrayedType)
142142

143143
# First check if it is a direct match
144144
if uniform_type == this_type:
@@ -176,7 +176,7 @@ def predict_type(self) -> rdltypes.ArrayPlaceholder:
176176
self.src_ref
177177
)
178178

179-
return rdltypes.ArrayPlaceholder(uniform_type)
179+
return rdltypes.ArrayedType(uniform_type)
180180

181181
def get_value(self, eval_width: Optional[int]=None) -> List[Any]:
182182
result = []

systemrdl/ast/references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ def predict_type(self) -> 'PreElabRDLType':
5454
)
5555

5656
array_type = self.array.predict_type()
57-
if not isinstance(array_type, rdltypes.ArrayPlaceholder):
57+
if not isinstance(array_type, rdltypes.ArrayedType):
5858
self.msg.fatal(
5959
"Cannot index non-array type",
6060
self.array.src_ref
6161
)
62-
assert isinstance(array_type, rdltypes.ArrayPlaceholder)
62+
assert isinstance(array_type, rdltypes.ArrayedType)
6363

6464
return array_type.element_type
6565

systemrdl/core/ComponentVisitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ def visitParam_def_elem(self, ctx: SystemRDLParser.Param_def_elemContext) -> Par
512512
param_data_type = self.datatype_from_token(data_type_token)
513513
if ctx.array_type_suffix() is None:
514514
# Non-array type
515-
param_type = param_data_type # type: Union[Type[Union[int, str, bool, rdltypes.BuiltinEnum, rdltypes.UserEnum, rdltypes.UserStruct, rdltypes.references.RefType, comp.Component]], rdltypes.ArrayPlaceholder]
515+
param_type = param_data_type # type: Union[Type[Union[int, str, bool, rdltypes.BuiltinEnum, rdltypes.UserEnum, rdltypes.UserStruct, rdltypes.references.RefType, comp.Component]], rdltypes.ArrayedType]
516516
else:
517517
# Array-like type
518-
param_type = rdltypes.ArrayPlaceholder(param_data_type)
518+
param_type = rdltypes.ArrayedType(param_data_type)
519519

520520
# Get parameter name
521521
param_name = get_ID_text(ctx.ID())

systemrdl/core/StructVisitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def visitStruct_elem(self, ctx: SystemRDLParser.Struct_elemContext):
8181
member_type = self.visit(ctx.struct_type())
8282

8383
if ctx.array_type_suffix() is not None:
84-
member_type = rdltypes.ArrayPlaceholder(member_type)
84+
member_type = rdltypes.ArrayedType(member_type)
8585

8686
return member_type, member_name, member_src_ref
8787

systemrdl/core/UDPVisitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .. import rdltypes
1616

1717
if TYPE_CHECKING:
18-
from typing import Optional, Union, Any, Set, Tuple
18+
from typing import Optional, Union, Any, Set
1919
from ..compiler import RDLCompiler
2020

2121
class UDPVisitor(BaseVisitor):
@@ -124,7 +124,7 @@ def visitUdp_type(self, ctx: SystemRDLParser.Udp_typeContext) -> None:
124124
is_array = ctx.array_type_suffix() is not None
125125
if is_array:
126126
# arrayify
127-
valid_type = rdltypes.ArrayPlaceholder(valid_type) # type: ignore
127+
valid_type = rdltypes.ArrayedType(valid_type) # type: ignore
128128

129129
self._valid_type = valid_type
130130

systemrdl/properties/builtin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ class Prop_hdl_path_gate(PropertyRule):
221221

222222
class Prop_hdl_path_gate_slice(PropertyRule):
223223
bindable_to = {comp.Field, comp.Mem}
224-
valid_types = (rdltypes.ArrayPlaceholder(str),)
224+
valid_types = (rdltypes.ArrayedType(str),)
225225
default = None
226226
dyn_assign_allowed = True
227227

228228

229229
class Prop_hdl_path_slice(PropertyRule):
230230
bindable_to = {comp.Field, comp.Mem}
231-
valid_types = (rdltypes.ArrayPlaceholder(str),)
231+
valid_types = (rdltypes.ArrayedType(str),)
232232
default = None
233233
dyn_assign_allowed = True
234234

systemrdl/properties/user_defined.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def constr_componentwidth(self) -> bool:
3838

3939
@property
4040
def valid_types(self) -> Tuple[Any, ...]: # type: ignore
41-
if isinstance(self.valid_type, rdltypes.ArrayPlaceholder):
41+
if isinstance(self.valid_type, rdltypes.ArrayedType):
4242
return (self.valid_type,)
4343
if issubclass(self.valid_type, rdltypes.references.RefType):
4444
return self.valid_type.expanded

systemrdl/py.typed

Whitespace-only changes.

systemrdl/rdltypes/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
from .user_struct import UserStruct, is_user_struct
1010

11-
from .array import ArrayPlaceholder
11+
from .array import ArrayedType
1212

13-
from .references import ComponentRef, PropertyReference
13+
from .references import ComponentRef, PropertyReference, RefType
1414

1515
if TYPE_CHECKING:
1616
from .typing import PreElabRDLType
@@ -32,7 +32,7 @@ def get_rdltype(value: Any) -> 'PreElabRDLType':
3232
elif isinstance(value, BuiltinEnum):
3333
return type(value)
3434
elif isinstance(value, list):
35-
# Create ArrayPlaceholder representation
35+
# Create ArrayedType representation
3636
# Determine element type and make sure it is uniform
3737
array_el_type = None # type: Optional[PreElabRDLType]
3838
for el in value:
@@ -43,7 +43,7 @@ def get_rdltype(value: Any) -> 'PreElabRDLType':
4343
if (array_el_type is not None) and (el_type != array_el_type):
4444
return None
4545
array_el_type = el_type
46-
return ArrayPlaceholder(array_el_type)
46+
return ArrayedType(array_el_type)
4747
else:
4848
return None
4949

0 commit comments

Comments
 (0)