#/usr/bin/shell

loc=fsms/

mkdir dc_run

for file in $@; do
    base=${file:0:${#file}-2};
    fname=$(echo $file | rev | cut -d'/' -f1 | rev)
    mdir=$(dirname $file) 

    designname=${fname:0:${#fname}-2}
    stimname=${designname}_stassign.v
    bmark=$(echo $designname | cut -d'_' -f1);

    cp $mdir/$bmark* .


    mv $bmark*stassign.v $stimname    
    
    
    echo "****Running DC Compiler on $bmark ***"

    sed -i '/`include/c\`include \"'$stimname'\";' $fname
    printf "set TOPLEVEL \"$designname\"\nset DESIGNS_LIST {\$TOPLEVEL}\n" > 'overrideTLDL.tcl'

    mkdir dc_run/$bmark

    dc_shell -f run_dc.tcl >& dc_run/$bmark/$designname.log
    echo "****Running Verilog to spice conversion on $designname ***"
    ./verilog2spice.pl netlists/$designname-gate.v
    
    echo "**** Moving $bmark spice results to $loc/$bmark ***"
    mkdir $loc/$bmark
    mkdir results/vergate/$bmark
    mv $designname*gate*.v.sp $loc/$bmark/$designname-gate.sp
    mv netlists/$designname*gate*.v results/vergate/$bmark/.
    echo "****Cleaning up...***"
    rm $bmark*
done