#!/bin/sh
# Automatically generated by Tool Builder Interface V1.0. 
# File: freessini   (Don't edit this file.) 

# 14-May-2009
#
############### OPTIONAL PARAMETERES 
# -exe		= Name of program
# -s		= Silent Mode
# -int		= Interactive Mode
# -batch	= Batch File Mode
# -iter		= Number of Iterations
# -startck	= Starting Cycle
# -lregs	= Number of Logical Regs
# -pregs	= Number of Physical Regs
# -pstruct	= Pipeline Structure
# -unilsu	= Unified LSU
# -ioi		= In-Order Issue
# -ioc		= In-Order Complete
# -unidi	= Unified Dispatch/Issue
# -fw		= Fetch Width
# -dw		= Decode Width
# -pw		= Dispatch Width
# -iw		= Issue Width
# -ww		= Write-Back Width
# -cw		= Commit Width
# -wins		= Instruction Window Size
# -robs		= Reorder Buffer Size
# -afu		= Number of Int. FU
# -alat		= Latency of INT ALU FU
# -mfu		= Number of Mult. FU
# -mlat		= Latency of Mult. FU
# -mpipe	= Pipelinization of Mult.
# -ffu		= Number of FP FU
# -xfu		= Number of FP Mult. FU
# -lfu		= Number of Load FU
# -llat		= Latency of Load FU
# -lpipe	= Pipelinization of Load
# -sfu		= Number of Store FU
# -slat		= Latency of Store FU
# -spipe	= Pipelinization of Store
# -bfu		= Number of Branch FU
# -blat		= Latency of Branch FU
# -lqs		= Load Queue Size
# -sqs		= Store Queue Size
# -spec		= Enable Speculation
# -wblat	= Write Back Latency
# -logfile	= Log File
#

#

# scr1=tool_name=name of this script without 3 trailing characters
  scr1=`echo $0 | awk -F/ '{l = length($NF); printf("%s", substr($NF, 1, l - 3))}'`


# scr=script name
  scr=`basename $0`
# bas=base directory
  bas1=`sh -c "type $0|cut -d\  -f 3"`
  bas=`echo $bas1 | awk -F'/' \
     '{printf("%s", $1); for (i = 2; i < NF; ++i) printf("/%s", $i); }'`
# isl=is a link?
  isl=`ls -F $0 | awk '/@/{print 1}'`
# tnm=true name
  if [ "$isl" = "1" ]; then
     tnm=`ls -l $0 |awk -F'>' '{print $2}' | awk '{print $1}'`
     chr=`echo $tnm | awk '{printf("%s", substr($1, 1, 1))}'`
     if [ ! "$chr" = "/" ]; then Tnm=$bas/$tnm; else Tnm=$tnm; fi
  else
     tnm=$0; Tnm=$0
  fi
# chr=first character
  chr=`echo $Tnm | awk '{printf("%s", substr($1, 1, 1))}'`
# cur=current directory holding this script
  if [ "$chr" = "/" ]; then
     cur=`echo $Tnm | awk -F/ \
        '{for (i = 1; i < NF - 1; ++i) printf("/%s", $(i + 1)); }'`
  else
     cur=$bas
  fi

##########################################################################
#### TEMPLATE
#### tem=template path name
###  ttt=freess
###  ccc="."
###  tem=$ccc/$ttt.tem                        # Precedence to dir '.'
###  if [ ! -f $tem ]; then                # If template not present here
###     ccc=$cur
###     tem=$ccc/$ttt.tem                  #   check for default template
###     if [ ! -f $tem ]; then
###        echo "Cannot find template file '$tem' nor './$ttt.tem'"
###        exit
###     fi
###  fi
###  echo "Template file is '$tem'" 
##########################################################################


# Defaults
progname=program
silent=no
interactive=yes
batch=no
iterations=3
start_ck=0
lregs=8
pregs=24
pipestruct=FDPIXWC
uni_lsu=yes
io_issue=no
io_complete=no
uni_di=yes
f_width=4
d_width=4
p_width=4
i_width=4
w_width=4
c_width=4
win_size=16
rob_size=16
int_fu=4
a_lat=0
im_fu=1
im_lat=4
im_pipe=yes
fp_fu=4
fm_fu=1
l_fu=1
l_lat=2
l_pipe=yes
s_fu=1
s_lat=1
s_pipe=yes
b_fu=1
b_lat=0
lqsize=1
sqsize=1
speculation=yes
wblat=0
logfile=def.log


# Command line parsing
c="0"
version="0"
auto="0"
help="0"
while [ $# -gt 0 ]; do
   firstc=`echo "$1" | awk '{ printf("%s", substr($1, 1, 1)) }'`
   if [ "'$1'" = "'-v'" ]; then
      version="1"; shift
   elif [ "'$1'" = "'-d'" ]; then
      debug="1"; shift
   elif [ "'$1'" = "'-auto'" ]; then
      auto="1"; shift
   elif [ "'$1'" = "'-help'" ]; then
      help="1"; shift
   elif [ "'$1'" = "'-template'" ]; then
      template="1"; shift
   elif [ "'$1'" = "'-exe'" ]; then
      shift
      progname=$1
      shift
   elif [ "'$1'" = "'-s'" ]; then
      shift
      silent=$1
      shift
   elif [ "'$1'" = "'-int'" ]; then
      shift
      interactive=$1
      shift
   elif [ "'$1'" = "'-batch'" ]; then
      shift
      batch=$1
      shift
   elif [ "'$1'" = "'-iter'" ]; then
      shift
      iterations=$1
      shift
   elif [ "'$1'" = "'-startck'" ]; then
      shift
      start_ck=$1
      shift
   elif [ "'$1'" = "'-lregs'" ]; then
      shift
      lregs=$1
      shift
   elif [ "'$1'" = "'-pregs'" ]; then
      shift
      pregs=$1
      shift
   elif [ "'$1'" = "'-pstruct'" ]; then
      shift
      pipestruct=$1
      shift
   elif [ "'$1'" = "'-unilsu'" ]; then
      shift
      uni_lsu=$1
      shift
   elif [ "'$1'" = "'-ioi'" ]; then
      shift
      io_issue=$1
      shift
   elif [ "'$1'" = "'-ioc'" ]; then
      shift
      io_complete=$1
      shift
   elif [ "'$1'" = "'-unidi'" ]; then
      shift
      uni_di=$1
      shift
   elif [ "'$1'" = "'-fw'" ]; then
      shift
      f_width=$1
      shift
   elif [ "'$1'" = "'-dw'" ]; then
      shift
      d_width=$1
      shift
   elif [ "'$1'" = "'-pw'" ]; then
      shift
      p_width=$1
      shift
   elif [ "'$1'" = "'-iw'" ]; then
      shift
      i_width=$1
      shift
   elif [ "'$1'" = "'-ww'" ]; then
      shift
      w_width=$1
      shift
   elif [ "'$1'" = "'-cw'" ]; then
      shift
      c_width=$1
      shift
   elif [ "'$1'" = "'-wins'" ]; then
      shift
      win_size=$1
      shift
   elif [ "'$1'" = "'-robs'" ]; then
      shift
      rob_size=$1
      shift
   elif [ "'$1'" = "'-afu'" ]; then
      shift
      int_fu=$1
      shift
   elif [ "'$1'" = "'-alat'" ]; then
      shift
      a_lat=$1
      shift
   elif [ "'$1'" = "'-mfu'" ]; then
      shift
      im_fu=$1
      shift
   elif [ "'$1'" = "'-mlat'" ]; then
      shift
      im_lat=$1
      shift
   elif [ "'$1'" = "'-mpipe'" ]; then
      shift
      im_pipe=$1
      shift
   elif [ "'$1'" = "'-ffu'" ]; then
      shift
      fp_fu=$1
      shift
   elif [ "'$1'" = "'-xfu'" ]; then
      shift
      fm_fu=$1
      shift
   elif [ "'$1'" = "'-lfu'" ]; then
      shift
      l_fu=$1
      shift
   elif [ "'$1'" = "'-llat'" ]; then
      shift
      l_lat=$1
      shift
   elif [ "'$1'" = "'-lpipe'" ]; then
      shift
      l_pipe=$1
      shift
   elif [ "'$1'" = "'-sfu'" ]; then
      shift
      s_fu=$1
      shift
   elif [ "'$1'" = "'-slat'" ]; then
      shift
      s_lat=$1
      shift
   elif [ "'$1'" = "'-spipe'" ]; then
      shift
      s_pipe=$1
      shift
   elif [ "'$1'" = "'-bfu'" ]; then
      shift
      b_fu=$1
      shift
   elif [ "'$1'" = "'-blat'" ]; then
      shift
      b_lat=$1
      shift
   elif [ "'$1'" = "'-lqs'" ]; then
      shift
      lqsize=$1
      shift
   elif [ "'$1'" = "'-sqs'" ]; then
      shift
      sqsize=$1
      shift
   elif [ "'$1'" = "'-spec'" ]; then
      shift
      speculation=$1
      shift
   elif [ "'$1'" = "'-wblat'" ]; then
      shift
      wblat=$1
      shift
   elif [ "'$1'" = "'-logfile'" ]; then
      shift
      logfile=$1
      shift

   else
      if [ 1 = 2 ]; then echo "";

      elif [ "$firstc" = "-" ]; then shift; c=`expr $c - 1`
      fi
      shift
      c=`expr $c + 1`
   fi
done

# Print version information
if [ "$version" = "1" ]; then
   echo "Version $vers"
   exit 0
fi

# Template File String
uuu="\
;Free Superscalar Simulator initialization file

[General]							
 Program Name		= __REFO1__		;  Name of program
 Silent			= __REFO2__		;  Silent Mode
 Interactive		= __REFO3__		;  Interactive Mode
 Mode			= __REFO4__		;  Batch File Mode
 Iterations		= __REFO5__		;  Number of Iterations
 Starting Cycle		= __REFO6__		;  Starting Cycle

[Architecture]							
 Logical Registers	= __REFO7__		;  Number of Logical Regs
 Physical Registers	= __REFO8__		;  Number of Physical Regs
 Pipeline Structure	= __REFO9__		;  Pipeline Structure
 Unified LSU		= __REFO10__		;  Unified LSU
 In-Order Issue		= __REFO11__		;  In-Order Issue
 In-Order Complete	= __REFO12__		;  In-Order Complete
 Unified Dispatch/Issue	= __REFO13__		;  Unified Dispatch/Issue
 Fetch Width		= __REFO14__		;  Fetch Width
 Decode Width		= __REFO15__		;  Decode Width
 Dispatch Width		= __REFO16__		;  Dispatch Width
 Issue Width		= __REFO17__		;  Issue Width
 Write-Back Width	= __REFO18__		;  Write-Back Width
 Commit Width		= __REFO19__		;  Commit Width
 Window Size		= __REFO20__		;  Instruction Window Size
 ROB Size		= __REFO21__		;  Reorder Buffer Size
 Integer ALU Units	= __REFO22__		;  Number of Int. FU
 Integer ALU Latency	= __REFO23__		;  Latency of INT ALU FU
 Integer Mult. Units	= __REFO24__		;  Number of Mult. FU
 Integer Mult. Latency	= __REFO25__		;  Latency of Mult. FU
 Integer Mult. Pipe	= __REFO26__		;  Pipelinization of Mult.
 Floating Point Units	= __REFO27__		;  Number of FP FU
 Floating Point Mult	= __REFO28__		;  Number of FP Mult. FU
 Load Units		= __REFO29__		;  Number of Load FU
 Load Latency		= __REFO30__		;  Latency of Load FU
 Load Pipe		= __REFO31__		;  Pipelinization of Load
 Store Units		= __REFO32__		;  Number of Store FU
 Store Latency		= __REFO33__		;  Latency of Store FU
 Store Pipe		= __REFO34__		;  Pipelinization of Store
 Branch Units		= __REFO35__		;  Number of Branch FU
 Branch Latency		= __REFO36__		;  Latency of Branch FU
 Load Queue Size	= __REFO37__		;  Load Queue Size
 Store Queue Size	= __REFO38__		;  Store Queue Size
 Speculation		= __REFO39__		;  Enable Speculation
 Write Back Latency	= __REFO40__		;  Write Back Latency

[Program Defaults]						
 Log File Name		= __REFO41__		;  Log File


"

# Generate a template
if [ "$template" = "1" ]; then
   echo "$uuu" > $cur/$scr1.tem
   echo "Template is in file '$cur/$scr1.tem'"
   exit
fi

if [ "$help" = "1" -o "$c" != "0" ]; then
   echo "Usage:"
   echo "   $scr [-exe <program_name>] [-s <silent>] [-int <interactive>] [-batch <mode>] [-iter <iterations>] [-startck <starting_cycle>] [-lregs <logical_registers>] [-pregs <physical_registers>] [-pstruct <pipeline_structure>] [-unilsu <unified_lsu>] [-ioi <in-order_issue>] [-ioc <in-order_complete>] [-unidi <unified_dispatch/issue>] [-fw <fetch_width>] [-dw <decode_width>] [-pw <dispatch_width>] [-iw <issue_width>] [-ww <write-back_width>] [-cw <commit_width>] [-wins <window_size>] [-robs <rob_size>] [-afu <integer_alu_units>] [-alat <integer_alu_latency>] [-mfu <integer_mult._units>] [-mlat <integer_mult._latency>] [-mpipe <integer_mult._pipe>] [-ffu <floating_point_units>] [-xfu <floating_point_mult>] [-lfu <load_units>] [-llat <load_latency>] [-lpipe <load_pipe>] [-sfu <store_units>] [-slat <store_latency>] [-spipe <store_pipe>] [-bfu <branch_units>] [-blat <branch_latency>] [-lqs <load_queue_size>] [-sqs <store_queue_size>] [-spec <speculation>] [-wblat <write_back_latency>] [-logfile <log_file_name>] "
   echo ""
   echo "   PARAMETER NAME                       DESCRIPTION             DEFAULT VALUE"
   echo "   <program_name>			Name of program		program"
   echo "   <silent>				Silent Mode		no"
   echo "   <interactive>			Interactive Mode	yes"
   echo "   <mode>				Batch File Mode		no"
   echo "   <iterations>				Number of Iterations	3"
   echo "   <starting_cycle>			Starting Cycle		0"
   echo "   <logical_registers>			Number of Logical Regs	8"
   echo "   <physical_registers>			Number of Physical Regs	24"
   echo "   <pipeline_structure>			Pipeline Structure	FDPIXWC"
   echo "   <unified_lsu>			Unified LSU		yes"
   echo "   <in-order_issue>			In-Order Issue		no"
   echo "   <in-order_complete>			In-Order Complete	no"
   echo "   <unified_dispatch/issue>		Unified Dispatch/Issue	yes"
   echo "   <fetch_width>			Fetch Width		4"
   echo "   <decode_width>			Decode Width		4"
   echo "   <dispatch_width>			Dispatch Width		4"
   echo "   <issue_width>			Issue Width		4"
   echo "   <write-back_width>			Write-Back Width	4"
   echo "   <commit_width>			Commit Width		4"
   echo "   <window_size>			Instruction Window Size	16"
   echo "   <rob_size>				Reorder Buffer Size	16"
   echo "   <integer_alu_units>			Number of Int. FU	4"
   echo "   <integer_alu_latency>		Latency of INT ALU FU	0"
   echo "   <integer_mult._units>		Number of Mult. FU	1"
   echo "   <integer_mult._latency>		Latency of Mult. FU	4"
   echo "   <integer_mult._pipe>			Pipelinization of Mult.	yes"
   echo "   <floating_point_units>		Number of FP FU		4"
   echo "   <floating_point_mult>		Number of FP Mult. FU	1"
   echo "   <load_units>				Number of Load FU	1"
   echo "   <load_latency>			Latency of Load FU	2"
   echo "   <load_pipe>				Pipelinization of Load	yes"
   echo "   <store_units>			Number of Store FU	1"
   echo "   <store_latency>			Latency of Store FU	1"
   echo "   <store_pipe>				Pipelinization of Store	yes"
   echo "   <branch_units>			Number of Branch FU	1"
   echo "   <branch_latency>			Latency of Branch FU	0"
   echo "   <load_queue_size>			Load Queue Size		1"
   echo "   <store_queue_size>			Store Queue Size	1"
   echo "   <speculation>			Enable Speculation	yes"
   echo "   <write_back_latency>			Write Back Latency	0"
   echo "   <log_file_name>			Log File		def.log"

   echo ""
   exit
fi

#__PARAMETERS_SYMBOL_ASSO__

# Rule for name: MUST USE 'rfn' FOR HOLDING RESULT
  rfn=`echo "$progname"`

# Input parameters transformations
  logfile=$rfn.log

# Create Actual .ini File
echo "$uuu" |sed -e "{
s:__REFO1__:$progname:
s:__REFO2__:$silent:
s:__REFO3__:$interactive:
s:__REFO4__:$batch:
s:__REFO5__:$iterations:
s:__REFO6__:$start_ck:
s:__REFO7__:$lregs:
s:__REFO8__:$pregs:
s:__REFO9__:$pipestruct:
s:__REFO10__:$uni_lsu:
s:__REFO11__:$io_issue:
s:__REFO12__:$io_complete:
s:__REFO13__:$uni_di:
s:__REFO14__:$f_width:
s:__REFO15__:$d_width:
s:__REFO16__:$p_width:
s:__REFO17__:$i_width:
s:__REFO18__:$w_width:
s:__REFO19__:$c_width:
s:__REFO20__:$win_size:
s:__REFO21__:$rob_size:
s:__REFO22__:$int_fu:
s:__REFO23__:$a_lat:
s:__REFO24__:$im_fu:
s:__REFO25__:$im_lat:
s:__REFO26__:$im_pipe:
s:__REFO27__:$fp_fu:
s:__REFO28__:$fm_fu:
s:__REFO29__:$l_fu:
s:__REFO30__:$l_lat:
s:__REFO31__:$l_pipe:
s:__REFO32__:$s_fu:
s:__REFO33__:$s_lat:
s:__REFO34__:$s_pipe:
s:__REFO35__:$b_fu:
s:__REFO36__:$b_lat:
s:__REFO37__:$lqsize:
s:__REFO38__:$sqsize:
s:__REFO39__:$speculation:
s:__REFO40__:$wblat:
s:__REFO41__:$logfile:
}" > ./$rfn.ini


opt_d=""
if [ "$debug" = "1" ]; then
   opt_d="-d"
fi
if [ "$auto" = "1" ]; then
###   exec $ccc/freess -i $rfn.ini
   exec $cur/$scr1 $opt_d -i $rfn.ini
else
###   echo "You can now issue '$ccc/freess -i $rfn.ini'."
   echo "You can now issue '$cur/$scr1 -i $rfn.ini'."
fi


