In reply to dave_59:
Hello Dave !
Thanks for your inputs. Does the below code make sense as you suggested in your 1st way ? Is there any other better way ? bcoz if its random variable for the dynamic array then its fine but if we need to load up some specific values using constraints then its going to be cumbersome. Kindly provide your comments.
module pkt_stim;
class tran_pkt #(int pkt_size = 64);
rand bit [pkt_size-1:0] pkt;
rand bit A [];
rand bit B [];
rand bit C [];
rand bit D [];
constraint fld_size_c {
A.size <= pkt_size;
B.size <= pkt_size;
C.size <= pkt_size;
D.size <= pkt_size;
A.size + B.size + C.size + D.size == pkt_size;
}
function void post_randomize;
$display("Size A = %0d, B = %0d, C = %0d, D = %0d\n", A.size, B.size, C.size, D.size);
$display("pkt Value b4 streaming = %0h\n", pkt);
pkt = {>>{D,C,B,A}};
$display("pkt Value a8 streaming = %0h\n", pkt);
endfunction: post_randomize
function void print_inf;
$display("pkt_size = %0d\n", pkt_size);
$display("Size A = %0d, B = %0d, C = %0d, D = %0d\n", A.size, B.size, C.size, D.size);
foreach (A[i]) $display("A[%0d] %d\n", i, A[i]);
foreach (B[i]) $display("B[%0d] %d\n", i, B[i]);
foreach (C[i]) $display("C[%0d] %d\n", i, C[i]);
foreach (D[i]) $display("D[%0d] %d\n", i, D[i]);
$display("pkt Value = %0h\n", pkt);
endfunction: print_inf
endclass: tran_pkt
initial begin
tran_pkt tp = new();
assert(tp.randomize());
tp.print_inf();
end
endmodule: pkt_stim