feat: init commit

This commit is contained in:
2023-01-17 22:45:23 +08:00
commit 94130c107c
72 changed files with 7568 additions and 0 deletions

1
test_data/endless_wasm/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.wasm

View File

@@ -0,0 +1,12 @@
wasm_endless_loop.wasm: wasm_endless_loop.wat
wat2wasm wasm_endless_loop.wat -o wasm_endless_loop.wasm
wapc_endless_loop.wasm: wapc_endless_loop.wat
wat2wasm wapc_endless_loop.wat -o wapc_endless_loop.wasm
.PHONY: build
build: wasm_endless_loop.wasm wapc_endless_loop.wasm
.PHONY: clean
clean:
rm -rf *.wasm

View File

@@ -0,0 +1,28 @@
This directory contains the source code of two WebAssembly modules, bot of them
perform an endless loop.
The code is written using the WebAssembly text format (aka `WAT`).
## `wasm_endless_loop.wat`
This is a module meant to be used with vanilla wasmtime engine.
The code exports a function called `endless_loop` that just performs
and endless loop.
This function takes zero parameters and doesn't return anything.
The `start` function of the WebAssembly module invokes the `endless_loop`, that
means that running the final `.wasm` file via something like `wasmtime run` will
cause the endless function to be executed.
## `wapc_endless_loop.wat`
This is a module meant to be used by a waPC host.
This code cheats a little, from the outside it looks like any regular waPC module
because it exposes the two functions required by a waPC host. However, these
two functions are reduced to the bare mimimum.
The most important difference is that no waPC function is registered by the
module. Calling any kind of waPC function from the host will result in an
endless loop being executed.

View File

@@ -0,0 +1,47 @@
;; This is a module meant to be used by a waPC host.
;;
;; This code cheats a little, from the outside it looks like any regular waPC module
;; because it exposes the two functions required by a waPC host. However, these
;; two functions are reduced to the bare mimimum.
;;
;; The most important difference is that no waPC function is registered by the
;; module. Calling any kind of waPC function from the host will result in an
;; endless loop being executed.
(module
(memory (export "memory") 1)
;; waPC host expects a function called wapc_init to be exported
(func $wapc_init (export "wapc_init")
;; we don't do anything in there
nop
)
;; non exported function that performs an endless loop
(func $endless_loop
;; create a variable and initialize it to 0
(local $am_i_done i32)
(loop $endless
;; if $am_i_done is not equal to 1 -> go back to the beginning of the loop
local.get $am_i_done
i32.const 1
i32.ne
br_if $endless
)
)
;; waPC host expects a function called wapc_init to be exported
;; A real implementation would look for the name of the waPC function
;; to be invoked, read its payload, invoke the function and
;; provide a success/failure boolean as result.
;; In this case we just start an endless loop. We don't care about the
;; waPC function to be invoked, nor the payload.
(func $guest_call (export "__guest_call")
(param $operation_size i32)
(param $payload_size i32)
(result i32)
(call $endless_loop)
i32.const 0
)
)

View File

@@ -0,0 +1,15 @@
(module
(func $endless_loop (export "endless_loop")
;; create a variable and initialize it to 0
(local $am_i_done i32)
(loop $endless
;; if $am_i_done is not equal to 1 -> go back to the beginning of the loop
local.get $am_i_done
i32.const 1
i32.ne
br_if $endless
)
)
(start $endless_loop)
)