Experimental Cures for Flattened Register Definitions in vr_ad

On my current project, I had an issue with my register definitions. Quite a few of my DUT's registers where just instances of the same register type. My vr_ad register definitions were generated by a script, based on the specification, a flow that I'm pretty sure is very similar to what most of you also have. Instead of generating a nice regular structure, this script created a separate type for each register instance. What resulted was a flattened structure where I'd, for example, get one instance each of registers SOME_REG0, SOME_REG1, SOME_REG2, instead of three instances of SOME_REG. I was lucky enough to be able to (partly) change the definitions by patching them by hand.


This is a companion discussion topic for the original entry at https://verificationgentleman.netlify.app/2014/11/17/experimental-cures-for-flattened-reg-defs.html

You can also try this:

get_reg_side(reg_index : uint, side_index : uint) : uint is {
var reg := graphics_model.graphics_regs.get_reg_by_kind(appendf(“TRIANGLE%d”, reg_index).as_a(vr_ad_reg_kind));
var fld_name : string = appendf(“SIDE%d”, side_index);
var field_info := reg.static_info.fields_info.first(it.fld_name == fld_name);
return reg.get_cur_value()[(field_info.fld_fidx + field_info.fld_size - 1):field_info.fld_fidx];
};

You should also include protection for the values of reg_index and side_index

You’re right! This also removes the need to do reflection. I was so fixed on that idea that I forgot about get_reg_by_kind(…).

What I also usually do is define an extra method inside vr_ad_reg, called get_field_by_name(fld_name : string). This basically does what your snippet does (including asserts, etc.). I find it really handy.