File: t_gen_class.v

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (67 lines) | stat: -rw-r--r-- 1,952 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0

`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d:  got=%0x exp=%0x (%s !== %s)\n", `__FILE__,`__LINE__, (gotv), (expv), `"gotv`", `"expv`"); `stop; end while(0);
`define checks(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d:  got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);

module Child;
   int ch_value;
endmodule

module Parent;
   for (genvar i = 0; i < 10; i++) begin : gen_child
      Child child();
   end
endmodule

module t;
   Parent parent();

   virtual class ChildAgentBase;
      pure virtual task preload(int value);
      pure virtual function string name();
   endclass

   ChildAgentBase child_agents[10];

   for (genvar i = 0; i < 10; i++) begin : gfor
      class ChildAgent extends ChildAgentBase;
         task automatic preload(int value);
            parent.gen_child[i].child.ch_value = value;
         endtask
         function string name();
            return $sformatf("%m");
         endfunction
      endclass

      ChildAgent agent = new();

      initial child_agents[i] = agent;
   end

   task automatic preload_children;
      for (int i = 0; i < 10; i++) begin
         child_agents[i].preload(i);
      end
   endtask

   string s;

   initial begin
      #1;  // Ensure all class instances are initialized
      preload_children();
      `checkh(parent.gen_child[3].child.ch_value, 3);
      `checkh(parent.gen_child[8].child.ch_value, 8);
`ifdef VERILATOR
      // Some legal examples "t.gfor[4].\ChildAgent::name", "t.gfor[4].ChildAgent.name"
      `checks(child_agents[4].name(), "t.gfor[4].ChildAgent.name");
`endif
      $write("*-* All Finished *-*\n");
      $finish;
   end

endmodule