Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. // set_type_override_by_type
  2. `include "uvm.svh"
  3. import uvm_pkg::*;
  4. //--------------------uvm_component------------------------------
  5. class A extends uvm_agent;
  6. `uvm_component_utils(A)
  7.  
  8. function new (string name="A", uvm_component parent);
  9. super.new(name, parent);
  10. `uvm_info(get_full_name, $sformatf("A new"), UVM_LOW);
  11. endfunction : new
  12.  
  13. virtual function void hello();
  14. `uvm_info(get_full_name, $sformatf("HELLO from Original class 'A'"), UVM_LOW);
  15. endfunction : hello
  16. endclass : A
  17.  
  18. class A_ovr extends A;
  19. `uvm_component_utils(A_ovr)
  20.  
  21. function new (string name="A_ovr", uvm_component parent);
  22. super.new(name, parent);
  23. `uvm_info(get_full_name, $sformatf("A_ovr new"), UVM_LOW);
  24. endfunction : new
  25.  
  26. function void hello();
  27. `uvm_info(get_full_name, $sformatf("HELLO from override class 'A_ovr'"), UVM_LOW);
  28. endfunction : hello
  29. endclass : A_ovr
  30.  
  31. //--------------------uvm_object------------------------------
  32. class B extends uvm_object;
  33. `uvm_object_utils(B)
  34.  
  35. function new (string name="B");
  36. super.new(name);
  37. `uvm_info(get_full_name, $sformatf("B new"), UVM_LOW);
  38. endfunction : new
  39.  
  40. virtual function void hello();
  41. `uvm_info(get_full_name, $sformatf("HELLO from Original class 'B'"), UVM_LOW);
  42. endfunction : hello
  43. endclass : B
  44.  
  45. class B_ovr extends B;
  46. `uvm_object_utils(B_ovr)
  47.  
  48. function new (string name="B_ovr");
  49. super.new(name);
  50. `uvm_info(get_full_name, $sformatf("B_ovr new"), UVM_LOW);
  51. endfunction : new
  52.  
  53. function void hello();
  54. `uvm_info(get_full_name, $sformatf("HELLO from override class 'B_ovr'"), UVM_LOW);
  55. endfunction : hello
  56. endclass : B_ovr
  57.  
  58. class B_override extends B_ovr;
  59. `uvm_object_utils(B_override)
  60.  
  61. function new (string name="B_override");
  62. super.new(name);
  63. `uvm_info(get_full_name, $sformatf("B_override new"), UVM_LOW);
  64. endfunction : new
  65.  
  66. function void hello();
  67. `uvm_info(get_full_name, $sformatf("HELLO from override class 'B_override'"), UVM_LOW);
  68. endfunction : hello
  69. endclass : B_override
  70.  
  71. //--------------------env class--------------------
  72. class environment extends uvm_env;
  73. `uvm_component_utils(environment)
  74. A a1;
  75. B b1, b2;
  76.  
  77. function new(string name="environment", uvm_component parent);
  78. super.new(name, parent);
  79. endfunction : new
  80.  
  81. function void build_phase(uvm_phase phase);
  82. super.build_phase(phase);
  83. // arguments of create method:
  84. // 1. string name = ""
  85. // 2. uvm_component parent = null
  86. // 3. string contxt = ""
  87. // The contxt argument, if supplied, supercedes the parent's context.
  88. a1 = A::type_id::create("a1", this);
  89. b1 = B::type_id::create("b1", , "path1");
  90. b2 = B::type_id::create("b2", , "path2");
  91.  
  92. void'(a1.hello()); // This will print from overridden class A_ovr
  93. void'(b1.hello()); // This will print from overridden class B_override
  94. void'(b2.hello()); // This will print from overridden class B_override
  95. endfunction : build_phase
  96. endclass : environment
  97.  
  98. //-------------------test class--------------------------
  99. class test extends uvm_test;
  100. `uvm_component_utils(test)
  101. environment env;
  102.  
  103. function new(string name = "test", uvm_component parent = null);
  104. super.new(name, parent);
  105. endfunction : new
  106.  
  107. virtual function void build_phase(uvm_phase phase);
  108. super.build_phase(phase);
  109. env = environment::type_id::create("env", this);
  110. `uvm_info(get_full_name, $sformatf("TEST set_inst_override_by_name"), UVM_LOW);
  111.  
  112. factory.set_type_override_by_type(A::get_type(), A_ovr::get_type()); // Working
  113.  
  114. factory.set_type_override_by_type(B::get_type(), B_override::get_type()); // Working
  115.  
  116. factory.print(); // This will print info about overridden classes.
  117. endfunction : build_phase
  118. endclass : test
  119.  
  120. module top();
  121. initial begin
  122. run_test("test");
  123. end
  124. endmodule : top
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement