forked from drogus/jawsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.sh
executable file
·56 lines (48 loc) · 1.06 KB
/
execute.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
#!/usr/bin/env bash
set -o pipefail
# Parse options
CARGO_RUN=0
while [[ $# -gt 0 ]]; do
case $1 in
--cargo-run)
CARGO_RUN=1
shift
;;
*)
break
;;
esac
done
# Set JAWSM_DIR only if JAWSM_DIR is not already set
: ${JAWSM_DIR:=.}
# Determine how to run the compiler
if [ $CARGO_RUN -eq 1 ]; then
COMPILER="cargo run"
else
if [ -n "$JAWSM_BINARY" ]; then
COMPILER="$JAWSM_BINARY"
else
COMPILER="$JAWSM_DIR/target/release/jawsm"
fi
fi
# Run the compiler
if ! cat $1 | $COMPILER; then
exit 100
fi
generate_wasm() {
wasm-tools parse $JAWSM_DIR/wat/generated.wat -o $JAWSM_DIR/wasm/generated.wasm
# && \
# wasm-tools component embed --all-features $JAWSM_DIR/wit --world jawsm $JAWSM_DIR/wat/generated.wat -t -o wasm/generated.core.wasm && \
# wasm-tools component new $JAWSM_DIR/wasm/generated.core.wasm -o $JAWSM_DIR/wasm/generated.component.wasm
}
run_wasm() {
node run.js $JAWSM_DIR/wasm/generated.wasm
}
# Convert WAT to WASM
if ! generate_wasm; then
exit 100
fi
# Run the WASM file
if ! run_wasm; then
exit 101
fi