In reply to dave_59:
Thanks that helped. I have this follow up question.
prev = cmd8_t’(act);
- can I view it like this ?? since streaming operators work on the same bitstream types, here it is an enum with integer index(32 bits). after streaming of 32 bits into destination variable every time the casting is applied with enum type since streamed bits width matched with bitstream type width??
- Could you please comment abot the Method 3 i’m talking in the below code
`define axis1 1
`define axis2 1
`define axis3 4
typedef enum {unset, wr, rd} cmd;
typedef cmd cmd_arr[`axis1][`axis2][`axis3];
typedef cmd cmd8_t[8];
class test;
//cmd prev[8]; // store previous values
cmd8_t prev;
// assuming i have matched the cmd8_t to the total number of enum cmds in my_arr
// i can initialize my_arr in below methods but im looking for a way to initialize the array in method3
// *Method1: if the array size is more it will be tedious and i feel its not recommended way
// static cmd_arr my_arr[2] = '{0: '{default: rd}, 1: '{default: wr}};
// Method2: assign default array blocks to all indexes using the function
//static cmd_arr my_arr[2] = '{default: test::initArr()};
// Method3: initialize each index with different enum through mannual index access or some loop(for/foreach etc...)
// instead of initializing like this. >>> static cmd_arr my_arr[2] = '{0: test::initArr(rd), 1: test::initArr(wr)};
/*
is the below achieved only by writing another static method ??
static cmd_arr my_arr[3];
my_arr[0] = test::initArr(rd);
my_arr[1] = test::initArr(wr);
my_arr[2] = test::initArr(unset);
*/
extern function void pre_randomize();
extern static function cmd_arr initArr(cmd c);
endclass
function cmd_arr test::initArr(cmd c=unset);
cmd_arr temp;
temp = '{default: c};
return temp;
endfunction
function void test::pre_randomize();
prev = cmd8_t'(test::my_arr);
endfunction
module main;
initial begin
test t;
t = new();
t.randomize();
$display("%0p", t.prev);
$display("0: %0p \n1: %0p",test::my_arr[0], test::my_arr[1]);
foreach(t.prev[i]) $display("i: %0d cmd: %0s", i, t.prev[i]);
end
endmodule