blob: 067b02b900f9b92844a41e213085d30b56ee21f0 [file] [log] [blame] [edit]
# Copyright 2020 Project U-Ray Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import numpy as np
root = sys.argv[1]
with open(root + "/leaftap/top.sv", "w") as f:
print("module top(input [7:0] clk, input d, output q);", file=f)
q = "d"
for c in range(8):
for x in range(200*c, 200*(c+1)):
depth = np.random.randint(5, 38)
print("wire [%d:0] lutchain_%d;" % (depth, x), file=f)
print("assign lutchain_%d[0] = %s;" % (x, q), file=f)
for i in range(depth):
print("(* keep, dont_touch *) LUT1 #(.INIT(2)) lut_%d_%d (.I0(lutchain_%d[%d]), .O(lutchain_%d[%d]));" % (x, i, x, i, x, i+1), file=f)
print("reg q_%d;" % x, file=f)
q = "q_%d" % x
print("always @(posedge clk[%d]) %s <= lutchain_%d[%d];" % (c, q, x, depth), file=f)
print("assign q = %s;\n" % q, file=f)
print("endmodule", file=f)