-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuperopt
executable file
·44 lines (39 loc) · 1.15 KB
/
superopt
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
#!/bin/bash
set -e
usage="Usage: $(basename "$0") filename [options]
Description: script to automatically apply preprocessing based on file extension
and then call ajs with output file set to filename_optimised.asm.
All options are passed onto ajs (in particular the output file can be overriden).
The options for ajs are as follows:
"
FILE=$1
if [ -z "$MPIR_ROOT" ]
then
MPIR_ROOT=../mpir
echo "Using $MPIR_ROOT as base directory of MPIR"
fi
OUT_DIR=out
if [ "$FILE" == "--help" ] || [ "$FILE" == "" ]
then
echo "$usage"
./ajs --help
exit
fi
filename=$(basename "$FILE")
filename="${filename%.*}"
echo "optimising $FILE"
mkdir -p "$OUT_DIR"
if [[ "$FILE" == *.asm ]]
then
m4 "-I$MPIR_ROOT/mpn/" "$FILE" | ./ajs -c 0 -o "$OUT_DIR/$filename"_optimised.asm "${@:2}"
elif [[ "$FILE" == *.as ]]
then
"$MPIR_ROOT/yasm/yasm" -e "-I$MPIR_ROOT/mpn/x86_64w/" "$MPIR_ROOT/mpn/$FILE" | ./ajs -i -c 0 -o "$OUT_DIR/$filename"_optimised.asm "${@:2}"
elif [[ "$FILE" == *.c ]]
then
gcc "-I$MPIR_ROOT/" -S -O2 "$FILE" -o "$filename"_tmp.s
./ajs "$filename"_tmp.s -o "$OUT_DIR/$filename"_optimised.asm "${@:2}"
rm "$filename"_tmp.s
else
echo "error: file format not recognised"
fi