#!/bin/sh
# Fri Dec 31 18:10:50 EST 2010 dtl
#
# Example script to illustrate selecting a VM based on image
# format number using ckformat utility program. This example
# assumes that /usr/local/bin/squeak runs the traditional VM,
# /usr/local/bin/cog runs Cog, and /usr/local/bin/squeak64 runs
# a traditional intepreter VM compiled for 64-bit images.
#
# ckformat is a C program with source generated from
# ImageFormat class>>createCkStatusProgram. See package ImageFormat
# in the SqueakSource VMMaker repository.
#

BASEDIR="/usr/local"
BIN=$BASEDIR/bin
CKFORMAT="$BIN/ckformat"   # The ckformat utility
INTERP="$BIN/squeak"       # Standard 32-bit interpreter, all 32-bit images
INTERP_64="$BIN/squeak64"  # Standard interpreter for 64-bit images
COG="$BIN/cog"             # Cog VM for 32-bit images with closure support

if test $# -lt 1
then
  echo usage: $0 imagefile
  exit 1
fi
NUM=`$CKFORMAT $1`
if test $? -ne 0
then
  echo cannot detect image format for $1
  exit 1
fi

# Use Cog if image is 32 bits with closure support

case $NUM in
6502)
  VM=$INTERP;;
6504 | 6505)
  VM=$COG;;
68000 | 68002 | 68003)
  VM=$INTERP_64;;
*)  echo image format $NUM not recognized;
  exit -1;;
esac

echo image $1 with image format format $NUM can use the $VM VM

