Skip to content

Commit

Permalink
a test wat
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jun 7, 2023
1 parent 0658153 commit 7d36df0
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions wat/wasi/recursive_hello_arg.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(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 $args_get (import "wasi_snapshot_preview1" "args_get") (param i32 i32) (result i32))
(func $args_sizes_get (import "wasi_snapshot_preview1" "args_sizes_get") (param i32 i32) (result i32))
(func $putstrz (param $p i32)
(local $tmp i32)
local.get $p
i32.load8_u
local.tee $tmp
i32.eqz
br_if 0

i32.const 0
local.get $p
i32.store

i32.const 1
i32.const 0
i32.const 1
i32.const 0
call $fd_write
i32.const 0
i32.ne
if
i32.const 1
call $proc_exit
end

local.get $p
i32.const 1
i32.add
call $putstrz
)
(func $print_args
i32.const 0x1000 ;; &argc
i32.const 0x1004
call $args_sizes_get
if
unreachable
end

i32.const 0x1004 ;; &argv
i32.const 0x2000
call $args_get
if
unreachable
end

;; hello,
i32.const 0x100
call $putstrz

i32.const 0x1000
i32.load
i32.const 2
i32.ne
if (result i32)
;; noname
i32.const 0x300
else
;; argv[1]
i32.const 0x1004
i32.load offset=0x4
end
call $putstrz

;; newline
i32.const 0x200
call $putstrz
)
(func (export "_start")
call $print_args
)
(memory (export "memory") 1)

;; iov_base = 0, iov_len = 1
(data (i32.const 0) "\00\00\00\00\01\00\00\00")
(data (i32.const 0x100) "hello, \00")
(data (i32.const 0x200) "\n\00")
(data (i32.const 0x300) "noname\00")
)

0 comments on commit 7d36df0

Please sign in to comment.