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

# 14-Oct-2025
#
############### OPTIONAL PARAMETERES 
# -exe		= Name of program
# -s		= Silent Mode
# -int		= Interactive Mode
# -batch	= Batch File Mode
# -iter		= Number of Iterations
# -stck		= Starting Clock Cycle
# -tom		= Tomasulo Pipeline + RS
# -lregs	= Number of Logical Regs
# -pregs	= Number of Physical Regs
# -pstruct	= Pipeline Structure
# -unilsu	= Unified LSU
# -loadpri	= Load over Store Pri.
# -ioi		= In-Order Issue
# -ioc		= In-Order Complete
# -unidi	= Unified Dispatch/Issue
# -rsrel	= Early RS Release
# -mempipe	= Pipelined Data Mempry
# -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
# -ars		= Reservation St. per FU
# -mfu			= Number of Mult. FU
# -mlat		= Latency of Mult. FU
# -mpipe	= Pipelinization of Mult.
# -mrs		= Reservation St. per FU
# -dfu			= Number of Div. FU
# -dlat		= Latency of Div. FU
# -dpipe	= Pipelinization of Div.
# -drs		= Reservation St. per FU
# -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
# -swaits	= Store waits completion
# -lsrs		= Reservation St. per FU
# -bfu			= Number of Branch FU
# -blat		= Latency of Branch FU
# -brs		= Reservation St. per 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
tomasulo=no
lregs=8
pregs=24
pipestruct=FDPIXWC
uni_lsu=yes
load_has_pri=yes
io_issue=no
io_complete=no
uni_di=yes
early_rs_rel=yes
mem_pipe=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
a_rs=100
im_fu=1
im_lat=4
im_pipe=yes
im_rs=100
id_fu=1
id_lat=4
id_pipe=yes
id_rs=100
fp_fu=4
fm_fu=1
l_fu=1
l_lat=2
l_pipe=yes
s_fu=1
s_lat=1
s_pipe=yes
s_waits=no
ls_rs=100
b_fu=1
b_lat=0
b_rs=100
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'" = "'-stck'" ]; then
      shift
      start_ck=$1
      shift
   elif [ "'$1'" = "'-tom'" ]; then
      shift
      tomasulo=$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'" = "'-loadpri'" ]; then
      shift
      load_has_pri=$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'" = "'-rsrel'" ]; then
      shift
      early_rs_rel=$1
      shift
   elif [ "'$1'" = "'-mempipe'" ]; then
      shift
      mem_pipe=$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'" = "'-ars'" ]; then
      shift
      a_rs=$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'" = "'-mrs'" ]; then
      shift
      im_rs=$1
      shift
   elif [ "'$1'" = "'-dfu	'" ]; then
      shift
      id_fu=$1
      shift
   elif [ "'$1'" = "'-dlat'" ]; then
      shift
      id_lat=$1
      shift
   elif [ "'$1'" = "'-dpipe'" ]; then
      shift
      id_pipe=$1
      shift
   elif [ "'$1'" = "'-drs'" ]; then
      shift
      id_rs=$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'" = "'-swaits'" ]; then
      shift
      s_waits=$1
      shift
   elif [ "'$1'" = "'-lsrs'" ]; then
      shift
      ls_rs=$1
      shift
   elif [ "'$1'" = "'-bfu	'" ]; then
      shift
      b_fu=$1
      shift
   elif [ "'$1'" = "'-blat'" ]; then
      shift
      b_lat=$1
      shift
   elif [ "'$1'" = "'-brs'" ]; then
      shift
      b_rs=$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 Clock Cycle	= __REFO6__		;  Starting Clock Cycle
 Tomasulo Mode		= __REFO7__		;  Tomasulo Pipeline + RS

[Architecture]							
 Logical Registers	= __REFO8__		;  Number of Logical Regs
 Physical Registers	= __REFO9__		;  Number of Physical Regs
 Pipeline Structure	= __REFO10__		;  Pipeline Structure
 Unified LSU		= __REFO11__		;  Unified LSU
 Load over Store Pri	= __REFO12__		;  Load over Store Pri.
 In-Order Issue		= __REFO13__		;  In-Order Issue
 In-Order Complete	= __REFO14__		;  In-Order Complete
 Unified Disp./Issue	= __REFO15__		;  Unified Dispatch/Issue
 Early RS Release	= __REFO16__		;  Early RS Release
 Data Mem. Pipe		= __REFO17__		;  Pipelined Data Mempry
 Fetch Width		= __REFO18__		;  Fetch Width
 Decode Width		= __REFO19__		;  Decode Width
 Dispatch Width		= __REFO20__		;  Dispatch Width
 Issue Width		= __REFO21__		;  Issue Width
 Write-Back Width	= __REFO22__		;  Write-Back Width
 Commit Width		= __REFO23__		;  Commit Width
 Window Size		= __REFO24__		;  Instruction Window Size
 ROB Size		= __REFO25__		;  Reorder Buffer Size
 Integer ALU Units	= __REFO26__		;  Number of Int. FU
 Integer ALU Latency	= __REFO27__		;  Latency of INT ALU FU
 Int. ALU Res.Stat.	= __REFO28__		;  Reservation St. per FU
 Integer Mult. Units	= __REFO29__		;  Number of Mult. FU
 Integer Mul. Latency	= __REFO30__		;  Latency of Mult. FU
 Integer Mul. Pipe	= __REFO31__		;  Pipelinization of Mult.
 Int. Mul. Res.Stat.	= __REFO32__		;  Reservation St. per FU
 Integer Div. Units	= __REFO33__		;  Number of Div. FU
 Integer Div. Latency	= __REFO34__		;  Latency of Div. FU
 Integer Div. Pipe	= __REFO35__		;  Pipelinization of Div.
 Int. Div. Res.Stat.	= __REFO36__		;  Reservation St. per FU
 Floating Point Units	= __REFO37__		;  Number of FP FU
 Floating Point Mul	= __REFO38__		;  Number of FP Mult. FU
 Load Units		= __REFO39__		;  Number of Load FU
 Load Latency		= __REFO40__		;  Latency of Load FU
 Load Pipe		= __REFO41__		;  Pipelinization of Load
 Store Units		= __REFO42__		;  Number of Store FU
 Store Latency		= __REFO43__		;  Latency of Store FU
 Store Pipe		= __REFO44__		;  Pipelinization of Store
 Store Waits		= __REFO45__		;  Store waits completion
 Load/Store Res.Stat.	= __REFO46__		;  Reservation St. per FU
 Branch Units		= __REFO47__		;  Number of Branch FU
 Branch Latency		= __REFO48__		;  Latency of Branch FU
 Branch Res.Stat.	= __REFO49__		;  Reservation St. per FU
 Load Queue Size	= __REFO50__		;  Load Queue Size
 Store Queue Size	= __REFO51__		;  Store Queue Size
 Speculation		= __REFO52__		;  Enable Speculation
 Write Back Latency	= __REFO53__		;  Write Back Latency

[Program Defaults]						
 Log File Name		= __REFO54__		;  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>] [-stck <starting_clock_cycle>] [-tom <tomasulo_mode>] [-lregs <logical_registers>] [-pregs <physical_registers>] [-pstruct <pipeline_structure>] [-unilsu <unified_lsu>] [-loadpri <load_over_store_pri>] [-ioi <in-order_issue>] [-ioc <in-order_complete>] [-unidi <unified_disp./issue>] [-rsrel <early_rs_release>] [-mempipe <data_mem._pipe>] [-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>] [-ars <int._alu_res.stat.>] [-mfu	 <integer_mult._units>] [-mlat <integer_mul._latency>] [-mpipe <integer_mul._pipe>] [-mrs <int._mul._res.stat.>] [-dfu	 <integer_div._units>] [-dlat <integer_div._latency>] [-dpipe <integer_div._pipe>] [-drs <int._div._res.stat.>] [-ffu	 <floating_point_units>] [-xfu	 <floating_point_mul>] [-lfu	 <load_units>] [-llat <load_latency>] [-lpipe <load_pipe>] [-sfu	 <store_units>] [-slat <store_latency>] [-spipe <store_pipe>] [-swaits <store_waits>] [-lsrs <load/store_res.stat.>] [-bfu	 <branch_units>] [-blat <branch_latency>] [-brs <branch_res.stat.>] [-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_clock_cycle>		Starting Clock Cycle	0"
   echo "   <tomasulo_mode>			Tomasulo Pipeline + RS	no"
   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 "   <load_over_store_pri>		Load over Store Pri.	yes"
   echo "   <in-order_issue>			In-Order Issue		no"
   echo "   <in-order_complete>			In-Order Complete	no"
   echo "   <unified_disp./issue>		Unified Dispatch/Issue	yes"
   echo "   <early_rs_release>			Early RS Release	yes"
   echo "   <data_mem._pipe>			Pipelined Data Mempry	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 "   <int._alu_res.stat.>			Reservation St. per FU	100"
   echo "   <integer_mult._units>		Number of Mult. FU	1"
   echo "   <integer_mul._latency>		Latency of Mult. FU	4"
   echo "   <integer_mul._pipe>			Pipelinization of Mult.	yes"
   echo "   <int._mul._res.stat.>		Reservation St. per FU	100"
   echo "   <integer_div._units>			Number of Div. FU	1"
   echo "   <integer_div._latency>		Latency of Div. FU	4"
   echo "   <integer_div._pipe>			Pipelinization of Div.	yes"
   echo "   <int._div._res.stat.>		Reservation St. per FU	100"
   echo "   <floating_point_units>		Number of FP FU		4"
   echo "   <floating_point_mul>			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 "   <store_waits>			Store waits completion	no"
   echo "   <load/store_res.stat.>		Reservation St. per FU	100"
   echo "   <branch_units>			Number of Branch FU	1"
   echo "   <branch_latency>			Latency of Branch FU	0"
   echo "   <branch_res.stat.>			Reservation St. per FU	100"
   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__:$tomasulo:
s:__REFO8__:$lregs:
s:__REFO9__:$pregs:
s:__REFO10__:$pipestruct:
s:__REFO11__:$uni_lsu:
s:__REFO12__:$load_has_pri:
s:__REFO13__:$io_issue:
s:__REFO14__:$io_complete:
s:__REFO15__:$uni_di:
s:__REFO16__:$early_rs_rel:
s:__REFO17__:$mem_pipe:
s:__REFO18__:$f_width:
s:__REFO19__:$d_width:
s:__REFO20__:$p_width:
s:__REFO21__:$i_width:
s:__REFO22__:$w_width:
s:__REFO23__:$c_width:
s:__REFO24__:$win_size:
s:__REFO25__:$rob_size:
s:__REFO26__:$int_fu:
s:__REFO27__:$a_lat:
s:__REFO28__:$a_rs:
s:__REFO29__:$im_fu:
s:__REFO30__:$im_lat:
s:__REFO31__:$im_pipe:
s:__REFO32__:$im_rs:
s:__REFO33__:$id_fu:
s:__REFO34__:$id_lat:
s:__REFO35__:$id_pipe:
s:__REFO36__:$id_rs:
s:__REFO37__:$fp_fu:
s:__REFO38__:$fm_fu:
s:__REFO39__:$l_fu:
s:__REFO40__:$l_lat:
s:__REFO41__:$l_pipe:
s:__REFO42__:$s_fu:
s:__REFO43__:$s_lat:
s:__REFO44__:$s_pipe:
s:__REFO45__:$s_waits:
s:__REFO46__:$ls_rs:
s:__REFO47__:$b_fu:
s:__REFO48__:$b_lat:
s:__REFO49__:$b_rs:
s:__REFO50__:$lqsize:
s:__REFO51__:$sqsize:
s:__REFO52__:$speculation:
s:__REFO53__:$wblat:
s:__REFO54__:$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


