test-lower-globals.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ;;; Copyright (C) 2023 Igalia, S.L.
  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. ;;; String tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (test utils)
  20. (srfi srfi-64)
  21. (wasm lower-globals)
  22. (wasm wat))
  23. (test-begin "test-lower-globals")
  24. (let ((mod (wat->wasm
  25. '((type $i32 (struct i32))
  26. (func $succ (param i32) (result i32)
  27. (i32.add (local.get 0) (i32.const 1)))
  28. (global $g0 i32 (i32.const 42))
  29. (global $g1 (ref $i32)
  30. (struct.new $i32 (global.get $g0)))
  31. (global $g2 (ref $i32)
  32. (struct.new $i32
  33. (call $succ
  34. (struct.get $i32 0 (global.get $g1)))))
  35. (global $g3 (ref $i32)
  36. (struct.new $i32
  37. (call $succ
  38. (struct.get $i32 0 (global.get $g2)))))))))
  39. (test-equal '(module
  40. (type $i32 (struct i32))
  41. (type $__start (func))
  42. (global $g0 i32 (i32.const 42))
  43. (global $g1 (ref $i32) (global.get $g0) (struct.new $i32))
  44. (global $g2 (mut (ref null $i32)) (ref.null $i32))
  45. (global $g3 (mut (ref null $i32)) (ref.null $i32))
  46. (func $succ (param i32) (result i32)
  47. (local.get 0) (i32.const 1) (i32.add))
  48. (func $__start
  49. (global.get $g1) (struct.get $i32 0)
  50. (call $succ) (struct.new $i32) (global.set $g2)
  51. (global.get $g2) (ref.as_non_null) (struct.get $i32 0)
  52. (call $succ) (struct.new $i32) (global.set $g3))
  53. (start $__start))
  54. (wasm->wat (lower-globals mod))))
  55. (test-end* "test-lower-globals")