File: t_constraint_assoc_arr_bad.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 (93 lines) | stat: -rwxr-xr-x 2,446 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
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
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by PlanV GmbH.
// SPDX-License-Identifier: CC0-1.0

// Long String index associative array
class AssocArrayString;
    rand int string_arr [string];

    constraint c {
        string_arr["a_very_long_string"] == 65;
    }
    function new();
        string_arr["a_very_long_string"] = 0;
    endfunction
endclass

class keyClass;
    int id;
    function new();
        id = 3;
    endfunction
endclass
// Class index associative array
class AssocArrayClass;
    rand bit [31:0] data [keyClass];
    keyClass cl;
    // constraint c4 { foreach (data[i]) data[i] > 0;} Unsupported index type for an associative array in an iterative constraint.
    constraint c1 { data[cl] > 0;} // Illegal index expression of unpacked type in constraint.
    function new();
        cl = new();
        data[cl] = 32'd77;
    endfunction
endclass

typedef struct {
    int a;
    int b;
} UnpackedIndexType;
// Struct (unpacked) index associative array
class AssocArrayUnpackedStruct;
    rand bit [31:0] data [UnpackedIndexType];
    constraint c2 { foreach (data[i]) data[i] < 100; } // Illegal non-integral expression in random constraint.

    function new();
        UnpackedIndexType idx;
        idx.a = 1;
        idx.b = 2;
        data[idx] = 32'd25;
    endfunction
endclass

// Array (unpacked) index associative array
typedef logic [2:0] IndexArrayType[3];
class AssocArrayArrayIndex;
    rand bit [31:0] data [IndexArrayType];
    constraint c3 { foreach (data[i]) data[i] > 0; }

    function new();
        IndexArrayType idx;
        for (int j = 0; j < 4; j++) begin
            idx[j] = 3'd0;
        end
        data[idx] = 32'd75;
    endfunction
endclass

module t_constraint_assoc_arr_bad;

    AssocArrayString test_str;
    AssocArrayClass test_cls;
    AssocArrayUnpackedStruct test_unp_struct;
    AssocArrayArrayIndex test_unp_arr;
    int success = 0;

    initial begin
        test_str = new();
        test_cls = new();
        test_unp_struct = new();
        test_unp_arr = new();

        success += test_str.randomize();
        success += test_cls.randomize();
        success += test_unp_struct.randomize();
        success += test_unp_arr.randomize();

        if(success != 4) $stop;

        $write("*-* All Finished *-*\n");
        $finish;
    end
endmodule