diff --git a/src/systemrdl/core/ExprVisitor.py b/src/systemrdl/core/ExprVisitor.py index 91bbd71..c8d3c79 100644 --- a/src/systemrdl/core/ExprVisitor.py +++ b/src/systemrdl/core/ExprVisitor.py @@ -118,7 +118,7 @@ def visitNumberVerilog(self, ctx: SystemRDLParser.NumberVerilogContext): src_ref_from_antlr(ctx.VLOG_INT()) ) - if val >= (1 << width): + if val.bit_length() > width: self.msg.fatal( "Value of integer literal exceeds the specified width", src_ref_from_antlr(ctx.VLOG_INT()) diff --git a/src/systemrdl/properties/builtin.py b/src/systemrdl/properties/builtin.py index c97bbcc..1fa43b9 100644 --- a/src/systemrdl/properties/builtin.py +++ b/src/systemrdl/properties/builtin.py @@ -76,7 +76,7 @@ def validate(self, node: m_node.Node, value: Any) -> None: # 5.2.2.1-a: If value is a bit mask, the mask shall have the same width # as the field if not isinstance(value, bool) and isinstance(value, int): - if value >= (1 << node.width): + if value.bit_length() > node.width: self.env.msg.error( "Bit mask (%d) of property 'dontcompare' exceeds width (%d) of field '%s'" % (value, node.width, node.inst_name), @@ -433,7 +433,7 @@ def validate(self, node: m_node.Node, value: Any) -> None: assert isinstance(node, m_node.FieldNode) if isinstance(value, int): # 9.5.1-c: The reset value cannot be larger than can fit in the field - if value >= (1 << node.width): + if value.bit_length() > node.width: self.env.msg.error( "The reset value (%d) of field '%s' cannot fit within its width (%d)" % (value, node.inst_name, node.width), diff --git a/src/systemrdl/properties/user_defined.py b/src/systemrdl/properties/user_defined.py index 0da49e6..3a1dba3 100644 --- a/src/systemrdl/properties/user_defined.py +++ b/src/systemrdl/properties/user_defined.py @@ -90,8 +90,8 @@ def validate(self, node: m_node.Node, value: Any) -> None: # Spec does not specify, but assuming this check gets ignored for # non-vector nodes - if isinstance(node, m_node.VectorNode): - if value >= (1 << node.width): + if isinstance(node, m_node.VectorNode) and isinstance(value, int): + if value.bit_length() > node.width: self.env.msg.error( "Value (%d) of the '%s' property cannot fit within the width (%d) of component '%s'" % (value, self.name, node.width, node.inst_name),