-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WASI: add args_get and args_sizes_get
Update the test script to test passing the arguments as well Signed-off-by: Máté Tokodi [email protected]
- Loading branch information
1 parent
50f6317
commit e9a6258
Showing
5 changed files
with
162 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(module | ||
(import "wasi_snapshot_preview1" "fd_write" (func $wasi_fd_write (param i32 i32 i32 i32) (result i32))) | ||
(import "wasi_snapshot_preview1" "args_get" (func $wasi_args_get (param i32 i32) (result i32))) | ||
(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi_args_sizes_get (param i32 i32) (result i32))) | ||
(memory 1) | ||
|
||
(export "memory" (memory 0)) | ||
(export "print_args" (func $print_args)) | ||
(data (i32.const 100) "500" ) | ||
|
||
(func $print_args | ||
(local $i i32) | ||
i32.const 0 ;; args count | ||
i32.const 12 ;; args overall size in characters | ||
call $wasi_args_sizes_get | ||
drop | ||
|
||
i32.const 500 ;; argp | ||
i32.const 600 ;; argp[0] | ||
call $wasi_args_get | ||
drop | ||
|
||
;; Memory[100] = 600, start of output string. | ||
i32.const 100 | ||
i32.const 600 | ||
i32.store | ||
|
||
;; Memory[104] = size of output string. | ||
i32.const 104 | ||
i32.const 12 | ||
i32.load | ||
i32.store | ||
|
||
;; Replace '\0' with '\n' for readable printing. | ||
i32.const 0 | ||
local.set $i | ||
(loop $loop | ||
i32.const 600 | ||
local.get $i | ||
i32.add | ||
i32.load8_u | ||
|
||
i32.eqz | ||
(if | ||
(then | ||
i32.const 600 | ||
local.get $i | ||
i32.add | ||
i32.const 10 | ||
i32.store8 | ||
) | ||
) | ||
|
||
local.get $i | ||
i32.const 1 | ||
i32.add | ||
local.tee $i | ||
|
||
i32.const 12 | ||
i32.load | ||
i32.lt_u | ||
br_if $loop | ||
) | ||
|
||
(call $wasi_fd_write | ||
(i32.const 1) ;;file descriptor | ||
(i32.const 100) ;;offset of str offset | ||
(i32.const 1) ;;iovec length | ||
(i32.const 200) ;;result offset | ||
) | ||
drop | ||
) | ||
) | ||
|
||
(assert_return (invoke "print_args")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters