Skip to content

Commit

Permalink
Give names to some locals and params in wat
Browse files Browse the repository at this point in the history
Also add some comments
  • Loading branch information
yamt committed Jan 23, 2023
1 parent 62781d3 commit 67c2b3f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions test/testsuite/wasi_threads_exit_main_block.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
;; When the main thread calls proc_exit, it should terminate
;; a thread blocking in `memory.atomic.wait32` opecode.
;;
;; linear memory usage:
;; 0: notify/wait

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
Expand Down
3 changes: 3 additions & 0 deletions test/testsuite/wasi_threads_exit_main_busy.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
;; When the main thread calls proc_exit, it should terminate
;; a busy-looping thread.
;;
;; linear memory usage:
;; 0: wait

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
Expand Down
6 changes: 6 additions & 0 deletions test/testsuite/wasi_threads_exit_main_wasi.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
;; When the main thread calls proc_exit, it should terminate
;; a thread blocking in a WASI call. (poll_oneoff)
;;
;; linear memory usage:
;; 0: wait
;; 100: poll_oneoff subscription
;; 200: poll_oneoff event
;; 300: poll_oneoff return value

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
Expand Down
3 changes: 3 additions & 0 deletions test/testsuite/wasi_threads_exit_nonmain_block.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
;; When a non-main thread calls proc_exit, it should terminate
;; the main thread blocking in `memory.atomic.wait32` opecode.
;;
;; linear memory usage:
;; 0: wait

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
Expand Down
3 changes: 3 additions & 0 deletions test/testsuite/wasi_threads_exit_nonmain_busy.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
;; When a non-main thread calls proc_exit, it should terminate
;; the main thread which is busy-looping.
;;
;; linear memory usage:
;; 0: wait

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
Expand Down
6 changes: 6 additions & 0 deletions test/testsuite/wasi_threads_exit_nonmain_wasi.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
;; When a non-main thread calls proc_exit, it should terminate
;; the main thread which is blocking in a WASI call. (poll_oneoff)
;;
;; linear memory usage:
;; 0: wait
;; 100: poll_oneoff subscription
;; 200: poll_oneoff event
;; 300: poll_oneoff return value

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
Expand Down
17 changes: 11 additions & 6 deletions test/testsuite/wasi_threads_spawn.wat
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
;; Create a thread with thread-spawn and perform a few sanity checks.

;; linear memory usage:
;; 0: notify/wait
;; 4: tid
;; 8: user_arg

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
(func (export "wasi_thread_start") (param i32 i32)
(func (export "wasi_thread_start") (param $tid i32) (param $user_arg i32)
;; store tid
i32.const 4
local.get 0
local.get $tid
i32.store
;; store user pointer
i32.const 8
local.get 1
local.get $user_arg
i32.store
;; notify the main
i32.const 0
Expand All @@ -23,12 +28,12 @@
drop
;; returning from wasi_thread_start terminates only this thread
)
(func (export "_start") (local i32)
(func (export "_start") (local $tid i32)
;; spawn a thread
i32.const 12345 ;; user pointer
call $thread_spawn
;; check error
local.tee 0 ;; save the tid to check later
local.tee $tid ;; save the tid to check later
i32.const 0
i32.le_s
if
Expand All @@ -46,7 +51,7 @@
unreachable
end
;; check the tid
local.get 0
local.get $tid
i32.const 4
i32.load
i32.ne
Expand Down

0 comments on commit 67c2b3f

Please sign in to comment.