lkolbly / ripstop

Apache License 2.0
0 stars 0 forks source link

Some tests to add #36

Open lkolbly opened 4 months ago

lkolbly commented 4 months ago

So, I have some old test files sitting in the repo. No sense in letting good test files go to waste, need to triage and determine which ones are good, which ones are completely nonsensical, and which ones represent a need for additional functionality:

### CODE

module duplicate_variable(bits<4> a) -> (bits<4> a) {
    a[t] = a[t];
}

### OUTPUT
// Should error
### CODE

module if_compound_condition(bit a, bit b, bit c) -> (bit all) {
    if a[t] && b[t] && c[t] {
        all[t] = 1;
    } else {
        all[t] = 0;
    }
}

### DATA
rst,a in 1,b in 1,c in 1,all out 1
1,0,0,0,0
0,1,0,0,0
0,1,1,1,1
0,1,0,1,0
### CODE

module shifter(bits<4> a) -> (bits<4> b) {
    b[t] = a[t][2:0] ++ 1'd0;
}

module instantiation_time(bits<4> a) -> (bits<4> b) {
    my_shifter.a[t] = a[t-1];
    b[t] = my_shifter.b[t-1];
    instantiate shifter as my_shifter;
}

### DATA
rst,a in 4,b out 4
1,0,x
0,1,x
0,2,x
0,3,2
0,12,4
0,x,6
0,x,8
### CODE

struct pixel {
    bits<8> r;
    bits<8> g;
    bits<8> b;
}

module pixelify(bits<8> r, bits<8> g, bits<8> b) -> (pixel pixel) {
    pixel.r[t] = r[t];
    pixel.g[t] = g[t];
    pixel.b[t] = b[t];
}

module unpixelify(pixel pixel) -> (bits<8> r, bits<8> g, bits<8> b) {
    r[t] = pixel.r[t];
    g[t] = pixel.g[t];
    b[t] = pixel.b[t];
}

module delay_pixel(pixel i) -> (pixel o) {
    o[t] = i[t-2];
}

module registered_struct(bits<8> r, bits<8> g, bits<8> b) -> (bits<8> r_o, bits<8> g_o, bits<8> b_o) {
    instantiate pixelify as pixelify;

    pixelify.r[t] = r[t];
    pixelify.g[t] = g[t];
    pixelify.b[t] = b[t];

    instantiate delay_pixel as delay_pixel;

    delay_pixel.i[t] = pixelify.pixel[t];

    instantiate unpixelify as unpixelify;

    unpixelify.pixel[t] = delay_pixel.o[t];

    r_o[t] = unpixelify.r[t];
    g_o[t] = unpixelify.g[t];
    b_o[t] = unpixelify.b[t];
}

### DATA
rst,r in 8,g in 8,b in 8,r_o out 8,g_o out 8,b_o out 8
1, 0,0,0,    x,x,x
0, 1,2,3,    x,x,x
0, 4,5,6,    x,x,x
0, 7,8,9,    1,2,3
0, 10,11,12, 4,5,6
0, 13,14,15, 7,8,9
0, 16,17,18, 10,11,12

This one almost certainly does not have the correct output. I think in general terms the code should work fine:

### CODE

module typecheck_reset() -> (bit a) {
    a[0] = 16'd0;
    a[t] = ~a[t-1];
}

### OUTPUT
Mismatched types: provided `bits<2>` but should have been `bits<1>` on line 3 col 16:
    a_out[t] = b[t];
               ^

Mismatched types: provided `bits<2>` but should have been `bits<1>` on line 4 col 21:
    b_out[t] = b[t] + a[t];
                    ^

I think there's multiple errors for each module in this one:

### CODE

module unset_result(bit a) -> (bit b) {
    //
}

module unset_instantiated_input(bit a) -> (bit b) {
    instantiate unset_result as child;

    b[t] = a[t];
}

struct twobits {
    bit bit0;
    bit bit1;
}

module unset_partial_result_struct(bit a, bit b) -> (twobits result) {
    result.bit0[t] = a[t];
}

### OUTPUT

Should throw three errors