test-disassemble.scm 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; Copyright (C) 2023 David Thompson <dave@spritely.institute>
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; Disassembler tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils)
  21. (wasm wat))
  22. (test-begin "test-disassemble")
  23. (test-equal "disassemble"
  24. '(module
  25. $bloop
  26. (func $cos (import "math" "cos") (param f64) (result f64))
  27. (table $objs 10 (ref eq))
  28. (memory $main 1)
  29. (global $the-answer i32 (i32.const 42))
  30. (global $mutable (mut i32) (i32.const 0))
  31. (elem $stuff (table $objs) (offset (i32.const 0)) (ref i31)
  32. (item (i32.const 42) (ref.i31)))
  33. (data $bytes $main (i32.const 0) #vu8(1 2 3 4))
  34. (func $factorial (export "factorial") (param $n i32) (result i32)
  35. (local $result i32)
  36. (i32.const 1)
  37. (local.set $result)
  38. (loop $loop (result i32)
  39. (local.get $n)
  40. (i32.const 1)
  41. (i32.eq)
  42. (if (result i32)
  43. (then (local.get $result))
  44. (else (local.get $n)
  45. (local.get $result)
  46. (i32.mul)
  47. (local.set $result)
  48. (local.get $n)
  49. (i32.const 1)
  50. (i32.sub)
  51. (local.set $n)
  52. (br $loop)))))
  53. (func $init (i32.const 1337) (global.set $mutable)))
  54. (wasm->wat
  55. (wat->wasm
  56. '(module
  57. $bloop
  58. (func $cos (import "math" "cos") (param f64) (result f64))
  59. (global $the-answer i32 (i32.const 42))
  60. (global $mutable (mut i32) (i32.const 0))
  61. (table $objs 10 (ref eq))
  62. (memory $main 1)
  63. (elem $stuff (table $objs) (offset (i32.const 0)) (ref i31)
  64. (item (ref.i31 (i32.const 42))))
  65. (data $bytes (memory $main) (i32.const 0) #vu8(1 2 3 4))
  66. (func $factorial (export "factorial") (param $n i32) (result i32)
  67. (local $result i32)
  68. (local.set $result (i32.const 1))
  69. (loop $loop (result i32)
  70. (if (result i32)
  71. (i32.eq (local.get $n) (i32.const 1))
  72. (then (local.get $result))
  73. (else (local.set $result (i32.mul (local.get $n)
  74. (local.get $result)))
  75. (local.set $n (i32.sub (local.get $n)
  76. (i32.const 1)))
  77. (br $loop)))))
  78. (func $init
  79. (global.set $mutable (i32.const 1337)))))))
  80. (test-end* "test-disassemble")