Halona
Halona

Reputation: 1485

Specman: Is there a way to access different variables by some index?

in my verification environment I have 3 different registers with the same fields: load_0, load_1 and load_2. Now I have the same function duplicated 3 times for every register and differs only in one line:

duplicated_func_0() {
    value = timer_regs.load_0; //This is the only different line (in duplicated_func_1 - load_1 is substituted

    ...

};

Is there a better way to access variable name (that differs only by its index) than duplicate the same function 3 times? Something like this:

not_duplicated_func(index : uint) {
    value = timer_regs.load_%x; //Is there a way to put the input index in the variable name instead of %x?

};

I will appreciate any help you can provide.

Upvotes: 1

Views: 449

Answers (1)

Tudor Timi
Tudor Timi

Reputation: 7573

Inside timer_regs I wouldn't define 3 variables, load_0, load_1 and load_2, but a list of the respective type:

extend TIMER_REGS vr_ad_reg_file {
  loads[3] : list of TIMER_LOAD vr_ad_reg;
};

This way you can access each register by index.

If you can't change the layout you already have, just constrain each list item to be equal to your existing instances:

extend TIMER_REGS vr_ad_reg_file {
  loads[3] : list of TIMER_LOAD vr_ad_reg;
  keep loads[0] == load_0;
  keep loads[1] == load_1;
  keep loads[2] == load_2;
};

Upvotes: 1

Related Questions