2021-04-19 01:39:04 -04:00
|
|
|
(with_import "./wasm.kp"
|
|
|
|
|
(let (
|
|
|
|
|
_ (println "args" *ARGV*)
|
2021-07-22 01:14:51 -04:00
|
|
|
(_ _ out) (cond (!= (len *ARGV*) 3) (error "wrong number of params to comp_wasm (please provide out)")
|
2021-04-19 01:39:04 -04:00
|
|
|
true *ARGV*)
|
2021-07-18 23:42:19 -04:00
|
|
|
_ (println "out" out)
|
2021-07-25 23:41:41 -04:00
|
|
|
wasm_code
|
|
|
|
|
(module
|
|
|
|
|
(import "wasi_unstable" "path_open"
|
|
|
|
|
(func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32)
|
|
|
|
|
(result i32)))
|
|
|
|
|
(import "wasi_unstable" "fd_prestat_dir_name"
|
|
|
|
|
(func $fd_prestat_dir_name (param i32 i32 i32)
|
|
|
|
|
(result i32)))
|
|
|
|
|
(import "wasi_unstable" "fd_read"
|
|
|
|
|
(func $fd_read (param i32 i32 i32 i32)
|
|
|
|
|
(result i32)))
|
|
|
|
|
(import "wasi_unstable" "fd_write"
|
|
|
|
|
(func $fd_write (param i32 i32 i32 i32)
|
|
|
|
|
(result i32)))
|
|
|
|
|
(memory $mem 1)
|
|
|
|
|
(data (i32.const 16) "HellH") ;; adder to put, then data
|
|
|
|
|
(func $start
|
2021-07-25 22:20:25 -04:00
|
|
|
(i32.store (i32.const 8) (i32.const 16)) ;; adder of data
|
2021-07-25 23:41:41 -04:00
|
|
|
(i32.store (i32.const 12) (i32.const 5)) ;; len of data
|
|
|
|
|
;; open file
|
|
|
|
|
(call $path_open
|
|
|
|
|
(i32.const 3) ;; file descriptor
|
|
|
|
|
(i32.const 0) ;; lookup flags
|
|
|
|
|
(i32.const 16) ;; path string *
|
|
|
|
|
(i32.load (i32.const 12)) ;; path string len
|
|
|
|
|
(i32.const 1) ;; o flags
|
|
|
|
|
(i64.const 66) ;; base rights
|
|
|
|
|
(i64.const 66) ;; inheriting rights
|
|
|
|
|
(i32.const 0) ;; fdflags
|
|
|
|
|
(i32.const 4) ;; opened fd out ptr
|
|
|
|
|
)
|
2021-07-25 22:20:25 -04:00
|
|
|
drop
|
2021-07-27 01:02:16 -04:00
|
|
|
(block $a
|
|
|
|
|
(block $b
|
|
|
|
|
(br $a)
|
|
|
|
|
(br_if $b (i32.const 3))
|
|
|
|
|
(loop $l
|
|
|
|
|
(br $a)
|
|
|
|
|
(br $l)
|
|
|
|
|
)
|
|
|
|
|
(_if $myif (i32.const 1)
|
|
|
|
|
(then
|
|
|
|
|
(i32.const 1)
|
|
|
|
|
drop
|
|
|
|
|
(br $b)
|
|
|
|
|
)
|
|
|
|
|
(else
|
|
|
|
|
(br $myif)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
(_if $another (i32.const 1) (br $b))
|
|
|
|
|
(i32.const 1)
|
|
|
|
|
(_if $third (br $b))
|
|
|
|
|
(_if $fourth (br $fourth))
|
|
|
|
|
)
|
|
|
|
|
)
|
2021-07-25 23:41:41 -04:00
|
|
|
|
|
|
|
|
(call $fd_read
|
|
|
|
|
(i32.const 0) ;; file descriptor
|
|
|
|
|
(i32.const 8) ;; *iovs
|
|
|
|
|
(i32.const 1) ;; iovs_len
|
|
|
|
|
(i32.const 12) ;; nwritten, overwrite buf len with it
|
2021-07-25 02:14:20 -04:00
|
|
|
)
|
2021-07-24 00:39:45 -04:00
|
|
|
drop
|
2021-07-25 18:10:10 -04:00
|
|
|
|
2021-07-25 23:41:41 -04:00
|
|
|
;; print name
|
2021-07-25 18:10:10 -04:00
|
|
|
(call $fd_write
|
2021-07-25 23:41:41 -04:00
|
|
|
(i32.load (i32.const 4)) ;; file descriptor
|
2021-07-25 18:10:10 -04:00
|
|
|
(i32.const 8) ;; *iovs
|
|
|
|
|
(i32.const 1) ;; iovs_len
|
|
|
|
|
(i32.const 4) ;; nwritten
|
|
|
|
|
)
|
|
|
|
|
drop
|
2021-07-25 23:41:41 -04:00
|
|
|
)
|
|
|
|
|
(export "memory" (memory $mem))
|
|
|
|
|
(export "_start" (func $start))
|
2021-07-27 22:21:03 -04:00
|
|
|
(start $start)
|
2021-07-18 23:42:19 -04:00
|
|
|
)
|
2021-04-19 01:39:04 -04:00
|
|
|
_ (write_file out (wasm_to_binary wasm_code))
|
|
|
|
|
return_code 0
|
|
|
|
|
) return_code ))
|