Is it not possible to cycle through an associative array during randomization ? For the below code, get the following error.
module assoc_array_cycling;
class config;
rand bit [7:0]my_pts[$];
endclass: config
class aac;
config cfg;
bit[7:0] agt_pts[string][$] = '{"alu0":'{0:'h11}, "cpu0":'{0:'h11, 1:'h22}};
function perform_opr;
cfg = new();
assert(cfg.randomize with {
cfg.my_pts.size() == agt_pts["cpu0"].size();
foreach(agt_pts["cpu0"][z])
my_pts[z] == agt_pts["cpu0"][z];
}) else $display("Randomization failed");
endfunction: perform_opr
endclass: aac
initial begin
aac aac_inst = new();
aac_inst.perform_opr();
end
endmodule: assoc_array_cycling
Error Message:
Error-[TCF-IIE] Illegal index expression
assoc_array_cycling.sv, 19
“this.my_pts[z]”
Expression of this type cannot be used to index the array
Thanks for your response. This is a basic example to represent my bigger issue. In that scenario, I can’t edit the my_pts code from queue to an dynamic array bcoz its a vip from a different team.
With that said, and even after changing the assignment code in the agt_pts I face the same issue. Aren’t there any other way to solve this out ? or is it not possible at all ?
THanks for your inputs. Had the reverse working at my end as well. But was wondering if cycleling through the assoc array during randomization isn’t possible at all?
The syntax is not legal, though simulators other than the one you are using support it. You are only allowed one set of 's in a foreach loop. Normally you would do there following to skip of iterating one of the dimensions:
foreach(agt_pts[,z])
But that doesn’t work when the z dimension is dynamically sized.
A few other non-standard code fragments
config is a reserved keyword
You cannot use an assignment pattern with named indexes to assign to a queue. Use array concatenation
You cannot initialize an implicitly static variable(aac_inst) in its declaration. People mistakenly think it gets initialized as part of entering the procedural block it in.