#!/bin/bash

#============= xml files ==================
APP=exampleDemo-DOLC
MAPXML=mappingOnSlide.xml

#============= binary options ===========
if [ "$@""a" == "a" ]; then
  # no arg ==> default option   
  # --limit 200 =  run simulation for 200 events and stop
  # --quiet     =  do not print detailed simulator log
  opt="--limit 200 --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 --create-scheduler $MAPXML 
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
res=$?
if ((res!=GOOD)); then 
  exit 1
fi

echo "========================================="
echo "========================================="
echo "========================================="
echo "========================================="
echo "      PERFORM:  make binary.x             "
echo "========================================="
echo "========================================="
make -f Makefile.RUN
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

