Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef enum logic [1:0] {
- TWO_LEGS,
- FOUR_LEGS,
- SIX_LEGS,
- EIGHT_LEGS
- } leg_e;
- typedef enum logic [2:0] {
- HUMAN,
- DOGS,
- CAT,
- ELEPHANT,
- FLY,
- COCKROACH,
- SPIDER
- } animal_e;
- class parameterized_class #( type enum_type);
- static int initial_allocation;
- static enum_type list[$];
- rand int unsigned ptr;
- constraint ptr_c {
- ptr < list.size();
- }
- function new();
- enum_type my_enum;
- if(initial_allocation == 0) begin
- initial_allocation = 1;
- for(int unsigned i = 0; i < my_enum.num(); i++)
- repeat($urandom_range(1,10)) list.push_back(my_enum);
- end
- endfunction
- endclass
- class random_class;
- rand parameterized_class#(leg_e) leg_select;
- rand parameterized_class#(animal_e) animal_select;
- rand leg_e leg_q[$];
- rand animal_e animal_q[$];
- constraint leg_animal_c {
- leg_select.list[leg_select.ptr] == TWO_LEGS -> animal_select.list[animal_select.ptr] inside {HUMAN};
- leg_select.list[leg_select.ptr] == FOUR_LEGS -> animal_select.list[animal_select.ptr] inside {DOGS, CAT, ELEPHANT};
- leg_select.list[leg_select.ptr] == SIX_LEGS -> animal_select.list[animal_select.ptr] inside {FLY, COCKROACH};
- leg_select.list[leg_select.ptr] == EIGHT_LEGS -> animal_select.list[animal_select.ptr] inside {SPIDER};
- }
- constraint q_c {
- leg_q.size() dist {[0:5] := 50, [6:10] := 50};
- animal_q.size() == leg_q.size();
- }
- function new();
- leg_select = new;
- animal_select = new;
- endfunction
- endclass
- module tb;
- initial begin
- random_class rnd = new;
- repeat (10) begin
- rnd.randomize();
- $display("Animals in queue = %p", rnd.animal_q);
- $display("Legs in queue = %p", rnd.leg_q);
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement