3

in my verification environment we work with vr_ad UVM package, where there is a general struct for a register vr_ad_reg which has been extended with different type for every register in the environment, etc:

reg_def TIMER_LOAD_0 TIMER 20'h00010 {
    reg_fld timer_load : uint : RW : 0xffff;
}:

The vr_ad_reg has predefined function post_access(), which I would like to extend for every register type that starts with the word 'TIMER'. Is there a way to do it? For example:

extend TIMER_* vr_ad_reg { //The intention here to extend the vr_ad_reg for all types that starts with the word TIMER
        post_access() is also {
            var some_var : uint;
        };
    }

Thank you for your help

Halona
  • 1,475
  • 1
  • 15
  • 26

2 Answers2

2

There's no built in construct to extend multiple sub-types. What you can do however is use a macro based solution. Team Specman had a blog post on this topic: http://www.cadence.com/Community/blogs/fv/archive/2009/10/20/extending-multiple-when-subtypes-simultaneously.aspx

They created a define as computed macro that takes multiple sub-types and extends those:

  define <multi_when'statement> "extend \[<detr'name>,...\] <base'type> (<MEMBERS {<struct_member>;...})" as computed {
    for each in <detr'names> do {
      result = appendf("%s extend %s %s %s;",result,it,<base'type>,<MEMBERS>);
    };
  };

You can then use like so:

extend [ TIMER_LOAD_0, TIMER_LOAD_1, TIMER_LOAD_2 ] vr_ad_reg {
  post_access() is also {
    // ...
  };
};
Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
  • 1
    This is a good solution, indeed, and you just need to keep in mind one important point. It doesn't really create "common" code, but rather it duplicates the same code under different subtypes. For example, if you add a field called 'x', there will be several different 'x' fields under each of the subtypes, and not one "shared" field. – Yuri Tsoglin Sep 18 '14 at 08:35
2

If you have a lot of registers that match your expression or you don't know the exact name beforehand, you might want to consider using a run-time solution:

extend vr_reg {
  post_access() is also {
    var some_var: uint;
    if str_match(kind.as_a(string), "/^TIMER_*/") {
    ... // do stuff for the TIMER_* registers
    };
  };
};
Thorsten
  • 710
  • 8
  • 17