-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-wasm.sh
executable file
·86 lines (75 loc) · 2.22 KB
/
build-wasm.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
#!/bin/bash
args=("$@")
LLVM_BIN_DIR=../llvm/bin
BINARYEN_BIN_DIR=../binaryen/bin
WABT_BIN_DIR=./wabt/bin
AS_BIN=asc
WASM_DIR=./wasm
function build_wasm_c {
$LLVM_BIN_DIR/clang -emit-llvm --target=wasm32 -Oz $WASM_DIR/cpp/hello.c -c -o $WASM_DIR/cpp/hello.bc
$LLVM_BIN_DIR/clang -emit-llvm --target=wasm32 -Oz $WASM_DIR/cpp/hello-2.c -c -o $WASM_DIR/cpp/hello-2.bc
$LLVM_BIN_DIR/llvm-link $WASM_DIR/cpp/hello.bc $WASM_DIR/cpp/hello-2.bc -o $WASM_DIR/cpp/hello-c.bc
$LLVM_BIN_DIR/llc -asm-verbose=false -o $WASM_DIR/cpp/hello-c.s $WASM_DIR/cpp/hello-c.bc
$BINARYEN_BIN_DIR/s2wasm $WASM_DIR/cpp/hello-c.s > $WASM_DIR/cpp/hello-c.wast
$WABT_BIN_DIR/wat2wasm $WASM_DIR/cpp/hello-c.wast -o $WASM_DIR/cpp/hello-c.wasm
rm -f $WASM_DIR/cpp/*.bc
rm -f $WASM_DIR/cpp/*.s
rm -f $WASM_DIR/cpp/*.wast
}
function build_wasm_as {
$AS_BIN $WASM_DIR/as/hello.as -O --noRuntime --outFile $WASM_DIR/as/hello.wast
$WABT_BIN_DIR/wat2wasm $WASM_DIR/as/hello.wast -o $WASM_DIR/as/hello-as.wasm
rm -f $WASM_DIR/as/hello.wast
}
function build_wasm_rust {
rustc $WASM_DIR/rust/hello.rs --target=wasm32-unknown-unknown -C panic=abort -o $WASM_DIR/rust/hello-rust.wasm
# wasm-gc $WASM_DIR/rust/hello-rust.wasm $WASM_DIR/rust/hello-rust.wasm
$WABT_BIN_DIR/wasm2wat $WASM_DIR/rust/hello-rust.wasm -o $WASM_DIR/rust/hello-rust.wast
}
function run_wasm_c {
echo -e "\033[32mRunning C...\033[0m"
$(pwd)/my-interp wasm/cpp/hello-c.wasm -E export_function
}
function run_wasm_as {
echo -e "\033[32mRunning AssemblyScript...\033[0m"
$(pwd)/my-interp wasm/as/hello-as.wasm -E export_function
}
function run_wasm_rust {
echo -e "\033[32mRunning Rust...\033[0m"
$(pwd)/my-interp wasm/rust/hello-rust.wasm -E export_function
}
if [[ ${args[0]} = "build" ]]
then
if [[ ${args[1]} = "c" ]]
then
build_wasm_c
elif [[ ${args[1]} = "as" ]]
then
build_wasm_as
elif [[ ${args[1]} = "rust" ]]
then
build_wasm_rust
elif [[ ${args[1]} = "all" ]]
then
build_wasm_c
build_wasm_as
build_wasm_rust
fi
elif [[ ${args[0]} = "run" ]]
then
if [[ ${args[1]} = "c" ]]
then
run_wasm_c
elif [[ ${args[1]} = "as" ]]
then
run_wasm_as
elif [[ ${args[1]} = "rust" ]]
then
run_wasm_rust
elif [[ ${args[1]} = "all" ]]
then
run_wasm_c
run_wasm_as
run_wasm_rust
fi
fi