Re: [PATCH 03/13] verification/rvgen: Implement state and transition parser based on Lark

From: Gabriele Monaco

Date: Wed May 06 2026 - 10:48:44 EST



Looks good, although I need to put more effort to understand the grammar.
There's an issue parsing events though:

> +class EventLabelParser:
> +    grammar = r'''
> +    events: event ("\\n" event)*
> +
> +    event: name (";" guard)*
> +
> +    guard: reset
> +         | rule
> +         | rule reset
> +         | reset rule
> +
> +    name: CNAME
> +
> +    reset: "reset" "(" ENV ")"
> +
> +    %import common.CNAME
> +    %import common.WS
> +    %ignore WS
> +    ''' + ConstraintRule.grammar
> +
> +    class GetEvents(lark.visitors.Transformer):
> +        def guard(self, args):
> +            reset = None
> +            rule = None
> +            for arg in args:
> +                if arg.data == "reset":
> +                    reset = ConstraintReset(arg.children[0])
> +                elif arg.data == "rule":
> +                    conditions = arg.children
> +                    rule = ConstraintRule(conditions[0])
> +                    for i in range(1, len(conditions), 2):
> +                        rule.chain(conditions[i], conditions[i + 1])
> +            return reset, rule
> +
> +        def OP(self, args):
> +            return args
> +
> +        def condition(self, args):
> +            return ConstraintCondition(*args)
> +
> +        def event(self, args):
> +            name = args[0]
> +            rule, reset = None, None
> +            if len(args) == 2:
> +                reset, rule = args[1]
> +            return name, reset, rule

I'm not sure if it could be solved better changing the grammar, but this doesn't
work in case we have both a reset and a rule, e.g.:

"event2;env1 == 0;reset(clk)"

It apparently saves only one of them, the other would end up in args[2].

Doing this seems to fix:

diff --git a/tools/verification/rvgen/rvgen/automata.py
b/tools/verification/rvgen/rvgen/automata.py
index cc42b8127fc0..10534f956cc3 100644
--- a/tools/verification/rvgen/rvgen/automata.py
+++ b/tools/verification/rvgen/rvgen/automata.py
@@ -314,8 +314,11 @@ class EventLabelParser:
def event(self, args):
name = args[0]
rule, reset = None, None
- if len(args) == 2:
- reset, rule = args[1]
+ for _reset, _rule in args[1:]:
+ if _reset:
+ reset = _reset
+ if _rule:
+ rule = _rule
return name, reset, rule

def events(self, args):

Thanks,
Gabriele