Convert enum methods on type-parameter fields. - #331
Conversation
Add EnumMethod pass and teach ParamType to substitute resolved enum-bearing type-parameter bindings so ara_req.emul.next() converts without a sed patch. Includes core tests for paramtype enum methods and scoped enum item values. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thank you for putting together this contribution! I have another implementation of enum method support from some time ago that I never quite wrapped up. My concern was that it seemed to slow things down, but it came with another bug fix or two that seemed worthwhile. IIRC, the design I had gone with avoided the first two limitations you listed. If I put this on a branch, would you be interested in reconciling these two designs? |
|
@zachjs Yes absolutely, I am not wedded to a particular way, in fact i was trying to emulate your style as much as I could. Share your branch an I will do my best to get it working, not sure if it is this PR or a different one, but lets get going, I have some time between projects at the moment so I am trying to tidy up some niggles I found along my way before I get stuck into the next one. |
I noticed! I appreciate your effort.
Thank you! Here you go: https://github.com/zachjs/sv2v/compare/enum-method |
|
I am looking at this now, the only problem is that the code base itself seems to trigger a number of issues, my goal is to get this to compile successfully in icaurs:
I have a fix that addresses all of these |
Awesome! Please send it over. I'm happy to help however I can! I got an email with a comment comparing |
Summary
Adds a new
Convert.EnumMethodpass that lowers SystemVerilog enum methods (next,prev,first,last,num) to synthesizable Verilog (IEEE 1800-2017 §6.19.5).Also fixes conversion when the enum lives inside a type-parameter binding (e.g. a struct field passed via
parameter type), which previously required manual preprocessing or left.next()in the output.This addresses some of the issues raised in #263
Changes
Convert.EnumMethod: new pass (runs afterConvert.Enumin the main pipeline). Rewrites enum methods to arithmetic or case/mux expressions; caches enum item values at declaration scope.Convert.Enum: preserveEnumnodes inParamTypedeclarations and in instance type bindings untilParamTypeinlines them.Convert.ParamType: treat resolvedEnumtypes as simple so enum-bearing bindings are substituted instead of deferred behind~-tagged template modules.enum_method,enum_method_scope,enum_method_paramtype; error test for non-constantnext(N)step.Motivation
Real RTL (e.g. PULP Ara
ara_dispatcher.sv) usesara_req.emul.next()whereemulis a field of a type passed asparameter type ara_req_t. Without this change, sv2v either leaves.next()in the Verilog or fails once enum types are stripped before the binding is resolved.Limitations
.name()is not converted.next/prevstep arguments are rejected (seetest/error/enum_method_var_step.sv).ParamTypesubstitution — usually when the parent module (e.g.ara.sv) is in the same sv2v invocation and binds.ara_req_t(ara_req_t). Convertingara_dispatcher.svalone without that binding still leavesemul.next().