Halona
Halona

Reputation: 1485

Specman e: Is there a way to extend multiple kinds of a struct?

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

Upvotes: 3

Views: 675

Answers (2)

Thorsten
Thorsten

Reputation: 700

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
    };
  };
};

Upvotes: 2

Tudor Timi
Tudor Timi

Reputation: 7573

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 {
    // ...
  };
};

Upvotes: 2

Related Questions