linking2.wat 816 B

123456789101112131415161718192021222324252627282930313233
  1. (module
  2. (type $fd_write_ty (func (param i32 i32 i32 i32) (result i32)))
  3. (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (type $fd_write_ty)))
  4. (func (export "double") (param i32) (result i32)
  5. local.get 0
  6. i32.const 2
  7. i32.mul
  8. )
  9. (func (export "log") (param i32 i32)
  10. ;; store the pointer in the first iovec field
  11. i32.const 4
  12. local.get 0
  13. i32.store
  14. ;; store the length in the first iovec field
  15. i32.const 4
  16. local.get 1
  17. i32.store offset=4
  18. ;; call the `fd_write` import
  19. i32.const 1 ;; stdout fd
  20. i32.const 4 ;; iovs start
  21. i32.const 1 ;; number of iovs
  22. i32.const 0 ;; where to write nwritten bytes
  23. call $fd_write
  24. drop
  25. )
  26. (memory (export "memory") 2)
  27. (global (export "memory_offset") i32 (i32.const 65536))
  28. )