inlining.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WebAssembly.instantiate(WebAssembly.wabt.convertWast2Wasm(`
  6. (module
  7. (type $t1 (func (result i32)))
  8. (type $t2 (func (param i32) (result i32)))
  9. (type $t3 (func))
  10. (import "test" "foo" (func $foo (type $t2)))
  11. (memory (export "memory") 5000 5000)
  12. (global $x (mut i32) (i32.const -12))
  13. (func $f1 (type $t1) (local i32)
  14. (set_local 0 (i32.const 321))
  15. (return
  16. (i32.add
  17. (i32.const 2)
  18. (call $f3 (get_local 0))
  19. )
  20. )
  21. )
  22. (func $f2 (export "a") (type $t2) (local f32)
  23. (if (i32.ge_s (i32.const 26) (i32.const 25))
  24. (set_local 0 (i32.add (get_local 0) (i32.const 4)))
  25. )
  26. (set_local 0 (i32.add (get_local 0) (call_indirect (type $t1) (i32.const 0))))
  27. (if (i32.ge_s (i32.const 22) (i32.const 25))
  28. (set_local 0 (i32.add (get_local 0) (i32.const 4)))
  29. (set_local 0 (i32.sub (get_local 0) (i32.const 5)))
  30. )
  31. (block
  32. (set_local 0 (i32.add (get_local 0) (i32.const 4)))
  33. (set_local 0 (i32.add (get_local 0) (i32.clz (get_local 0))))
  34. (set_local 0 (i32.add (get_local 0) (call $f1)))
  35. (br_if 0 (select (f32.ne (get_local 1) (get_local 1)) (i32.const 0) (i32.const 1)))
  36. (set_local 0 (i32.add (get_local 0) (i32.const 4)))
  37. )
  38. (call $foo (get_local 0))
  39. (i32.store (get_local 0) (i32.add (get_local 0) (i32.const 7)))
  40. (set_local 0 (i32.load (get_local 0)))
  41. (set_local 1 (f32.convert_s/i32 (get_local 0)))
  42. (set_local 1 (f32.add (get_local 1) (get_local 1)))
  43. (set_local 0 (i32.reinterpret/f32 (get_local 1)))
  44. (set_local 0 (i32.add (get_local 0) (call $foo (get_local 0))))
  45. (return (i32.add (get_local 0) (i32.const 42)))
  46. )
  47. (func $f3 (type $t2)
  48. (set_global $x (get_local 0))
  49. (i32.store (get_global $x)
  50. (i32.add
  51. (get_local 0)
  52. (i32.const 456)
  53. )
  54. )
  55. (call $f4)
  56. (return (i32.load (get_local 0))
  57. ))
  58. (func $f4 (type $t3)
  59. (return)
  60. )
  61. (table anyfunc (elem $f1 $f2))
  62. )`), {test: {foo(v) {return v + 5;}}})
  63. .then(({instance: {exports: {a}}}) => {
  64. console.log(a());
  65. console.log(a());
  66. }, console.log)
  67. .catch(console.log);