A cumbersome way to iterate over a struct can be to use a union to contain the struct. It is a tedious way but gets the intent of cycling over a struct.
typedef struct packed {
int a;
int b;
} x_s;
typedef enum {a, b} x_e; //not needed but just helps in identifying the struct members
typedef union {
x_s x;
int xs[2]; //2 because of 2 integer members of the struct
} x_u;
virtual function void cycle_thru_struct();
x_e v_e;
x_u v_u;
v_u.x.a = 10;
v_u.x.b = 20;
//One way is this but no way to know the name of the struct member
foreach (v_u.xs[i]) begin
`uvm_info("cycle_thru_struct", $sformatf("struct-member[%d] = %0d", i , v_u.xs[i]), UVM_MEDIUM)
end
//Other way is this where an enum needs to carry the struct member names
for(int i=0; i< v_e.num(); i++) begin
`uvm_info("cycle_thru_struct", $sformatf("%s : 0x%x", v_e.name(), v_u.xs[i]), UVM_MEDIUM)
v_e = v_e.next();
end
endfunction : cycle_thru_struct