#!/bin/sh
#
# COPYRIGHT (c) 2026 The Fellowship of SML/NJ (https://smlnj.org)
# All rights reserved.
#
# Wrapper for ml-antlr heap image; this script is for debugging the tool
# during devlopment
#

mlantlrdir=$0
scripthome=${mlantlrdir%ml-antlr}
#echo "script home:"
#echo $scripthome

#
# determine heap suffix
#
case `uname -s` in
  Darwin)
    OPSYS=darwin
    case `uname -p` in
      arm) ARCH=arm64;;
      i386) ARCH=amd64;;
    esac
    ;;
  Linux)
    OPSYS=linux
    case `uname -m` in
    # As long as we do not natively support the amd64 architecture,
    # we should fallback to the x86 compatibility mode.  --Stef
      x86_64) ARCH=amd64;;
      *) exit 1;;
    esac
    ;;
  *) exit 1;;
esac

heap=${scripthome}ml-antlr.${ARCH}-${OPSYS}

if test ! -r $heap ; then
  echo "ml-antlr: no heap image!"
  exit 1
fi

exec sml @SMLload=$heap "$@"

