#!/bin/bash

APP=example

#----------- options ---------
if [ "$@""a" == "a" ]; then
  # no arg ==> default option
  #   execute for 1000 events
  #   dont print simulation log
  opt="--limit 1000 --quiet"
else 
  opt="$@"
fi


#=============================================
APP_APSW=${APP}_SWModel
GOOD=0

source $DC2BTV30_ROOT/sourceme.rc

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PERFORM: DOLC ---> BIP             "
echo "========================================="
echo "========================================="
$DOL2BIP -f ${APP}.xml
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PRFORM:  BIP ----> bip.C (C++)     "
echo "========================================="
echo "========================================="

export BIP2_HOME=$SIM_BIP2_HOME
$BIP2_HOME/bin/bipc -f ${APP_APSW}.bip --genC-execute
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PRFORM:  make binary.x             "
echo "========================================="
echo "========================================="
make -f ${APP_APSW}.bip.mk
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

# clean up
rm ${APP_APSW}.bip.C ${APP_APSW}.bip.h ${APP_APSW}.bip.mk ${APP_APSW}.bip.o ${APP_APSW}.model ${APP_APSW}.timod

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PRFORM: exec  binary.x $opt        "
echo "        note:  you can provide alternative options to this script "
echo "========================================="
echo "========================================="
./${APP_APSW}.bip.x $opt

