summaryrefslogtreecommitdiff
path: root/runner.sh
blob: 19c4960a3984ce5b98d66963a594b90654966ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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
    echo "Not finished!"
}



## Check that $2 is a file
if [ -z "$2" ]; then
    echo "Usage: $0 <arg1> <file>"
    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