#/usr/local/bin/bash

for file in $@; do
    base=${file:0:${#file}-2};
    cp $base* .
    fname=$(echo $file | rev | cut -d'/' -f1 | rev)    
    designname=${fname:0:${#fname}-2}
    localfile="$designname.v";
    txttarget="include"
    txtreplace="\`include \""$designname"_stassign.v\";"
    txtreplace2="module "$designname" (RST, CLK, ptext, rtext);"
  
    sed -i "/include/c \ $txtreplace" $localfile
    sed -i "/^module/c \ $txtreplace2" $localfile
    printf "set TOPLEVEL \"$designname\"\nset DESIGNS_LIST {\$TOPLEVEL}\n" > 'overrideTLDL.tcl'
    dc_shell -f run_dc.tcl
done