#!/usr/bin/env python3 import sys, os, re, shutil import numpy as np max_span_hack = True pins = np.random.permutation(""" 1 2 3 4 7 8 9 10 11 12 19 22 23 24 25 26 28 29 31 32 33 34 37 38 41 42 43 44 45 47 48 52 56 58 60 61 62 63 64 73 74 75 76 78 79 80 81 87 88 90 91 95 96 97 98 101 102 104 105 106 107 112 113 114 115 116 117 118 119 120 121 122 134 135 136 137 138 139 141 142 143 144 """.split()) io_names = None mode = sys.argv[1] with open("%s.v" % sys.argv[1], "w") as f: if mode == "test0": io_names = [ "clk", "i0", "o0", "o1", "o2" ] print("module top(input clk, i0, output o0, o1, o2);", file=f) print(" reg [31:0] state;", file=f) print(" always @(posedge clk) state <= ((state << 5) + state) ^ i0;", file=f) print(" assign o0 = ^state, o1 = |state, o2 = state[31:16] + state[15:0];", file=f) print("endmodule", file=f) if mode == "test1": io_names = [ "clk", "i0", "i1", "i2", "i3", "o0", "o1", "o2", "o3" ] print("module top(input clk, i0, i1, i2, i3, output o0, o1, o2, o3);", file=f) print(" reg [15:0] din, dout;", file=f) print(" always @(posedge clk) din <= {din, i3, i2, i1, i0};", file=f) print(" always @(posedge clk) dout <= din + {din[7:0], din[15:8]};", file=f) print(" assign {o3, o2, o1, o0} = dout >> din;", file=f) print("endmodule", file=f) if mode == "test2": io_names = [ "clk", "i0", "i1", "i2", "i3", "o0", "o1", "o2", "o3" ] print(""" module top(input clk, i0, i1, i2, i3, output reg o0, o1, o2, o3); reg [7:0] raddr, waddr, rdata, wdata; reg [7:0] memory [0:255]; always @(posedge clk) begin case ({i0, i1, i2}) 0: raddr <= {raddr, i3}; 1: waddr <= {waddr, i3}; 2: wdata <= {wdata, i3}; 3: rdata <= memory[raddr]; 4: memory[waddr] <= wdata; 5: {o0, o1, o2, o3} <= rdata[3:0]; 6: {o0, o1, o2, o3} <= rdata[7:4]; endcase end endmodule """, file=f) if mode == "test3": io_names = [ "clk", "i0", "i1", "i2", "i3", "o0", "o1", "o2", "o3", "o4" ] print(""" module top(input clk, i0, i1, i2, i3, output reg o0, o1, o2, o3, o4); reg [9:0] raddr, waddr, rdata, wdata; reg [9:0] memory [0:1023]; always @(posedge clk) begin case ({i0, i1, i2}) 0: raddr <= {raddr, i3}; 1: waddr <= {waddr, i3}; 2: wdata <= {wdata, i3}; 3: rdata <= memory[raddr]; 4: memory[waddr] <= wdata; 5: rdata <= memory[waddr]; 6: {o0, o1, o2, o3, o4} <= rdata[4:0]; 7: {o0, o1, o2, o3, o4} <= rdata[9:5]; endcase end endmodule """, file=f) if mode == "test4": io_names = [ "clk", "i", "s", "o" ] print(""" module top(input clk, i, s, output reg o); reg re1, rclke