testapp.wat 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;; Copyright (C) 2024 YAMAMOTO Takashi
  2. ;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. (module
  4. (func $fd_read (import "wasi_snapshot_preview1" "fd_read") (param i32 i32 i32 i32) (result i32))
  5. (func $block_forever (export "block_forever")
  6. ;; read from FD 0
  7. i32.const 100 ;; iov_base
  8. i32.const 200 ;; buffer
  9. i32.store
  10. i32.const 104 ;; iov_len
  11. i32.const 1
  12. i32.store
  13. i32.const 0 ;; fd 0
  14. i32.const 100 ;; iov_base
  15. i32.const 1 ;; iov count
  16. i32.const 300 ;; retp (out)
  17. call $fd_read
  18. unreachable
  19. )
  20. (func (export "_start")
  21. call $block_forever
  22. )
  23. ;; a dumb malloc/free implementation
  24. (func (export "malloc") (param i32) (result i32)
  25. local.get 0
  26. i32.const 65535
  27. i32.add
  28. i32.const 65536
  29. i32.div_u
  30. memory.grow
  31. local.set 0
  32. local.get 0
  33. i32.const -1
  34. i32.eq
  35. if
  36. i32.const 0
  37. return
  38. end
  39. local.get 0
  40. i32.const 65536
  41. i32.mul
  42. )
  43. (func (export "free") (param i32))
  44. (memory (export "memory") 1)
  45. ;; fake globals to make wasm_set_aux_stack happy
  46. (global (export "__heap_base") i32 (i32.const 0x10000))
  47. (global (export "__data_end") i32 (i32.const 0x10000))
  48. (global (mut i32) (i32.const 0x10000))
  49. )