forked from Nic30/d3-hwschematic
/
verilog_to_json.sh
executable file
·47 lines (43 loc) · 1.11 KB
/
verilog_to_json.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Script expects one top file and verilog files.
# It creates json from the files using yosys.
help_message="Usage: $0 -t TOP FILE...\n\
TOP is top component in verilog to generate json for.\n\
FILE is a verilog input source file. Multiple file input is supported.\n\
\n\
The script generates json from verilog files using yosys."
while getopts "t:h" arg; do
case $arg in
h)
echo -e "$help_message"
exit 0;
;;
t)
top=$OPTARG
if test -z top; then
echo top is missing
exit 1
fi;
;;
?)
exit 1;
;;
esac
shift;
shift;
files=""
while test -n "$1"; do
files="$files $1"
shift
done;
done
# -noabc is used to avoid the dissolving of operators to elementary gates
# -noalumacc is used to keep comparators and arithmetic operators in original form
# -nordff is used to avoid the use of special DFFs
yosys -Q -p "read_verilog $files;"\
-p "hierarchy -top $top;"\
-p "synth -run coarse -noabc -noalumacc -nordff;"\
-p "splice"\
-p "#show -stretch; # show circuit in yosys graphviz"\
-p "write_json $top.json;"
exit $?