#!/usr/bin/env bash

##
## Run `swipl` and load the `terminus_store_prolog` library using Valgrind with
## the Callgrind tool.
##
## - Arguments to this script are passed to `swipl`.
## - You should run `make` before this.
##

# Exit the script on any error
set -e

# Absolute path of this script allowing it to be run from any directory
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"

# Get the `swipl` command in $CMD
source "$SCRIPTDIR/swipl-cmd.sh"

# Run `valgrind` with the `callgrind` tool and the `swipl` command. Generate
# assembly code annotation, including jumps.
valgrind \
  --tool=callgrind \
  --dump-instr=yes \
  --collect-jumps=yes \
  "${CMD[@]}"
