File: t_randomize_method_with_scoping.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 (115 lines) | stat: -rw-r--r-- 2,831 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Antmicro Ltd.
// SPDX-License-Identifier: CC0-1.0

class c1;
        rand int c1_f;
endclass
class c2;
        rand int c2_f;
endclass
localparam int PARAM = 42;
class Cls;
   rand int x;
   int q[$] = {0};
   rand enum {
      ONE_Y,
      TWO_Y
   } y;
   virtual function int get_x();
      return x;
   endfunction
endclass
class SubA extends Cls;
   c1 e = new;
   rand enum {
      AMBIG,
      ONE_A,
      TWO_A
   } en;
   function c1 get_c();
      return e;
   endfunction
   function int op(int v);
      return v + 1;
   endfunction
endclass
class SubB extends Cls;
   int z;
endclass
class SubC extends SubB;
   c2 e = new;
   rand enum {
      AMBIG,
      ONE_B,
      TWO_B
   } en;
   SubA f = new;
   function c2 get_c();
      return e;
   endfunction
   function int op(int v);
      return v - 1;
   endfunction
   function int doit;
      // access ambiguous names so width complains if we miss something
      doit = 1;

      f.x = 4;
      x = 5;
      doit = f.randomize() with { x == local::x; };
      if (f.x != x) $stop;

      z = 6;
      doit &= f.randomize() with { x == z; };
      if (f.x != z) $stop;

      doit &= f.randomize() with { e.c1_f == local::e.c2_f; };
      doit &= f.randomize() with { get_x() == local::get_x(); };
      doit &= f.randomize() with { get_c().c1_f == local::get_c().c2_f; };
      doit &= f.randomize() with { (get_c).c1_f == (local::get_c).c2_f; };

      f.y = ONE_Y;
      y = TWO_Y;
      doit &= f.randomize() with { y == local::y; };
      if (f.y != y) $stop;

      f.en = SubA::ONE_A;
      doit &= f.randomize() with { en == AMBIG; };
      if (doit != 1) $stop;
      if (f.en != SubA::AMBIG) $stop;

      doit &= f.randomize() with { x == PARAM; };
      if (doit != 1) $stop;
      if (f.x != PARAM) $stop;

      f.en = SubA::ONE_A;
      doit &= f.randomize() with { en == ONE_A; };
      doit &= f.randomize() with { local::en == local::AMBIG; };
      en = ONE_B;
      doit &= f.randomize() with { local::en == ONE_B; };

      doit &= f.randomize() with { x == local::op(op(0)); };
      if (f.x != 0) $stop;
      doit &= f.randomize() with { x == op(local::op(1)); };
      if (f.x != 1) $stop;
      doit &= f.randomize() with { x == local::op(op(local::op(op(0)))); };
      if (f.x != 0) $stop;
      doit &= f.randomize() with { x == op(local::op(op(local::op(1)))); };
      if (f.x != 1) $stop;
      doit &= f.randomize() with { foreach (q[i]) x == i; };
      if (f.x != 0) $stop;
   endfunction
endclass

module t (/*AUTOARG*/);
   SubC obj = new;

   initial begin
      if (obj.doit != 1) $stop;
      $write("*-* All Finished *-*\n");
      $finish;
   end
endmodule