#!/usr/bin/perl
# Nelson Hu
# EE464H
# 08/06/03

#######################################################
# This Program "HspiceAUTO" does the following:
#  1)convert Spectre netlist (si.inp) to Hspice code by calling Spectre2Hspice.pl
#  2)run Hspice to the Hspice code
#  3)merge the output from Hspice into matrix tables by calling fallrisetable.pl

#######################################################
# how to use this program:
# at prompt, type
#    perl HspiceAUTO.pl

#######################################################
# Input:
#  none

#######################################################
# Output:
#  %CELLNAME%.sp -- Hspice code for Hspice
#  %CELLNAME%.mt0 up to %CELLNAME%.mt4 (depending on number of inputs)-- output file after Hspice is run
#  %CELLNAME%.mt0_Cell_rise --\
#  %CELLNAME%.mt0_Cell_fall ---\
#  %CELLNAME%.mt0_rise_skew ----- matrix table for each cell and each pin
#  %CELLNAME%.mt0_fall_skew ---/
#
#  All of the output file will be stored under the link
#  "/home/projects/abraham/vlsi464/spicetest/%CELLNAME%/"
#  as provided below

#######################################################
# "@files" contains all the cel lname to be processed
# the number after each cell name is the resolution for
# Hspice to use for calculation
#######################################################

@files = qw $inv1 5 inv2 3 inv4 2
             buf1 5 buf2 3 buf4 2
             nand2x1 4 nand2x2 3 nand2x4 2
             nand3x1 4 nand3x2 3 nand3x4 2
             nand4x1 4 nand4x2 3 nand4x4 2
             nand5x1 4 nand5x2 3 nand5x4 2
             nor2x1 4 nor2x2 3 nor2x4 2
             nor3x1 4 nor3x2 3 nor3x4 2
             nor4x1 4 nor4x2 3 nor4x4 2
             nor5x1 4 nor5x2 3 nor5x4 2
             and2x1 5 and2x2 3 and2x4 2
             and3x1 5 and3x2 3 and3x4 2
             and4x1 5 and4x2 3 and4x4 2
             and5x1 5 and5x2 3 and5x4 2
             or2x1 5 or2x2 3 or2x4 2
             or3x1 5 or3x2 3 or3x4 2
             or4x1 5 or4x2 3 or4x4 2
             or5x1 5 or5x2 3 or5x4 2 
             mux2 5
             xor2x1 4 xor2x2 3 xor2x4 2 $;

#######################################################
# splits "@files" into two arrays,
# one for file name, another for resolution
#######################################################
for (0..$#files){
    if ($_ % 2) {
	$reso[$_/2]=$files[$_];}
    else {$newfiles[$_/2]=$files[$_];}}

#######################################################
# creating all the Hspice (%CELLNAME%.sp) files
# calls Spectre2Hspice.pl to generate Hspice source code
# Spectre2Hspice.pl requires a value after input file for resolution 
#######################################################
$n=0;
foreach (@newfiles){
    system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/Spectre2Hspice.pl /home/projects/abraham/vlsi464/spicetest/$_/si.inp $reso[$n]";
    $n++;
    system "mv $_.sp /home/projects/abraham/vlsi464/spicetest/$_/";}

#######################################################
# run all the HSPICE on cells in "@files"....WOW
#######################################################
foreach (@newfiles){
    system "hspice /home/projects/abraham/vlsi464/spicetest/$_/$_.sp";
    system "mv $_.* /home/projects/abraham/vlsi464/spicetest/$_/";}

#######################################################
# matrix to table
# calls fallrisetable.pl to 
#######################################################
foreach (@newfiles){
  system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/fallrisetable.pl /home/projects/abraham/vlsi464/spicetest/$_/$_.mt0";
  system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/fallrisetable.pl /home/projects/abraham/vlsi464/spicetest/$_/$_.mt1";
  system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/fallrisetable.pl /home/projects/abraham/vlsi464/spicetest/$_/$_.mt2";
  system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/fallrisetable.pl /home/projects/abraham/vlsi464/spicetest/$_/$_.mt3";
  system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/fallrisetable.pl /home/projects/abraham/vlsi464/spicetest/$_/$_.mt4";
}



