-
Notifications
You must be signed in to change notification settings - Fork 1
/
sigic
executable file
·65 lines (53 loc) · 1.22 KB
/
sigic
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
#!/bin/bash
#
POSITIONAL_ARGS=()
USAGE="Usage: $0 [-o FILE] [FILE | -e EXPR]"
while [[ $# -gt 0 ]]; do
case $1 in
-e|--expr)
EXPR="$2"
shift # past argument
shift # past value
;;
--output|-o)
OUTPUT="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
echo $USAGE
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
tmp=$(mktemp -d)
if [[ -z ${FILE+x} && -z ${EXPR+x} ]]; then
# both are missing
echo $USAGE
exit 1
elif [[ -n ${FILE+x} && -n ${EXPR+x} ]]; then
# both are set
echo $USAGE
exit 1
elif [[ -n ${FILE+x} ]]; then
basename=$(basename "$FILE")
FILEBASE=${basename%.*} # file name without extension
FILE=$(realpath "$FILE")
else
# we have an expr
FILEBASE="sigiexpr"
FILE="$tmp/$FILEBASE.sigi"
echo "$EXPR" > "$FILE"
fi
echo "Working in $tmp... ($filebase)"
set -e
just -f sigi-frontend/justfile sigiToMlir "$FILE" > "$tmp/$FILEBASE.mlir"
just -f sigi-mlir/justfile sigiToLlvmIr "$tmp/$FILEBASE.mlir"
EXEC=${OUTPUT:-./$FILEBASE}
cp $tmp/$FILEBASE.exe $EXEC
echo "Successfully compiled $EXEC"