@grain/binaryen.ml 0.9.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. {binaryen-archive → binaryen-archive-v0.11.2}/.gitattributes +0 -0
  2. {binaryen-archive → binaryen-archive-v0.11.2}/.gitignore +1 -0
  3. {binaryen-archive → binaryen-archive-v0.11.2}/.gitmodules +0 -0
  4. {binaryen-archive → binaryen-archive-v0.11.2}/CHANGELOG.md +73 -0
  5. {binaryen-archive → binaryen-archive-v0.11.2}/LICENSE +0 -0
  6. {binaryen-archive → binaryen-archive-v0.11.2}/README.md +27 -3
  7. {binaryen-archive → binaryen-archive-v0.11.2}/binaryen.opam +8 -8
  8. {binaryen-archive → binaryen-archive-v0.11.2}/dune +0 -0
  9. {binaryen-archive → binaryen-archive-v0.11.2}/dune-project +0 -0
  10. {binaryen-archive → binaryen-archive-v0.11.2}/dune-workspace +0 -0
  11. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/.gitattributes +0 -0
  12. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/.gitignore +0 -0
  13. binaryen-archive-v0.11.2/esy.lock/index.json +1365 -0
  14. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/astring.0.8.5/opam +0 -0
  15. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/base-threads.base/opam +0 -0
  16. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/base-unix.base/opam +0 -0
  17. {binaryen-archive/esy.lock/opam/base.v0.14.1 → binaryen-archive-v0.11.2/esy.lock/opam/base.v0.14.2}/opam +4 -4
  18. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/biniou.1.2.1/opam +1 -1
  19. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/cmdliner.1.0.4/opam +0 -0
  20. {binaryen-archive/esy.lock/opam/cppo.1.6.7 → binaryen-archive-v0.11.2/esy.lock/opam/cppo.1.6.8}/opam +4 -6
  21. {binaryen-archive/esy.lock/opam/csexp.1.4.0 → binaryen-archive-v0.11.2/esy.lock/opam/csexp.1.5.1}/opam +11 -9
  22. {binaryen-archive/esy.lock/opam/dune-build-info.2.8.2 → binaryen-archive-v0.11.2/esy.lock/opam/dune-build-info.2.9.1}/opam +5 -5
  23. {binaryen-archive/esy.lock/opam/dune-configurator.2.8.2 → binaryen-archive-v0.11.2/esy.lock/opam/dune-configurator.2.9.1}/opam +5 -5
  24. {binaryen-archive/esy.lock/opam/dune.2.8.2 → binaryen-archive-v0.11.2/esy.lock/opam/dune.2.9.1}/opam +4 -4
  25. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/easy-format.1.3.2/opam +1 -1
  26. {binaryen-archive/esy.lock/opam/fix.20201120 → binaryen-archive-v0.11.2/esy.lock/opam/fix.20211231}/opam +7 -5
  27. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/fpath.0.7.3/opam +0 -0
  28. binaryen-archive-v0.11.2/esy.lock/opam/js_of_ocaml-compiler.3.11.0/opam +54 -0
  29. binaryen-archive-v0.11.2/esy.lock/opam/js_of_ocaml-ppx.3.11.0/opam +44 -0
  30. binaryen-archive-v0.11.2/esy.lock/opam/js_of_ocaml.3.11.0/opam +45 -0
  31. {binaryen-archive/esy.lock/opam/menhir.20201216 → binaryen-archive-v0.11.2/esy.lock/opam/menhir.20211128}/opam +8 -6
  32. {binaryen-archive/esy.lock/opam/menhirLib.20201216 → binaryen-archive-v0.11.2/esy.lock/opam/menhirLib.20211128}/opam +8 -6
  33. {binaryen-archive/esy.lock/opam/menhirSdk.20201216 → binaryen-archive-v0.11.2/esy.lock/opam/menhirSdk.20211128}/opam +8 -6
  34. binaryen-archive-v0.11.2/esy.lock/opam/ocaml-compiler-libs.v0.12.4/opam +39 -0
  35. {binaryen-archive/esy.lock/opam/ocaml-lsp-server.1.4.0 → binaryen-archive-v0.11.2/esy.lock/opam/ocaml-lsp-server.1.9.0}/opam +15 -12
  36. {binaryen-archive/esy.lock/opam/ocaml-migrate-parsetree.2.1.0 → binaryen-archive-v0.11.2/esy.lock/opam/ocaml-migrate-parsetree.2.3.0}/opam +13 -10
  37. binaryen-archive-v0.11.2/esy.lock/opam/ocaml-version.3.4.0/opam +49 -0
  38. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/ocamlbuild.0.14.0/opam +1 -1
  39. {binaryen-archive/esy.lock/opam/ocamlfind.1.8.1 → binaryen-archive-v0.11.2/esy.lock/opam/ocamlfind.1.9.1}/opam +19 -39
  40. binaryen-archive-v0.11.2/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam +40 -0
  41. binaryen-archive-v0.11.2/esy.lock/opam/ocamlformat.0.18.0/opam +56 -0
  42. {binaryen-archive/esy.lock/opam/odoc.1.5.2 → binaryen-archive-v0.11.2/esy.lock/opam/odoc.1.5.3}/opam +12 -12
  43. binaryen-archive-v0.11.2/esy.lock/opam/pp.1.1.2/opam +58 -0
  44. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/ppx_derivers.1.2.1/opam +1 -1
  45. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam +2 -2
  46. {binaryen-archive/esy.lock/opam/ppxlib.0.21.0 → binaryen-archive-v0.11.2/esy.lock/opam/ppxlib.0.22.2}/opam +40 -32
  47. {binaryen-archive/esy.lock/opam/re.1.9.0 → binaryen-archive-v0.11.2/esy.lock/opam/re.1.10.3}/opam +8 -4
  48. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/result.1.5/opam +2 -2
  49. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/seq.base/files/META.seq +0 -0
  50. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/seq.base/files/seq.install +0 -0
  51. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/seq.base/opam +0 -0
  52. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/sexplib0.v0.14.0/opam +2 -2
  53. binaryen-archive-v0.11.2/esy.lock/opam/spawn.v0.15.0/opam +56 -0
  54. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/stdio.v0.14.0/opam +2 -2
  55. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/stdlib-shims.0.3.0/opam +0 -0
  56. {binaryen-archive/esy.lock/opam/topkg.1.0.3 → binaryen-archive-v0.11.2/esy.lock/opam/topkg.1.0.4}/opam +18 -22
  57. binaryen-archive-v0.11.2/esy.lock/opam/tyxml.4.5.0/opam +42 -0
  58. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/uchar.0.0.2/opam +0 -0
  59. binaryen-archive-v0.11.2/esy.lock/opam/uucp.14.0.0/opam +41 -0
  60. {binaryen-archive/esy.lock/opam/uuseg.13.0.0 → binaryen-archive-v0.11.2/esy.lock/opam/uuseg.14.0.0}/opam +22 -28
  61. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/uutf.1.0.2/opam +0 -0
  62. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/opam/yojson.1.7.0/opam +1 -1
  63. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/overrides/opam__s__ocamlbuild_opam__c__0.14.0_opam_override/files/ocamlbuild-0.14.0.patch +0 -0
  64. {binaryen-archive → binaryen-archive-v0.11.2}/esy.lock/overrides/opam__s__ocamlbuild_opam__c__0.14.0_opam_override/package.json +0 -0
  65. binaryen-archive/esy.lock/overrides/opam__s__ocamlfind_opam__c__1.8.1_opam_override/files/findlib-1.8.1.patch → binaryen-archive-v0.11.2/esy.lock/overrides/opam__s__ocamlfind_opam__c__1.9.1_opam_override/files/findlib-1.9.1.patch +0 -0
  66. {binaryen-archive/esy.lock/overrides/opam__s__ocamlfind_opam__c__1.8.1_opam_override → binaryen-archive-v0.11.2/esy.lock/overrides/opam__s__ocamlfind_opam__c__1.9.1_opam_override}/package.json +1 -1
  67. binaryen-archive-v0.11.2/js/binaryen.es5.js +5 -0
  68. {binaryen-archive → binaryen-archive-v0.11.2}/js/dune +1 -6
  69. binaryen-archive-v0.11.2/js/element_segment.ml +33 -0
  70. binaryen-archive-v0.11.2/js/export.ml +60 -0
  71. binaryen-archive-v0.11.2/js/expression.ml +944 -0
  72. binaryen-archive-v0.11.2/js/function.ml +60 -0
  73. binaryen-archive-v0.11.2/js/global.ml +48 -0
  74. {binaryen-archive → binaryen-archive-v0.11.2}/js/import.ml +24 -0
  75. {binaryen-archive → binaryen-archive-v0.11.2}/js/literal.ml +0 -0
  76. {binaryen-archive → binaryen-archive-v0.11.2}/js/memory.ml +0 -0
  77. {binaryen-archive → binaryen-archive-v0.11.2}/js/module.ml +42 -46
  78. {binaryen-archive → binaryen-archive-v0.11.2}/js/op.ml +9 -78
  79. binaryen-archive-v0.11.2/js/postlude.js +2 -0
  80. binaryen-archive-v0.11.2/js/prelude.js +11 -0
  81. binaryen-archive-v0.11.2/js/settings.ml +60 -0
  82. {binaryen-archive → binaryen-archive-v0.11.2}/js/stubs.c +0 -0
  83. binaryen-archive-v0.11.2/js/table.ml +29 -0
  84. {binaryen-archive → binaryen-archive-v0.11.2}/js/type.ml +3 -0
  85. binaryen-archive-v0.11.2/package.json +37 -0
  86. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_exports.c +78 -0
  87. binaryen-archive-v0.11.2/src/binaryen_stubs_expressions.c +1710 -0
  88. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_features.c +7 -0
  89. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_functions.c +78 -0
  90. binaryen-archive-v0.11.2/src/binaryen_stubs_globals.c +109 -0
  91. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_imports.c +29 -0
  92. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_literals.c +0 -0
  93. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_memory.c +1 -1
  94. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_modules.c +0 -122
  95. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_ops.c +19 -173
  96. binaryen-archive-v0.11.2/src/binaryen_stubs_settings.c +145 -0
  97. binaryen-archive-v0.11.2/src/binaryen_stubs_tables.c +145 -0
  98. {binaryen-archive → binaryen-archive-v0.11.2}/src/binaryen_stubs_types.c +18 -0
  99. binaryen-archive-v0.11.2/src/dune +14 -0
  100. binaryen-archive-v0.11.2/src/element_segment.ml +13 -0
  101. binaryen-archive-v0.11.2/src/export.ml +54 -0
  102. binaryen-archive-v0.11.2/src/expression.ml +844 -0
  103. {binaryen-archive → binaryen-archive-v0.11.2}/src/function.ml +18 -0
  104. binaryen-archive-v0.11.2/src/global.ml +24 -0
  105. {binaryen-archive → binaryen-archive-v0.11.2}/src/import.ml +12 -0
  106. {binaryen-archive → binaryen-archive-v0.11.2}/src/literal.ml +0 -0
  107. {binaryen-archive → binaryen-archive-v0.11.2}/src/memory.ml +0 -0
  108. binaryen-archive-v0.11.2/src/module.ml +115 -0
  109. {binaryen-archive → binaryen-archive-v0.11.2}/src/ocaml_helpers.c +0 -8
  110. {binaryen-archive → binaryen-archive-v0.11.2}/src/ocaml_helpers.h +2 -3
  111. {binaryen-archive → binaryen-archive-v0.11.2}/src/op.ml +18 -131
  112. binaryen-archive-v0.11.2/src/settings.ml +45 -0
  113. binaryen-archive-v0.11.2/src/table.ml +26 -0
  114. {binaryen-archive → binaryen-archive-v0.11.2}/src/type.ml +2 -0
  115. binaryen-archive-v0.11.2/test/config/dune +8 -0
  116. binaryen-archive-v0.11.2/test/config/ocamlopt_flags.ml +16 -0
  117. {binaryen-archive → binaryen-archive-v0.11.2}/test/dune +4 -0
  118. {binaryen-archive → binaryen-archive-v0.11.2}/test/test.expected +38 -5
  119. binaryen-archive-v0.11.2/test/test.ml +147 -0
  120. binaryen-archive-v0.11.2/virtual/dune +6 -0
  121. binaryen-archive-v0.11.2/virtual/element_segment.mli +11 -0
  122. binaryen-archive-v0.11.2/virtual/export.mli +33 -0
  123. binaryen-archive-v0.11.2/virtual/expression.mli +423 -0
  124. {binaryen-archive → binaryen-archive-v0.11.2}/virtual/function.mli +16 -0
  125. binaryen-archive-v0.11.2/virtual/global.mli +19 -0
  126. {binaryen-archive → binaryen-archive-v0.11.2}/virtual/import.mli +8 -0
  127. {binaryen-archive → binaryen-archive-v0.11.2}/virtual/literal.mli +0 -0
  128. {binaryen-archive → binaryen-archive-v0.11.2}/virtual/memory.mli +0 -0
  129. binaryen-archive-v0.11.2/virtual/module.mli +65 -0
  130. {binaryen-archive → binaryen-archive-v0.11.2}/virtual/op.mli +9 -53
  131. binaryen-archive-v0.11.2/virtual/settings.mli +35 -0
  132. binaryen-archive-v0.11.2/virtual/table.mli +19 -0
  133. {binaryen-archive → binaryen-archive-v0.11.2}/virtual/type.mli +2 -0
  134. binaryen-archive/esy.lock/index.json +0 -1288
  135. binaryen-archive/esy.lock/opam/conf-m4.1/opam +0 -22
  136. binaryen-archive/esy.lock/opam/dot-merlin-reader.4.1/opam +0 -30
  137. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.3.9.1/opam +0 -40
  138. binaryen-archive/esy.lock/opam/js_of_ocaml-ppx.3.9.0/opam +0 -30
  139. binaryen-archive/esy.lock/opam/js_of_ocaml.3.9.0/opam +0 -31
  140. binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.12.3/opam +0 -29
  141. binaryen-archive/esy.lock/opam/ocamlfind.1.8.1/files/ocaml-stub +0 -4
  142. binaryen-archive/esy.lock/opam/ocamlfind.1.8.1/files/ocamlfind.install +0 -6
  143. binaryen-archive/esy.lock/opam/ocamlformat.0.15.1/opam +0 -41
  144. binaryen-archive/esy.lock/opam/tyxml.4.4.0/opam +0 -47
  145. binaryen-archive/esy.lock/opam/uucp.13.0.0/opam +0 -44
  146. binaryen-archive/esy.lock/overrides/opam__s__conf_m4_opam__c__1_opam_override/package.json +0 -6
  147. binaryen-archive/js/export.ml +0 -23
  148. binaryen-archive/js/expression.ml +0 -185
  149. binaryen-archive/js/features.ml +0 -27
  150. binaryen-archive/js/function.ml +0 -29
  151. binaryen-archive/js/function_table.ml +0 -13
  152. binaryen-archive/js/global.ml +0 -19
  153. binaryen-archive/js/postlude.js +0 -2
  154. binaryen-archive/js/table.ml +0 -12
  155. binaryen-archive/package.json +0 -43
  156. binaryen-archive/src/binaryen_stubs_expressions.c +0 -410
  157. binaryen-archive/src/binaryen_stubs_function_tables.c +0 -25
  158. binaryen-archive/src/binaryen_stubs_globals.c +0 -46
  159. binaryen-archive/src/binaryen_stubs_tables.c +0 -31
  160. binaryen-archive/src/config/dune +0 -8
  161. binaryen-archive/src/config/library_flags.ml +0 -16
  162. binaryen-archive/src/dune +0 -53
  163. binaryen-archive/src/export.ml +0 -21
  164. binaryen-archive/src/expression.ml +0 -115
  165. binaryen-archive/src/features.ml +0 -49
  166. binaryen-archive/src/function_table.ml +0 -6
  167. binaryen-archive/src/global.ml +0 -10
  168. binaryen-archive/src/module.ml +0 -89
  169. binaryen-archive/src/table.ml +0 -4
  170. binaryen-archive/test/test.ml +0 -83
  171. binaryen-archive/vendor/binaryen-c.h +0 -2647
  172. binaryen-archive/vendor/js/index.es5.js +0 -5
  173. binaryen-archive/vendor/linux/libbinaryen.a +0 -0
  174. binaryen-archive/vendor/linux/libbinaryen.so +0 -0
  175. binaryen-archive/vendor/macosx/libbinaryen.a +0 -0
  176. binaryen-archive/vendor/macosx/libbinaryen.dylib +0 -0
  177. binaryen-archive/vendor/mingw64/libbinaryen.a +0 -0
  178. binaryen-archive/vendor/mingw64/libbinaryen.dll +0 -0
  179. binaryen-archive/vendor/wasm-delegations.h +0 -85
  180. binaryen-archive/virtual/dune +0 -6
  181. binaryen-archive/virtual/export.mli +0 -11
  182. binaryen-archive/virtual/expression.mli +0 -68
  183. binaryen-archive/virtual/features.mli +0 -23
  184. binaryen-archive/virtual/function_table.mli +0 -4
  185. binaryen-archive/virtual/global.mli +0 -7
  186. binaryen-archive/virtual/module.mli +0 -67
  187. binaryen-archive/virtual/table.mli +0 -2
@@ -0,0 +1,147 @@
1
+ open Binaryen
2
+
3
+ (* Testing colors enable *)
4
+ let _ = assert (Settings.are_colors_enabled () == true)
5
+
6
+ let _ = Settings.set_colors_enabled false
7
+
8
+ let _ = assert (Settings.are_colors_enabled () == false)
9
+
10
+ let _ = Settings.set_colors_enabled true
11
+
12
+ (* Testing debug_info enable *)
13
+ let _ = assert (Settings.get_debug_info () == false)
14
+
15
+ let _ = Settings.set_debug_info true
16
+
17
+ let _ = assert (Settings.get_debug_info () == true)
18
+
19
+ let _ = Settings.set_debug_info false
20
+
21
+ (* Testing low_memory_unused enable *)
22
+ let _ = assert (Settings.get_low_memory_unused () == false)
23
+
24
+ let _ = Settings.set_low_memory_unused true
25
+
26
+ let _ = assert (Settings.get_low_memory_unused () == true)
27
+
28
+ let _ = Settings.set_low_memory_unused false
29
+
30
+ let wasm_mod = Module.create ()
31
+
32
+ let _ = Module.set_features wasm_mod [ Module.Feature.all ]
33
+
34
+ (* Create function type for i32 (i32, i32) *)
35
+ let params () = Type.create [| Type.int32; Type.int32 |]
36
+
37
+ let results = Type.int32
38
+
39
+ let x () = Expression.Local_get.make wasm_mod 0 Type.int32
40
+
41
+ let y () = Expression.Local_get.make wasm_mod 1 Type.int32
42
+
43
+ let load = Expression.Load.make wasm_mod 1 ~signed:true 0 0 Type.int32 (y ())
44
+
45
+ let select =
46
+ Expression.Select.make wasm_mod
47
+ (Expression.Const.make wasm_mod (Literal.int32 1l))
48
+ (x ()) load
49
+
50
+ let bin = Expression.Binary.make wasm_mod Op.add_int32 select (y ())
51
+
52
+ let add =
53
+ Expression.Block.make wasm_mod ~return_type:Type.int32 "add"
54
+ [
55
+ Expression.If.make wasm_mod
56
+ (Expression.Const.make wasm_mod (Literal.int32 0l))
57
+ (Expression.Unreachable.make wasm_mod)
58
+ (Expression.Null.make ());
59
+ bin;
60
+ ]
61
+
62
+ (* Create the add function *)
63
+ let adder = Function.add_function wasm_mod "adder" (params ()) results [||] add
64
+
65
+ let call_adder =
66
+ Expression.Call_indirect.make wasm_mod "table"
67
+ (Expression.Const.make wasm_mod (Literal.int32 0l))
68
+ [
69
+ Expression.Const.make wasm_mod (Literal.int32 3l);
70
+ Expression.Const.make wasm_mod (Literal.int32 5l);
71
+ ]
72
+ (params ()) Type.int32
73
+
74
+ let start =
75
+ Function.add_function wasm_mod "start" Type.none Type.none [||]
76
+ (Expression.Drop.make wasm_mod call_adder)
77
+
78
+ let _ = Export.add_function_export wasm_mod "adder" "adder"
79
+
80
+ let _ = Table.add_table wasm_mod "table" 1 1
81
+
82
+ let _ =
83
+ Global.add_global wasm_mod "max_int64" Type.int64 false
84
+ (Expression.Const.make wasm_mod (Literal.int64 Int64.max_int))
85
+
86
+ let _ =
87
+ Global.add_global wasm_mod "test_float64_bits" Type.float64 false
88
+ (Expression.Const.make wasm_mod (Literal.float64_bits 0x3FF3AE147AE147AEL))
89
+
90
+ let _ =
91
+ Table.add_active_element_segment wasm_mod "table" "elem" [ "adder" ]
92
+ (Expression.Const.make wasm_mod (Literal.int32 0l))
93
+
94
+ let _ = Function.set_start wasm_mod start
95
+
96
+ let _ = Memory.set_memory wasm_mod 1 Memory.unlimited "memory" [] false
97
+
98
+ (* Create an imported "write" function i32 (externref, i32, i32) *)
99
+ (* Similar to the example here: https://bytecodealliance.org/articles/reference-types-in-wasmtime *)
100
+
101
+ let _ =
102
+ Import.add_function_import wasm_mod "write" "future-wasi" "write"
103
+ (Type.create [| Type.externref; Type.int32; Type.int32 |])
104
+ Type.int32
105
+
106
+ (* Create a function that calls the imported write function *)
107
+ let _ =
108
+ Function.add_function wasm_mod "hello" Type.externref Type.int32 [||]
109
+ (Expression.Call.make wasm_mod "write"
110
+ [
111
+ Expression.Local_get.make wasm_mod 0 Type.externref;
112
+ Expression.Const.make wasm_mod (Literal.int32 0l);
113
+ Expression.Const.make wasm_mod (Literal.int32 1l);
114
+ ]
115
+ Type.int32)
116
+
117
+ let _ = Export.add_function_export wasm_mod "hello" "hello"
118
+
119
+ (* Finally, we print 3 versions of the module to be checked against test.expected *)
120
+
121
+ (* 1. Print the the module as-is *)
122
+
123
+ let _ = Module.print wasm_mod
124
+
125
+ (* 2. Optimize, then print the module *)
126
+
127
+ let _ = Module.optimize wasm_mod
128
+
129
+ let _ = Module.print wasm_mod
130
+
131
+ (* 3. Copy previous module bytes into new module, validate, and print *)
132
+
133
+ let byts, _ = Module.write wasm_mod None
134
+
135
+ let new_mod = Module.read byts
136
+
137
+ let _ = Module.set_features new_mod [ Module.Feature.all ]
138
+
139
+ let _ = Module.validate new_mod
140
+
141
+ let _ = Module.print new_mod
142
+
143
+ (* Dispose the modules 👋 *)
144
+
145
+ let _ = Module.dispose wasm_mod
146
+
147
+ let _ = Module.dispose new_mod
@@ -0,0 +1,6 @@
1
+ (library
2
+ (name binaryen)
3
+ (public_name binaryen)
4
+ (virtual_modules element_segment export expression function global import
5
+ literal memory module op settings table type)
6
+ (default_implementation binaryen.native))
@@ -0,0 +1,11 @@
1
+ type t
2
+
3
+ val get_name : t -> string
4
+
5
+ val get_table : t -> string
6
+
7
+ val get_offset : t -> Expression.t
8
+
9
+ val get_length : t -> int
10
+
11
+ val get_data : t -> int -> string
@@ -0,0 +1,33 @@
1
+ type t
2
+
3
+ val add_function_export : Module.t -> string -> string -> t
4
+
5
+ val add_table_export : Module.t -> string -> string -> t
6
+
7
+ val add_memory_export : Module.t -> string -> string -> t
8
+
9
+ val add_global_export : Module.t -> string -> string -> t
10
+
11
+ val get_export : Module.t -> string -> t
12
+
13
+ val remove_export : Module.t -> string -> unit
14
+
15
+ val get_num_exports : Module.t -> int
16
+
17
+ val get_export_by_index : Module.t -> int -> t
18
+
19
+ val get_name : t -> string
20
+
21
+ val get_value : t -> string
22
+
23
+ val external_function : int
24
+
25
+ val external_table : int
26
+
27
+ val external_memory : int
28
+
29
+ val external_global : int
30
+
31
+ val external_event : int
32
+
33
+ val export_get_kind : t -> int
@@ -0,0 +1,423 @@
1
+ type t
2
+
3
+ type kind =
4
+ | Invalid
5
+ | Nop
6
+ | Block
7
+ | If
8
+ | Loop
9
+ | Break
10
+ | Switch
11
+ | Call
12
+ | CallIndirect
13
+ | LocalGet
14
+ | LocalSet
15
+ | GlobalGet
16
+ | GlobalSet
17
+ | Load
18
+ | Store
19
+ | AtomicRMW
20
+ | AtomicCmpxchg
21
+ | AtomicWait
22
+ | AtomicNotify
23
+ | AtomicFence
24
+ | SIMDExtract
25
+ | SIMDReplace
26
+ | SIMDShuffle
27
+ | SIMDTernary
28
+ | SIMDShift
29
+ | SIMDLoad
30
+ | SIMDLoadStoreLane
31
+ | MemoryInit
32
+ | DataDrop
33
+ | MemoryCopy
34
+ | MemoryFill
35
+ | Const
36
+ | Unary
37
+ | Binary
38
+ | Select
39
+ | Drop
40
+ | Return
41
+ | MemorySize
42
+ | MemoryGrow
43
+ | Unreachable
44
+ | Pop
45
+ | RefNull
46
+ | RefIs
47
+ | RefFunc
48
+ | RefEq
49
+ | Try
50
+ | Throw
51
+ | Rethrow
52
+ | TupleMake
53
+ | TupleExtract
54
+ | I31New
55
+ | I31Get
56
+ | CallRef
57
+ | RefTest
58
+ | RefCast
59
+ | BrOn
60
+ | RttCanon
61
+ | RttSub
62
+ | StructNew
63
+ | StructGet
64
+ | StructSet
65
+ | ArrayNew
66
+ | ArrayGet
67
+ | ArraySet
68
+ | ArrayLen
69
+ | RefAs
70
+
71
+ val get_kind : t -> kind
72
+
73
+ val print : t -> unit
74
+
75
+ val finalize : t -> unit
76
+
77
+ val copy : t -> Module.t -> t
78
+
79
+ (* Expression operations *)
80
+
81
+ module Block : sig
82
+ val make : ?return_type:Type.t -> Module.t -> string -> t list -> t
83
+
84
+ val get_name : t -> string option
85
+
86
+ val set_name : t -> string -> unit
87
+
88
+ val get_num_children : t -> int
89
+
90
+ val get_child_at : t -> int -> t
91
+
92
+ val set_child_at : t -> int -> t -> unit
93
+
94
+ val append_child : t -> t -> int
95
+
96
+ val insert_child_at : t -> int -> t -> unit
97
+
98
+ val remove_child_at : t -> int -> t
99
+ end
100
+
101
+ module If : sig
102
+ val make : Module.t -> t -> t -> t -> t
103
+
104
+ val get_condition : t -> t
105
+
106
+ val set_condition : t -> t -> unit
107
+
108
+ val get_if_true : t -> t
109
+
110
+ val set_if_true : t -> t -> unit
111
+
112
+ val get_if_false : t -> t option
113
+
114
+ val set_if_false : t -> t -> unit
115
+ end
116
+
117
+ module Loop : sig
118
+ val make : Module.t -> string -> t -> t
119
+
120
+ val get_name : t -> string
121
+
122
+ val set_name : t -> string -> unit
123
+
124
+ val get_body : t -> t
125
+
126
+ val set_body : t -> t -> unit
127
+ end
128
+
129
+ module Break : sig
130
+ val make : Module.t -> string -> t -> t -> t
131
+
132
+ val get_name : t -> string
133
+
134
+ val set_name : t -> string -> unit
135
+
136
+ val get_condition : t -> t option
137
+
138
+ val set_condition : t -> t -> unit
139
+
140
+ val get_value : t -> t option
141
+
142
+ val set_value : t -> t -> unit
143
+ end
144
+
145
+ module Switch : sig
146
+ val make : Module.t -> string list -> string -> t -> t -> t
147
+
148
+ val get_num_names : t -> int
149
+
150
+ val get_name_at : t -> int -> string
151
+
152
+ val set_name_at : t -> int -> string -> unit
153
+
154
+ val append_name : t -> string -> int
155
+
156
+ val insert_name_at : t -> int -> string -> unit
157
+
158
+ val remove_name_at : t -> int -> string
159
+
160
+ val get_default_name : t -> string option
161
+
162
+ val set_default_name : t -> string -> unit
163
+
164
+ val get_condition : t -> t
165
+
166
+ val set_condition : t -> t -> unit
167
+
168
+ val get_value : t -> t option
169
+
170
+ val set_value : t -> t -> unit
171
+ end
172
+
173
+ module Call : sig
174
+ val make : Module.t -> string -> t list -> Type.t -> t
175
+
176
+ val make_return : Module.t -> string -> t list -> Type.t -> t
177
+
178
+ val get_target : t -> string
179
+
180
+ val set_target : t -> string -> unit
181
+
182
+ val get_num_operands : t -> int
183
+
184
+ val get_operand_at : t -> int -> t
185
+
186
+ val set_operand_at : t -> int -> t -> unit
187
+
188
+ val append_operand : t -> t -> int
189
+
190
+ val insert_operand_at : t -> int -> t -> unit
191
+
192
+ val remove_operand_at : t -> int -> t
193
+
194
+ val is_return : t -> bool
195
+
196
+ val set_return : t -> bool -> unit
197
+ end
198
+
199
+ module Call_indirect : sig
200
+ val make : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t
201
+
202
+ val make_return : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t
203
+
204
+ val get_target : t -> t
205
+
206
+ val set_target : t -> t -> unit
207
+
208
+ val get_table : t -> string
209
+
210
+ val set_table : t -> string -> unit
211
+
212
+ val get_num_operands : t -> int
213
+
214
+ val get_operand_at : t -> int -> t
215
+
216
+ val set_operand_at : t -> int -> t -> unit
217
+
218
+ val append_operand : t -> t -> int
219
+
220
+ val insert_operand_at : t -> int -> t -> unit
221
+
222
+ val remove_operand_at : t -> int -> t
223
+
224
+ val is_return : t -> bool
225
+
226
+ val set_return : t -> bool -> unit
227
+ end
228
+
229
+ module Local_get : sig
230
+ val make : Module.t -> int -> Type.t -> t
231
+ end
232
+
233
+ module Local_set : sig
234
+ val make : Module.t -> int -> t -> t
235
+
236
+ val get_value : t -> t
237
+
238
+ val set_value : t -> t -> unit
239
+ end
240
+
241
+ module Local_tee : sig
242
+ val make : Module.t -> int -> t -> Type.t -> t
243
+ end
244
+
245
+ module Global_get : sig
246
+ val make : Module.t -> string -> Type.t -> t
247
+
248
+ val get_name : t -> string
249
+
250
+ val set_name : t -> string -> unit
251
+ end
252
+
253
+ module Global_set : sig
254
+ val make : Module.t -> string -> t -> t
255
+
256
+ val get_name : t -> string
257
+
258
+ val set_name : t -> string -> unit
259
+
260
+ val get_value : t -> t
261
+
262
+ val set_value : t -> t -> unit
263
+ end
264
+
265
+ module Load : sig
266
+ val make : Module.t -> int -> ?signed:bool -> int -> int -> Type.t -> t -> t
267
+
268
+ val get_ptr : t -> t
269
+
270
+ val set_ptr : t -> t -> unit
271
+ end
272
+
273
+ module Store : sig
274
+ val make : Module.t -> int -> int -> int -> t -> t -> Type.t -> t
275
+
276
+ val get_ptr : t -> t
277
+
278
+ val set_ptr : t -> t -> unit
279
+
280
+ val get_value : t -> t
281
+
282
+ val set_value : t -> t -> unit
283
+ end
284
+
285
+ module Const : sig
286
+ val make : Module.t -> Literal.t -> t
287
+ end
288
+
289
+ module Unary : sig
290
+ val make : Module.t -> Op.t -> t -> t
291
+
292
+ val get_value : t -> t
293
+
294
+ val set_value : t -> t -> unit
295
+ end
296
+
297
+ module Binary : sig
298
+ val make : Module.t -> Op.t -> t -> t -> t
299
+
300
+ val get_left : t -> t
301
+
302
+ val set_left : t -> t -> unit
303
+
304
+ val get_right : t -> t
305
+
306
+ val set_right : t -> t -> unit
307
+ end
308
+
309
+ module Select : sig
310
+ val make : Module.t -> t -> t -> t -> t
311
+
312
+ val get_if_true : t -> t
313
+
314
+ val set_if_true : t -> t -> unit
315
+
316
+ val get_if_false : t -> t
317
+
318
+ val set_if_false : t -> t -> unit
319
+
320
+ val get_condition : t -> t
321
+
322
+ val set_condition : t -> t -> unit
323
+ end
324
+
325
+ module Drop : sig
326
+ val make : Module.t -> t -> t
327
+
328
+ val get_value : t -> t
329
+
330
+ val set_value : t -> t -> unit
331
+ end
332
+
333
+ module Return : sig
334
+ val make : Module.t -> t -> t
335
+
336
+ val get_value : t -> t
337
+
338
+ val set_value : t -> t -> unit
339
+ end
340
+
341
+ module Memory_size : sig
342
+ val make : Module.t -> t
343
+ end
344
+
345
+ module Memory_grow : sig
346
+ val make : Module.t -> t -> t
347
+
348
+ val get_delta : t -> t
349
+
350
+ val set_delta : t -> t -> unit
351
+ end
352
+
353
+ module Memory_copy : sig
354
+ val make : Module.t -> t -> t -> t -> t
355
+
356
+ val get_dest : t -> t
357
+
358
+ val set_dest : t -> t -> unit
359
+
360
+ val get_source : t -> t
361
+
362
+ val set_source : t -> t -> unit
363
+
364
+ val get_size : t -> t
365
+
366
+ val set_size : t -> t -> unit
367
+ end
368
+
369
+ module Memory_fill : sig
370
+ val make : Module.t -> t -> t -> t -> t
371
+
372
+ val get_dest : t -> t
373
+
374
+ val set_dest : t -> t -> unit
375
+
376
+ val get_value : t -> t
377
+
378
+ val set_value : t -> t -> unit
379
+
380
+ val get_size : t -> t
381
+
382
+ val set_size : t -> t -> unit
383
+ end
384
+
385
+ module Tuple_make : sig
386
+ val make : Module.t -> t list -> t
387
+
388
+ val get_num_operands : t -> int
389
+
390
+ val get_operand_at : t -> int -> t
391
+
392
+ val set_operand_at : t -> int -> t -> unit
393
+
394
+ val append_operand : t -> t -> int
395
+
396
+ val insert_operand_at : t -> int -> t -> unit
397
+
398
+ val remove_operand_at : t -> int -> t
399
+ end
400
+
401
+ module Tuple_extract : sig
402
+ val make : Module.t -> t -> int -> t
403
+
404
+ val get_tuple : t -> t
405
+
406
+ val set_tuple : t -> t -> unit
407
+ end
408
+
409
+ module Nop : sig
410
+ val make : Module.t -> t
411
+ end
412
+
413
+ module Unreachable : sig
414
+ val make : Module.t -> t
415
+ end
416
+
417
+ module Pop : sig
418
+ val make : Module.t -> Type.t -> t
419
+ end
420
+
421
+ module Null : sig
422
+ val make : unit -> t
423
+ end
@@ -9,6 +9,22 @@ val set_debug_location : t -> Expression.t -> int -> int -> int -> unit
9
9
 
10
10
  val get_function : Module.t -> string -> t
11
11
 
12
+ val get_function_by_index : Module.t -> int -> t
13
+
12
14
  val remove_function : Module.t -> string -> unit
13
15
 
14
16
  val get_num_functions : Module.t -> int
17
+
18
+ val get_name : t -> string
19
+
20
+ val get_params : t -> Type.t
21
+
22
+ val get_results : t -> Type.t
23
+
24
+ val get_num_vars : t -> int
25
+
26
+ val get_var : t -> int -> Type.t
27
+
28
+ val get_body : t -> Expression.t
29
+
30
+ val set_body : t -> Expression.t -> unit
@@ -0,0 +1,19 @@
1
+ type t
2
+
3
+ val add_global : Module.t -> string -> Type.t -> bool -> Expression.t -> t
4
+
5
+ val get_global : Module.t -> string -> t
6
+
7
+ val remove_global : Module.t -> string -> unit
8
+
9
+ val get_num_globals : Module.t -> int
10
+
11
+ val get_global_by_index : Module.t -> int -> t
12
+
13
+ val get_name : t -> string
14
+
15
+ val get_type : t -> Type.t
16
+
17
+ val is_mutable : t -> bool
18
+
19
+ val get_init_expr : t -> Expression.t
@@ -7,3 +7,11 @@ val add_memory_import : Module.t -> string -> string -> string -> bool -> unit
7
7
 
8
8
  val add_global_import :
9
9
  Module.t -> string -> string -> string -> Type.t -> bool -> unit
10
+
11
+ val function_import_get_module : Function.t -> string
12
+
13
+ val global_import_get_module : Global.t -> string
14
+
15
+ val function_import_get_base : Function.t -> string
16
+
17
+ val global_import_get_base : Global.t -> string