Skip to content

Commit

Permalink
design flattening script
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghani committed May 17, 2023
1 parent dbd37ea commit 3dff393
Show file tree
Hide file tree
Showing 7 changed files with 433,355 additions and 0 deletions.
342,189 changes: 342,189 additions & 0 deletions top_level/design_instantiations_flattened.v

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions top_level/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import glob

sources = []

insts = ["" for _ in range(64)]

SKIP_DESIGNS = ["d10_wabib_tictactoe"]

# Populate all slots with placeholder
# which will be replaced if there exists a design
for i in range(64):
insts[i] = ""
insts[i] += f"// Design #{i}\n"
insts[i] += f"// Unpopulated design slot\n"
insts[i] += f"assign des_io_out[{i}] = 12'h000;\n"


for des in sorted(list(glob.glob("../designs/d*"))):
name = os.path.basename(des)
idx = int(name.split("_")[0].replace("d", ""))

if name in SKIP_DESIGNS:
print("Skipping", idx, name, des)
continue

sources.append(os.path.join(des, "flattened.v"))
print(idx, name, des)
insts[idx] = ""
insts[idx] += f"// Design #{idx}\n"
insts[idx] += f"// Design name {name}\n"
insts[idx] += f"{name} inst{idx} (\n"
insts[idx] += f" .io_in({{des_reset[{idx}], clock, des_io_in[{idx}]}}),\n"
insts[idx] += f" .io_out(des_io_out[{idx}])\n"
insts[idx] += f");\n"

insts = "\n\n".join(insts)

with open("insts.sv.template") as f:
insts = f.read().replace(r"{INSTANCES}", insts)

with open("insts_generated.sv", "w+") as f:
f.write(insts)

sources += ["multiplexer.sv", "insts_generated.sv"]

with open("sources.txt", "w+") as f:
f.write(" ".join(sources))

os.system("sv2v "+(" ".join(sources))+" > merged.v")
os.system("yosys -p 'read_verilog merged.v; proc; flatten; select design_instantiations; write_verilog -selected design_instantiations_flattened.v;'")
21 changes: 21 additions & 0 deletions top_level/insts.sv.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
`default_nettype none

module design_instantiations (
input logic [11:0] io_in,
output logic [11:0] io_out,

input logic [5:0] des_sel,
input logic hold_if_not_sel,

input logic clock, reset
);

logic [11:0] des_io_in[0:63];
logic [11:0] des_io_out[0:63];
logic des_reset[0:63];

multiplexer mux (.*);

{INSTANCES}

endmodule
Loading

0 comments on commit 3dff393

Please sign in to comment.