Skip to content

Commit

Permalink
add a few modules i used to test tail-call of host functions manually
Browse files Browse the repository at this point in the history
```
spacetanuki% ../../b/toywasm --wasi --print-stats tail.wasm
hello
=== execution statistics ===
operand stack 4 (16 bytes)
locals 4 (16 bytes)
labels 0 (0 bytes)
frames 2 (64 bytes)
                   call            3
              host_call            2
              tail_call            1
         host_tail_call            1
                 branch            0
       branch_goto_else            0
        jump_cache2_hit            0
         jump_cache_hit            0
      jump_table_search            0
type_annotation_lookup1            0
type_annotation_lookup2            0
type_annotation_lookup3            0
spacetanuki% ../../b/toywasm --wasi --print-stats nontail.wasm
hello
=== execution statistics ===
operand stack 4 (16 bytes)
locals 4 (16 bytes)
labels 0 (0 bytes)
frames 2 (64 bytes)
                   call            3
              host_call            2
              tail_call            0
         host_tail_call            0
                 branch            0
       branch_goto_else            0
        jump_cache2_hit            0
         jump_cache_hit            0
      jump_table_search            0
type_annotation_lookup1            0
type_annotation_lookup2            0
type_annotation_lookup3            0
spacetanuki%
```
  • Loading branch information
yamt committed Jan 23, 2023
1 parent b1a4400 commit 8eda2a9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions wat/wasi/nontail.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; print hello

(module
(func $fd_write (import "wasi_snapshot_preview1" "fd_write") (param i32 i32 i32 i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
(func $call_fd_write (param i32 i32 i32 i32) (result i32)
local.get 0
local.get 1
local.get 2
local.get 3
call $fd_write
)
(func (export "_start")
i32.const 1
i32.const 0
i32.const 1
i32.const 0
call $call_fd_write
i32.const 0
i32.ne
call $proc_exit
)
(memory (export "memory") 1)

;; iov_base = 0x100, iov_len = 6
(data (i32.const 0) "\00\01\00\00\06\00\00\00")
(data (i32.const 0x100) "hello\n")
)
28 changes: 28 additions & 0 deletions wat/wasi/tail.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; print hello

(module
(func $fd_write (import "wasi_snapshot_preview1" "fd_write") (param i32 i32 i32 i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
(func $call_fd_write (param i32 i32 i32 i32) (result i32)
local.get 0
local.get 1
local.get 2
local.get 3
return_call $fd_write
)
(func (export "_start")
i32.const 1
i32.const 0
i32.const 1
i32.const 0
call $call_fd_write
i32.const 0
i32.ne
call $proc_exit
)
(memory (export "memory") 1)

;; iov_base = 0x100, iov_len = 6
(data (i32.const 0) "\00\01\00\00\06\00\00\00")
(data (i32.const 0x100) "hello\n")
)

0 comments on commit 8eda2a9

Please sign in to comment.