#!/bin/sh ################################################## # A test script capable of running all phases of # # compilation when supplied a phase name and a # # file. # ################################################## #### Functions function run_with_java() { # run the passed in file with java ext="class" if [ ! -f "${filename}.$ext" ]; then javac -g $1 fi java -cp $dirname $filename } function heat() { # heat the file java Typecheck < $1 } function boil() { # boil the file ext="vapor" java J2V < $1 > "./output/${filename}.$ext" java -jar vapor.jar run "./output/${filename}.$ext" } function vaporize() { # vaporize the file ext="vaporm" java V2VM < $1 > "./output/${filename}.$ext" java -jar vapor.jar run -mips "./output/${filename}.$ext" } function condense() { # condense the file ext="s" java VM2M < $1 > "./output/${filename}.$ext" java -jar mars.jar nc "./output/${filename}.$ext" } ## Check that $2 is a file if [ -z "$2" ]; then echo "Usage: $0 " exit 1 fi if [ ! -f "$2" ]; then echo "Error: $2 is not a regular file." exit 1 fi dirname=$(dirname "$2") filefull=$(basename "$2") filename=${filefull%.*} ## Handle passed args case "$1" in "java") run_with_java "$2" ;; "heat") heat "$2" ;; "boil") boil "$2" ;; "vaporize") vaporize "$2" ;; "condense") condense "$2" ;; *) echo "usage $0 [java|heat|boil|vaporize|condense]" exit 1 ;; esac