-
Notifications
You must be signed in to change notification settings - Fork 0
/
wamr_decode.sh
85 lines (77 loc) · 2.07 KB
/
wamr_decode.sh
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
#!/bin/bash
set -e
help() {
echo "Configure decode.c and WAMR compiler with libpng WASM target."
echo "Use the WAMR compiler to compile decode.wasm to decode.aot for"
echo "usage with the WAMR iwasm VM core."
echo
echo "Syntax: bash wasm_decode.sh [-h|s]"
echo "options:"
echo "h Print this help menu."
echo "s Run with WASM SIMD128 instructions enabled for libpng library"
echo
}
while getopts "hs" OPTION
do
case $OPTION in
h) help
exit;;
s) simd=true
echo "simd enabled...";;
esac
done
SCRIPT=$(readlink -f "$0")
SCRIPT_PATH=$(dirname "$SCRIPT")
echo "compiling decode.c to WASM..."
if [[ "$simd" = true ]]; then
CFLAGS="-O3 -msimd128" \
LDFLAGS="-Wl,--export-all -Wl,--growable-table" \
${WASI_SDK_PATH}/bin/clang \
--sysroot ${WASI_SDK_PATH}/share/wasi-sysroot \
-I${WASI_SDK_PATH}/share/wasi-sysroot/include/libpng16 \
-I${SIMDE_PATH}/simde/wasm \
-L${WASI_SDK_PATH}/share/wasi-sysroot/lib \
-o out/decode_simd.wasm \
decode.c \
-lpng16 -lz
else
LDFLAGS="-Wl,--export-all -Wl,--growable-table" \
${WASI_SDK_PATH}/bin/clang \
--sysroot ${WASI_SDK_PATH}/share/wasi-sysroot \
-I${WASI_SDK_PATH}/share/wasi-sysroot/include/libpng16 \
-L${WASI_SDK_PATH}/share/wasi-sysroot/lib \
-o out/decode_no_simd.wasm \
decode.c \
-lpng16 -lz
fi
# Extraneous step - only for checking WASM code
echo "converting .wasm to .wat..."
if [[ "$simd" = true ]]; then
${WABT_PATH}/build/wasm2wat -o out/decode_simd.wat out/decode_simd.wasm
else
${WABT_PATH}/build/wasm2wat -o out/decode_nosimd.wat out/decode_no_simd.wasm
fi
echo "rebuilding WAMR..."
if [[ "$simd" = true ]]; then
cd ${WAMR_PATH}/wamr-compiler/build
cmake .. -DWAMR_BUILD_SIMD=1
make
cd ${SCRIPT_PATH}
else
cd ${WAMR_PATH}/wamr-compiler/build
cmake .. -DWAMR_BUILD_SIMD=0
make
cd ${SCRIPT_PATH}
fi
echo "compiling to AOT with wamrc..."
if [[ "$simd" = true ]]; then
${WAMR_PATH}/wamr-compiler/build/wamrc \
-o out/decode_simd.aot \
out/decode_simd.wasm
else
${WAMR_PATH}/wamr-compiler/build/wamrc \
--disable-simd \
-o out/decode_nosimd.aot \
out/decode_no_simd.wasm
fi
echo "done"