#!/bin/bash


#--- application ----------------
APP=example

#------ simulation options --------------
if [ "$@""a" == "a" ]; then
  # default options:
  #   - run 1000 simulation events
  #   - do not print BIP simulation details
  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 "      PERFORM:  BIP ----> bip.C (C++)     "
echo "========================================="
echo "========================================="

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

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PERFORM:  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 "      PERFORM: exec  binary.x $opt        "
echo "        note:  you can provide alternative options to this script "
echo "========================================="
echo "========================================="
./${APP_APSW}.bip.x $opt

