Skip to content

Commit

Permalink
Fix comparison of default udp assignment with api model. #213
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed May 9, 2024
1 parent 917eb0e commit f1d6a47
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion systemrdl/properties/rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .. import rdltypes
from ..core.helpers import get_all_subclasses
from ..ast.ast_node import ASTNode

if TYPE_CHECKING:
from ..compiler import RDLEnvironment
Expand Down Expand Up @@ -61,7 +62,12 @@ def register_udp(self, udp: UserProperty, src_ref: 'SourceRefBase') -> None:
"The property definition for the feature extension '%s' uses a different 'type' definition from what this tool expects." % udp.name,
src_ref
)
if existing_udp.default_assignment != udp.default_assignment:

if isinstance(udp.default_assignment, ASTNode):
udp_default_assign_value = udp.default_assignment.get_value()
else:
udp_default_assign_value = udp.default_assignment
if existing_udp.default_assignment != udp_default_assign_value:
self.env.msg.error(
"The property definition for the feature extension '%s' uses a different 'default' definition from what this tool expects." % udp.name,
src_ref
Expand Down
21 changes: 21 additions & 0 deletions test/rdl_src/udp_types.rdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
property int_udp {
type = longint;
default = 123;
component = all;
};

property bool_udp {
type = boolean;
default = false;
component = all;
};


addrmap top {
reg {
field {
int_udp;
bool_udp;
} defaults;
} x;
};
28 changes: 28 additions & 0 deletions test/test_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ def validate(self, node, value) -> None:
with self.assertRaises(RDLCompileError):
rdlc.elaborate("top")

def test_udp_types(self):
root = self.compile(
["rdl_src/udp_types.rdl"],
"top"
)
field = root.find_by_path("top.x.defaults")
self.assertEqual(field.get_property("int_udp"), 123)
self.assertEqual(field.get_property("bool_udp"), False)

def test_soft_udp_types(self):
class IntUDP(UDPDefinition):
name = "int_udp"
valid_type = int
default_assignment = 123
class BoolUDP(UDPDefinition):
name = "bool_udp"
valid_type = bool
default_assignment = False
rdlc = RDLCompiler()
rdlc.register_udp(IntUDP)
rdlc.register_udp(BoolUDP)
rdlc.compile_file(os.path.join(this_dir, "rdl_src/udp_types.rdl"))
root = rdlc.elaborate("top")

field = root.find_by_path("top.x.defaults")
self.assertEqual(field.get_property("int_udp"), 123)
self.assertEqual(field.get_property("bool_udp"), False)

def test_soft_udp_undeclared(self):
class MyUDP(UDPDefinition):
name = "int_udp"
Expand Down

0 comments on commit f1d6a47

Please sign in to comment.