#!/bin/bash
# Copyright (c) 2017 Princeton University
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Princeton University nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY PRINCETON UNIVERSITY "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL PRINCETON UNIVERSITY BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


shopt -s expand_aliases

buildargs=''
runargs=''
# morerunargs='-sim_run_args=+pll_en=1'
buildargs='-sys=jtag_testbench -x_tiles=1 -y_tiles=1'
# buildargs='-sys=jtag_testbench -x_tiles=2 -y_tiles=1'
# buildargs='-sys=jtag_testbench -x_tiles=2 -y_tiles=2'
# buildargs='-sys=jtag_testbench -x_tiles=1 -y_tiles=1 -sim_pll'
buildargs+=' -ibm'
# runargs='-sys=jtag_testbench test_fail.s -sim_run_args=+test_case_base=jtag_stall'
runargs='-sys=jtag_testbench test_fail.s -sim_run_args=+test_case_base=jtag_shadowscan'
# runargs='-sys=jtag_testbench jtag_infinite_loop.s -sim_run_args=+test_case_base=jtag_sram_write'
# runargs='-sys=jtag_testbench test.s -sim_run_args=+test_case_base=jtag_thread_start_manual -sim_run_args=+jtag_iob_send_wakeup=0'
# runargs='-sys=jtag_testbench jtag_infinite_loop1.s -sim_run_args=+test_case_base=jtag_pc_write'
# runargs='-sys=jtag_testbench test.s -sim_run_args=+test_case_base=jtag_reset_vector -sim_run_args=+jtag_iob_send_wakeup=0'
# runargs='-sys=jtag_testbench test.s -sim_run_args=+test_case_base=jtag_manual_program -sim_run_args=+jtag_iob_send_wakeup=0 -sim_run_args=+jtag_timeout=2000000000'
# runargs='-sys=jtag_testbench -sim_run_args=+test_case_base=jtag_oram_read -sim_run_args=+jtag_iob_send_wakeup=0 -oram'
# runargs='-sys=jtag_testbench -sim_run_args=+test_case_base=jtag_rw_configregs -sim_run_args=+jtag_iob_send_wakeup=0'
# runargs='-sys=jtag_testbench -sim_run_args=+test_case_base=jtag_sram_write_frf -sim_run_args=+jtag_iob_send_wakeup=0'
# runargs='-sys=jtag_testbench jtag_infinite_loop.s -sim_run_args=+test_case_base=jtag_read_irf'
# runargs='-sys=jtag_testbench test_fail.s -sim_run_args=+test_case_base=jtag_test_clk_gating'
# runargs='-sys=jtag_testbench test.s -sim_run_args=+test_case_base=jtag_test_oram_clk_gating_on'
# runargs='-sys=jtag_testbench test.s -sim_run_args=+test_case_base=jtag_test_oram_clk_gating_off'
# runargs='-sys=jtag_testbench test_fail.s -sim_run_args=+test_case_base=jtag_pc_breakpoint'
# runargs='-sys=jtag_testbench test.s -sim_run_args=+test_case_base=jtag_pc_breakpoint_resume'

# jtag_test_clk_gating
if [ "$1" = 'compile' ] ; then
   CWD=`pwd`
   cd $PITON_ROOT/piton/verif/env/jtag_testbench/test_cases
   python jtag_test_clk_gating.py
   cd $CWD
   shift
fi

if [ "$1" = 'build' ] ; then
   sims -vcs_build $buildargs -vcs_build_args=-debug_all > buildout
	echo BUILD DONE
   shift
fi

if [ "$1" = 'gui' ] ; then
   sims -vcs_run $buildargs $morerunargs $runargs -rtl_timeout=500000 -gui
fi

if [ "$1" = 'run' ] ; then
   sims -vcs_run $buildargs $morerunargs $runargs -rtl_timeout=500000 > out;
   echo DONE
fi

# sims -vcs_run $runargs -rtl_timeout=500000 
