pattern.sv 2.25 KB
Newer Older
1 2 3 4 5 6 7
module test;
    typedef struct packed {
        int w, x;
        byte y;
        logic z;
    } struct_a;
    struct_a a;
8 9 10 11 12
    wire signed [31:0] a_w, a_x;
    wire signed [7:0] a_y;
    assign a_w = a.w;
    assign a_x = a.x;
    assign a_y = a.y;
13
    initial begin
14 15 16
        // TODO: The signed fields should not have to be indirected here, but
        // iverilog does not currently support complex arguments to $monitor.
        $monitor("%2d: %b %b %b %b %b", $time, a, a_w, a_x, a_y, a.z);
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

        #1 a.w = 0;
        #1 a.x = 0;
        #1 a.y = 0;
        #1 a.z = 0;

        #1 a = '{default: 1};
        #1 a = '{default: 2};
        #1 a = '{default: 3};
        #1 a = '{default: 0};
        #1 a = '{default: -1};
        #1 a = '{default: -2};

        #1 a = '{int: 0, default: 1};
        #1 a = '{byte: 0, default: 1};
        #1 a = '{logic: 0, default: 1};
        #1 a = '{logic: 1, int: 2, byte: 3};
        #1 a = '{logic: 1, int: 2, byte: 3, default: -1};
        #1 a = '{int: 3, byte: 2, default: 0};

        #1 a = '{w: 8, int: 0, default: 1};
        #1 a = '{w: 8, byte: 0, default: 1};
        #1 a = '{w: 8, logic: 0, default: 1};
        #1 a = '{w: 8, logic: 1, int: 2, byte: 3};
        #1 a = '{w: 8, logic: 1, int: 2, byte: 3, default: -1};
        #1 a = '{w: 8, int: 3, byte: 2, default: 0};

    end
45 46 47 48 49 50
    typedef struct packed {
        int x;
        struct_a y;
        logic z;
    } struct_b;
    struct_b b;
51 52
    wire signed [31:0] b_x;
    assign b_x = b.x;
53 54
    initial begin
        #100;
55 56 57
        // TODO: The signed fields should not have to be indirected here, but
        // iverilog does not currently support complex arguments to $monitor.
        $monitor("%2d: %b %b %b %b", $time, b, b_x, b.y, b.z);
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

        #1 b.x = 0;
        #1 b.y = 0;
        #1 b.z = 0;

        #1 b = '{default: 1};
        #1 b = '{default: 2};
        #1 b = '{default: 3};
        #1 b = '{default: 0};
        #1 b = '{default: -1};
        #1 b = '{default: -2};

        #1 b = '{int: 0, default: 1};
        #1 b = '{byte: 0, default: 1};
        #1 b = '{logic: 0, default: 1};
        #1 b = '{logic: 1, int: 2, byte: 3};
        #1 b = '{logic: 1, int: 2, byte: 3, default: -1};
        #1 b = '{int: 3, byte: 2, default: 0};

    end
78 79 80
endmodule

module top; endmodule