-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmc
executable file
·106 lines (97 loc) · 2.13 KB
/
mmc
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
help()
{
echo "miniMatlab compiler."
echo "Usage : mmc [-S ^ -m] [-p|-s|-t] [-o outfile] *.mm"
echo " -h | --help : Show this help text."
echo " -S | --assembly : Generate assembly file."
echo " -m | --emit-mic : Generate machine - independant code. Only one of these files is generated."
echo " -s | --trace-scan : Trace lexer's scan."
echo " -p | --trace-parse : Trace parse."
echo " -t | --trace-tacos : Trace three-address codes."
}
asm=0
mic=0
tp=0
ts=0
tc=0
outfile=""
infile=""
while [ "$1" != "" ]; do
case $1 in
-o | --output ) shift
if [ "$outfile" != "" ]; then
echo "Only one file can be set as output:"
echo "Specified : $outfile"
echo "Also specified : $1"
exit 1
else
outfile=$1
fi
;;
-S | --assembly ) asm=1
;;
-m | --emit-mic ) mic=1
;;
-p | --trace-parse ) tp=1
;;
-s | --trace-scan ) ts=1
;;
-t | --trace-tacos ) tc=1
;;
-h | --help ) help
exit 0
;;
* ) if [ "$infile" != "" ]; then
echo "Error : only one file can be compiled at a time:"
echo "Specified : $infile"
echo "Also specified : $1"
exit 1
else
infile=$1
fi
;;
esac
shift
done
if [ $mic -eq 1 ] && [ $asm -eq 1 ] ; then
echo "Only one of -S and -m can be set."
exit 1
fi
if [ "$infile" == "" ]; then
echo "Error : no input files specified."
exit 1
fi
if [ "$outfile" == "" ]; then
if [ $asm -eq 1 ]; then
outfile="$infile.asm"
elif [ $mic -eq 1 ]; then
outfile="$infile.out"
else
outfile="a.out"
fi
fi
if [ "$infile" == "$outfile" ]; then
echo "Error : input and output files are same."
exit 1
fi
options=""
if [ $tp -eq 1 ]; then
options+="--trace-parse "
fi
if [ $ts -eq 1 ]; then
options+="--trace-scan "
fi
if [ $tc -eq 1 ]; then
options+="--trace-tacos "
fi
if [ $mic -eq 1 ]; then
options+="--emit-mic "
./compile $options ./$infile >$outfile
elif [ $asm -eq 1 ]; then
./compile $options ./$infile >$outfile
else
./compile $options ./$infile >$outfile.s
gcc -lm $outfile.s mmstd.o -o $outfile
rm -f $outfile.s
fi