-
Notifications
You must be signed in to change notification settings - Fork 3
/
wsmlton-secondphase
executable file
·93 lines (73 loc) · 2.64 KB
/
wsmlton-secondphase
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
#!/bin/bash
# This takes the .sml file down to a binary.
if [ ! -f "$1" ];
then echo Usage: "wsmlton-secondphase <query-file.sml> <options ...>";
echo
echo File \"$1\" does not exist.
exit 1;
fi
INPUT=$1
shift
if [ "$WSMLOUTPUT" == "" ]; then WSMLOUTPUT=query.mlton.exe; fi
# Clean up first:
rm -f "$WSMLOUTPUT"
export MLTONARGS="$MLTONARGS -verbose 1 -link-opt -lfftw3f -cc-opt -DWSMLTON -cc-opt -I$REGIMENTD/src/linked_lib "
export WSMLCINCLUDES="$WSMLCINCLUDES $REGIMENTD/src/ws/passes/mlton_bkend/fftw.c "
# I'm having a lot of trouble getting enough quotes around
# 'allowFFI true' for it to be treated as one token.
# Thus I'm intruducing helper scripts as a hack:
export MLTON=mlton.hack
if [ "$1" == "-dbg" ]
then export MLTON=mlton.dbg;
shift;
fi
if [ "$1" == "-O3" ]
then export MLTON=mlton.opt;
shift;
fi
# Pull the extra libraries off the first line of the query file.
############################################################
FIRST=`head -n1 $INPUT`
MATCH=`echo $FIRST | grep "WSLIBDEPS:"`
if [ "$MATCH" != "" ];
then
EXTRALIBS=`echo $FIRST | sed "s/.*WSLIBDEPS://"`
echo Linking extra libraries requested by query file: $EXTRALIBS
echo
#export WSMLCINCLUDES="$WSMLCINCLUDES $EXTRALIBS"
for inc in $EXTRALIBS; do
if [ "${inc#*.}" = "so" ];
then BASENAME=${inc%.*}
MLTONARGS+=" -link-opt -l${BASENAME#lib} "
elif [ -f "$inc" ];
then WSMLCINCLUDES+=" $inc "
elif [ -f "$REGIMENTD/lib/$inc" ];
then WSMLCINCLUDES+=" $REGIMENTD/lib/$inc ";
else
#WSMLCINCLUDES+=" $inc "
echo "Couldn't locate include $inc"; exit 1
fi
done
export WSMLCINCLUDES
fi
############################################################
################################################################################
#MLTON="mlton -const 'Exn.keepHistory true'"
#echo "$MLTON -const 'Exn.keepHistory true' -default-ann 'allowFFI true' -output $OUTPUT $FLAGS $INCLUDES query.sml $CINCLUDES"
#echo "$MLTON -output $OUTPUT $FLAGS $INCLUDES query.sml $CINCLUDES"
#-default-ann 'allowFFI true'
#GRR="'allowFFI true'"
MLEXEC="$MLTON -output $WSMLOUTPUT $MLTONARGS query.sml $WSMLCINCLUDES"
echo "Calling MLton:"
echo " $MLEXEC"
start=`date +%s`
if
# For debugging enable keepHistory to get Stack traces:
#$MLTON -const 'Exn.keepHistory true' -default-ann 'allowFFI true' -output $OUTPUT $FLAGS $INCLUDES query.sml $CINCLUDES
#$MLTON -output $OUTPUT $FLAGS $INCLUDES query.sml $CINCLUDES
$MLEXEC
then end=`date +%s`;
echo " Time spent in $SML compiler: "$[($end) - ($start)]" second(s)";
echo "Executable output to: $WSMLOUTPUT";
else echo "$SML returned error!!"; exit -1
fi