/* ---------------------------------------------------------------------------- * * tut3.tv * * This test is identical to tut2.tv, except that we now enable stricter type * checking by leaving '_StrictChecking' at its default level of 1. We use two * variables (i and j) which must both now be declared. * * Maia is broadly C-compatible at Level 1, *except* that you must use * correctly-sized expressions when directly driving or checking DUT ports and * internal signals. The right-hand side of the drive statements below test * the value of the 4-bit 'Q' output, and so must be 4-bit (there is an * exception if you test against an ordinary unsized integer, in which case * the size match requirement is dropped). * * One of the drive statements tests Q against 'i+5'. 'i' is 4-bit, and '5' * defaults to 32-bit, so this requires some thought. The code below shows two * ways to handle this. * * Note that 'i' is declared as a 'var4' (a 4-bit 'var'). It is therefore * unsigned, and 4-state (each bit can be '0', '1', 'x', or 'z'). It could be * used as a loop index, but this can be confusing with unsigned objects * (which are always >= 0). 'j' is therefore used for the loop count. 'j' is a * plain signed 2-state integer, with a default size (normally 32 bits), and * is used for the loop index. * * ------------------------------------------------------------------------- */ DUT { module Count4USL // copy the HDL module declaration here (input C, SLOAD, input [3:0] D, output [3:0] Q) create_clock C // declare the clock [C, SLOAD, D] -> [Q] // drive declaration } void test() { [.C, 1, 2] -> [2]; // load 2, test against 2 int j; var4 i = 2; [.C, 0, .X] -> [++i]; // turn off SLOAD, test against 3 [.C, -, -] -> [++i]; // SLOAD and D retain their previous values // unnecessary, but interesting: check expression sizes assert(i`size == 4); // we declared i with a size of 4 bits assert(5`size == 32); // unsized constants default to 32 bits assert((i + 5)`size == 32); // 32-bit addition expression assert((i +$4 5)`size == 4); // 4-bit addition expression for(j=0, i=0; j<16; j++, i++) { // [.C, -, -] -> [i + 5]; // syntax error: 4-bit Q, vs. 32-bit expr // [.C, -, -] -> [i + 4`d5]; // works: 4b var + 4b const = 4b result [.C, -, -] -> [i +$4 5]; // works: 4-bit adder } } void main() { [.C, 0, -] -> [.X]; // outputs unknown test(); } // ----------------------------------- EOF ------------------------------------