Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. typedef enum logic [1:0] {
  2. TWO_LEGS,
  3. FOUR_LEGS,
  4. SIX_LEGS,
  5. EIGHT_LEGS
  6. } leg_e;
  7.  
  8. typedef enum logic [2:0] {
  9. HUMAN,
  10. DOGS,
  11. CAT,
  12. ELEPHANT,
  13. FLY,
  14. COCKROACH,
  15. SPIDER
  16. } animal_e;
  17.  
  18. class parameterized_class #( type enum_type);
  19. static int initial_allocation;
  20. static enum_type list[$];
  21.  
  22. rand int unsigned ptr;
  23.  
  24. constraint ptr_c {
  25. ptr < list.size();
  26. }
  27.  
  28. function new();
  29. enum_type my_enum;
  30. if(initial_allocation == 0) begin
  31. initial_allocation = 1;
  32. for(int unsigned i = 0; i < my_enum.num(); i++)
  33. repeat($urandom_range(1,10)) list.push_back(my_enum);
  34. end
  35. endfunction
  36. endclass
  37.  
  38. class random_class;
  39. rand parameterized_class#(leg_e) leg_select;
  40. rand parameterized_class#(animal_e) animal_select;
  41.  
  42. rand leg_e leg_q[$];
  43. rand animal_e animal_q[$];
  44.  
  45. constraint leg_animal_c {
  46. leg_select.list[leg_select.ptr] == TWO_LEGS -> animal_select.list[animal_select.ptr] inside {HUMAN};
  47. leg_select.list[leg_select.ptr] == FOUR_LEGS -> animal_select.list[animal_select.ptr] inside {DOGS, CAT, ELEPHANT};
  48. leg_select.list[leg_select.ptr] == SIX_LEGS -> animal_select.list[animal_select.ptr] inside {FLY, COCKROACH};
  49. leg_select.list[leg_select.ptr] == EIGHT_LEGS -> animal_select.list[animal_select.ptr] inside {SPIDER};
  50. }
  51.  
  52. constraint q_c {
  53. leg_q.size() dist {[0:5] := 50, [6:10] := 50};
  54. animal_q.size() == leg_q.size();
  55. }
  56. function new();
  57. leg_select = new;
  58. animal_select = new;
  59. endfunction
  60. endclass
  61.  
  62. module tb;
  63. initial begin
  64. random_class rnd = new;
  65. repeat (10) begin
  66. rnd.randomize();
  67. $display("Animals in queue = %p", rnd.animal_q);
  68. $display("Legs in queue = %p", rnd.leg_q);
  69. end
  70. end
  71. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement