diff --git a/synth.sh b/synth.sh index f3f7523..a093203 100755 --- a/synth.sh +++ b/synth.sh @@ -1,199 +1,162 @@ #!/bin/bash BBDD_SCRIPT="yosys/bbdd_synth_muxxor.ys" BDD_SCRIPT="yosys/bdd_synth.ys" -NEM_SCRIPT="yosys/nem_synth.ys" MUXIG_SCRIPT="yosys/muxig_synth.ys" -SIFTING_SCRIPT="yosys/bbdd_sifting.ys" -NO_FLATTEN_SCRIPT="yosys/no_flatten.ys" TEMP_DIR="temp" -DATA_DIR="data" LIBERTY_FILE="liberty/nem_thesis.lib" TIMEOUT="2m" #1 minute timeout for now TECHMAP_BBDD="yosys/techmap_bbdd.v" print_options(){ echo "(1) Synthesis Verilog file with bbdd optimization" echo "(2) Synthesis Verilog file with bdd optimization" echo "(3) Synthesis Verilog file with muxig optimization" - echo "(4) Synthesis all optimization" - echo "(5) Test sifting function" - echo "(6) No flatten pass" - echo "(7) Check equality of two .blif files" echo "(e) Exit" } safe_path() { local unsafe_path="$1" echo "$(printf '%s\n' "$unsafe_path" | sed 's/[&/\]/\\&/g')" } process_input() { file_name=$(basename "$file_path") # with extension file_base="${file_name%.*}" # without # get top module name read -p "top module [default=${file_base}] " top_module top_module=${top_module:-${file_base}} #safe_file_path=$(printf '%s\n' "$file_path" | sed 's/[&/\]/\\&/g') safe_file_path=$(safe_path "$file_path") #safe_techmap_path=$(printf '%s\n' "$TECHMAP_BBDD" | sed 's/[&/\]/\\&/g') } run_yosys() { # Run yosys if $nosat; then sat_replacement="#" # comment out {{SAT}} else sat_replacement="" # replace {{SAT}} with nothing fi echo "Synthesising $file_base" sed -e "s/{{VERILOG_FILE}}/$safe_file_path/g" \ -e "s/{{TEMP_DIR}}/$TEMP_DIR/g" \ -e "s/{{TOP_MODULE}}/$top_module/g" \ -e "s/{{BASE_NAME}}/$file_base/g" \ -e "s/{{TECHMAP_BBDD}}/$safe_techmap_path/g" \ -e "s/{{LIBERTY_FILE}}/$safe_liberty_path/g" \ -e "s/{{OUT_DIR}}/$safe_out_path/g" \ -e "s/{{TIMEOUT}}/$TIMEOUT/g" \ -e "s/{{SAT}}/$sat_replacement/g" \ "$yosys_script" > "$TEMP_DIR/${file_base}_synth.ys" mkdir -p ${out_dir}/${file_base}/ /usr/bin/time -f "Time: %E\nCPU: %P\nMemory: %M KB" -o ${out_dir}/${file_base}/yosys_${opt_name}_time.txt yosys${yosys_flags} ${TEMP_DIR}/${file_base}_synth.ys if [ -e ${out_dir}/${file_base} ]; then python ./yosys/print_summary.py ${out_dir}/${file_base} else echo "${file_base} did not finish in time" fi } synth_verilog() { local yosys_script="$1" local opt_name="$2" if ! $verbose; then yosys_flags=" -q" # is quite mode else yosys_flags="" fi safe_techmap_path=$(safe_path "$TECHMAP_BBDD") safe_liberty_path=$(safe_path "$LIBERTY_FILE") echo "Using script: $yosys_script" read -e -p 'Input file path: ' file_path # Get Output Dir read -e -p 'Output directory: ' out_dir safe_out_path=$(safe_path "$out_dir") out_dir="${out_dir%/}/" if [ -f "$file_path" ]; then process_input run_yosys if ! $nocleanup; then rm ${TEMP_DIR}/${file_base}_synth.ys rm ${TEMP_DIR}/${file_base}.blif rm -f ${TEMP_DIR}/${file_base}_bbdd.blif rm -f ${TEMP_DIR}/${file_base}_bdd.blif fi exit elif [ -d "$file_path" ]; then # extend / if not present file_path="${file_path%/}/" for file in "$file_path"*.v; do if [ -e "$file" ]; then safe_file_path=$(safe_path "$file") file_name=$(basename "$file") # with extension file_base="${file_name%.*}" # without top_module="$file_base" yosys_flags=" -q" run_yosys if ! $nocleanup; then rm ${TEMP_DIR}/${file_base}_synth.ys rm ${TEMP_DIR}/${file_base}.blif rm -f ${TEMP_DIR}/${file_base}_bbdd.blif rm -f ${TEMP_DIR}/${file_base}_bdd.blif fi fi done exit else echo "[ERROR] File ${file_path} does not exist" fi } -compare_blif() { - read -e -p 'Golden model: ' golden_path - read -e -p 'File to check: ' bbdd_path - if [ -e "$golden_path" ] && [ -e "$bbdd_path" ]; then - - file_name=$(basename "$golden_path") # with extension - file_base="${file_name%.*}" # without extension - - # get top module name - read -p "top module [default=${file_base}] " top_module - top_module=${top_module:-${file_base}} - - safe_golden_path=$(printf '%s\n' "$golden_path" | sed 's/[&/\]/\\&/g') - safe_bbdd_path=$(printf '%s\n' "$bbdd_path" | sed 's/[&/\]/\\&/g') - safe_techmap_path=$(printf '%s\n' "$TECHMAP_BBDD" | sed 's/[&/\]/\\&/g') - sed -e "s/{{TOP_MODULE}}/$top_module/g" -e "s/{{GOLDEN_MODULE}}/$safe_golden_path/g" -e "s/{{BBDD_MODULE}}/$safe_bbdd_path/g" -e "s/{{TECHMAP_BBDD}}/$safe_techmap_path/g" "yosys/sat.ys" > "$TEMP_DIR/${file_base}_sat.ys" - - yosys ${TEMP_DIR}/${file_base}_sat.ys - rm ${TEMP_DIR}/${file_base}_sat.ys - exit - else - echo "[ERROR] File ${file_path} does not exist" - fi -} - handle_selection() { case "$1" in 1) synth_verilog $BBDD_SCRIPT "bbdd";; 2) synth_verilog $BDD_SCRIPT "bdd";; 3) synth_verilog $MUXIG_SCRIPT "muxig";; - 4) synth_verilog $NEM_SCRIPT "nem";; - 5) synth_verilog $SIFTING_SCRIPT "bbdd";; - 6) synth_verilog $NO_FLATTEN_SCRIPT "bbdd";; - 7) compare_blif;; e) echo "Exiting..."; exit 0 ;; *) echo "Invalid option. Please try again." ;; esac } # Initialize booleans as false nocleanup=false nosat=false verbose=false # Parse flags while [[ $# -gt 0 ]]; do case "$1" in -nocleanup) nocleanup=true shift ;; -nosat) nosat=true shift ;; -v) verbose=true shift ;; *) echo "Unknown option: $1" exit 1 ;; esac done # get input file mkdir -p $TEMP_DIR while true; do if [ "$nosat" = false ]; then echo "Satisfiability check is enabled" fi print_options - read -p "Enter your choice [1-6]: " choice + read -p "Enter your choice [1-3]: " choice handle_selection "$choice" echo "" done