@grain/binaryen.ml 0.9.0 → 0.11.1

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 (135) hide show
  1. binaryen-archive/.gitignore +1 -0
  2. binaryen-archive/CHANGELOG.md +73 -0
  3. binaryen-archive/README.md +27 -3
  4. binaryen-archive/binaryen.opam +8 -8
  5. binaryen-archive/esy.lock/index.json +537 -460
  6. binaryen-archive/esy.lock/opam/{base.v0.14.1 → base.v0.14.2}/opam +4 -4
  7. binaryen-archive/esy.lock/opam/biniou.1.2.1/opam +1 -1
  8. binaryen-archive/esy.lock/opam/{cppo.1.6.7 → cppo.1.6.8}/opam +4 -6
  9. binaryen-archive/esy.lock/opam/{csexp.1.4.0 → csexp.1.5.1}/opam +11 -9
  10. binaryen-archive/esy.lock/opam/{dune-build-info.2.8.2 → dune-build-info.2.9.1}/opam +5 -5
  11. binaryen-archive/esy.lock/opam/{dune-configurator.2.8.2 → dune-configurator.2.9.1}/opam +5 -5
  12. binaryen-archive/esy.lock/opam/{dune.2.8.2 → dune.2.9.1}/opam +4 -4
  13. binaryen-archive/esy.lock/opam/easy-format.1.3.2/opam +1 -1
  14. binaryen-archive/esy.lock/opam/{fix.20201120 → fix.20211231}/opam +7 -5
  15. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.3.11.0/opam +54 -0
  16. binaryen-archive/esy.lock/opam/js_of_ocaml-ppx.3.11.0/opam +44 -0
  17. binaryen-archive/esy.lock/opam/js_of_ocaml.3.11.0/opam +45 -0
  18. binaryen-archive/esy.lock/opam/{menhir.20201216 → menhir.20211128}/opam +8 -6
  19. binaryen-archive/esy.lock/opam/{menhirLib.20201216 → menhirLib.20211128}/opam +8 -6
  20. binaryen-archive/esy.lock/opam/{menhirSdk.20201216 → menhirSdk.20211128}/opam +8 -6
  21. binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.12.4/opam +39 -0
  22. binaryen-archive/esy.lock/opam/{ocaml-lsp-server.1.4.0 → ocaml-lsp-server.1.9.0}/opam +15 -12
  23. binaryen-archive/esy.lock/opam/{ocaml-migrate-parsetree.2.1.0 → ocaml-migrate-parsetree.2.3.0}/opam +13 -10
  24. binaryen-archive/esy.lock/opam/ocaml-version.3.4.0/opam +49 -0
  25. binaryen-archive/esy.lock/opam/ocamlbuild.0.14.0/opam +1 -1
  26. binaryen-archive/esy.lock/opam/{ocamlfind.1.8.1 → ocamlfind.1.9.1}/opam +19 -39
  27. binaryen-archive/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam +40 -0
  28. binaryen-archive/esy.lock/opam/ocamlformat.0.18.0/opam +56 -0
  29. binaryen-archive/esy.lock/opam/{odoc.1.5.2 → odoc.1.5.3}/opam +12 -12
  30. binaryen-archive/esy.lock/opam/pp.1.1.2/opam +58 -0
  31. binaryen-archive/esy.lock/opam/ppx_derivers.1.2.1/opam +1 -1
  32. binaryen-archive/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam +2 -2
  33. binaryen-archive/esy.lock/opam/{ppxlib.0.21.0 → ppxlib.0.22.2}/opam +40 -32
  34. binaryen-archive/esy.lock/opam/{re.1.9.0 → re.1.10.3}/opam +8 -4
  35. binaryen-archive/esy.lock/opam/result.1.5/opam +2 -2
  36. binaryen-archive/esy.lock/opam/sexplib0.v0.14.0/opam +2 -2
  37. binaryen-archive/esy.lock/opam/spawn.v0.15.0/opam +56 -0
  38. binaryen-archive/esy.lock/opam/stdio.v0.14.0/opam +2 -2
  39. binaryen-archive/esy.lock/opam/{topkg.1.0.3 → topkg.1.0.4}/opam +18 -22
  40. binaryen-archive/esy.lock/opam/tyxml.4.5.0/opam +42 -0
  41. binaryen-archive/esy.lock/opam/uucp.14.0.0/opam +41 -0
  42. binaryen-archive/esy.lock/opam/{uuseg.13.0.0 → uuseg.14.0.0}/opam +22 -28
  43. binaryen-archive/esy.lock/opam/yojson.1.7.0/opam +1 -1
  44. binaryen-archive/esy.lock/overrides/{opam__s__ocamlfind_opam__c__1.8.1_opam_override/files/findlib-1.8.1.patch → opam__s__ocamlfind_opam__c__1.9.1_opam_override/files/findlib-1.9.1.patch} +0 -0
  45. binaryen-archive/esy.lock/overrides/{opam__s__ocamlfind_opam__c__1.8.1_opam_override → opam__s__ocamlfind_opam__c__1.9.1_opam_override}/package.json +1 -1
  46. binaryen-archive/js/binaryen.es5.js +5 -0
  47. binaryen-archive/js/dune +1 -6
  48. binaryen-archive/js/element_segment.ml +33 -0
  49. binaryen-archive/js/export.ml +37 -0
  50. binaryen-archive/js/expression.ml +935 -177
  51. binaryen-archive/js/function.ml +31 -0
  52. binaryen-archive/js/global.ml +29 -0
  53. binaryen-archive/js/import.ml +24 -0
  54. binaryen-archive/js/literal.ml +8 -4
  55. binaryen-archive/js/module.ml +42 -46
  56. binaryen-archive/js/op.ml +9 -78
  57. binaryen-archive/js/settings.ml +60 -0
  58. binaryen-archive/js/table.ml +20 -3
  59. binaryen-archive/js/type.ml +3 -0
  60. binaryen-archive/package.json +14 -20
  61. binaryen-archive/src/binaryen_stubs_exports.c +78 -0
  62. binaryen-archive/src/binaryen_stubs_expressions.c +1300 -0
  63. binaryen-archive/src/binaryen_stubs_features.c +7 -0
  64. binaryen-archive/src/binaryen_stubs_functions.c +78 -0
  65. binaryen-archive/src/binaryen_stubs_globals.c +63 -0
  66. binaryen-archive/src/binaryen_stubs_imports.c +29 -0
  67. binaryen-archive/src/binaryen_stubs_memory.c +1 -1
  68. binaryen-archive/src/binaryen_stubs_modules.c +0 -122
  69. binaryen-archive/src/binaryen_stubs_ops.c +19 -173
  70. binaryen-archive/src/binaryen_stubs_settings.c +145 -0
  71. binaryen-archive/src/binaryen_stubs_tables.c +121 -7
  72. binaryen-archive/src/binaryen_stubs_types.c +18 -0
  73. binaryen-archive/src/dune +5 -44
  74. binaryen-archive/src/element_segment.ml +13 -0
  75. binaryen-archive/src/export.ml +33 -0
  76. binaryen-archive/src/expression.ml +805 -76
  77. binaryen-archive/src/function.ml +18 -0
  78. binaryen-archive/src/global.ml +14 -0
  79. binaryen-archive/src/import.ml +12 -0
  80. binaryen-archive/src/literal.ml +2 -2
  81. binaryen-archive/src/module.ml +64 -38
  82. binaryen-archive/src/ocaml_helpers.c +0 -8
  83. binaryen-archive/src/ocaml_helpers.h +2 -3
  84. binaryen-archive/src/op.ml +18 -131
  85. binaryen-archive/src/settings.ml +45 -0
  86. binaryen-archive/src/table.ml +26 -4
  87. binaryen-archive/src/type.ml +2 -0
  88. binaryen-archive/test/config/dune +8 -0
  89. binaryen-archive/test/config/ocamlopt_flags.ml +16 -0
  90. binaryen-archive/test/dune +4 -0
  91. binaryen-archive/test/test.expected +38 -3
  92. binaryen-archive/test/test.ml +90 -18
  93. binaryen-archive/virtual/dune +2 -2
  94. binaryen-archive/virtual/element_segment.mli +11 -0
  95. binaryen-archive/virtual/export.mli +22 -0
  96. binaryen-archive/virtual/expression.mli +389 -34
  97. binaryen-archive/virtual/function.mli +16 -0
  98. binaryen-archive/virtual/global.mli +12 -0
  99. binaryen-archive/virtual/import.mli +8 -0
  100. binaryen-archive/virtual/literal.mli +2 -2
  101. binaryen-archive/virtual/module.mli +25 -27
  102. binaryen-archive/virtual/op.mli +9 -53
  103. binaryen-archive/virtual/settings.mli +35 -0
  104. binaryen-archive/virtual/table.mli +19 -2
  105. binaryen-archive/virtual/type.mli +2 -0
  106. binaryen-archive/esy.lock/opam/conf-m4.1/opam +0 -22
  107. binaryen-archive/esy.lock/opam/dot-merlin-reader.4.1/opam +0 -30
  108. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.3.9.1/opam +0 -40
  109. binaryen-archive/esy.lock/opam/js_of_ocaml-ppx.3.9.0/opam +0 -30
  110. binaryen-archive/esy.lock/opam/js_of_ocaml.3.9.0/opam +0 -31
  111. binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.12.3/opam +0 -29
  112. binaryen-archive/esy.lock/opam/ocamlfind.1.8.1/files/ocaml-stub +0 -4
  113. binaryen-archive/esy.lock/opam/ocamlfind.1.8.1/files/ocamlfind.install +0 -6
  114. binaryen-archive/esy.lock/opam/ocamlformat.0.15.1/opam +0 -41
  115. binaryen-archive/esy.lock/opam/tyxml.4.4.0/opam +0 -47
  116. binaryen-archive/esy.lock/opam/uucp.13.0.0/opam +0 -44
  117. binaryen-archive/esy.lock/overrides/opam__s__conf_m4_opam__c__1_opam_override/package.json +0 -6
  118. binaryen-archive/js/features.ml +0 -27
  119. binaryen-archive/js/function_table.ml +0 -13
  120. binaryen-archive/src/binaryen_stubs_function_tables.c +0 -25
  121. binaryen-archive/src/config/dune +0 -8
  122. binaryen-archive/src/config/library_flags.ml +0 -16
  123. binaryen-archive/src/features.ml +0 -49
  124. binaryen-archive/src/function_table.ml +0 -6
  125. binaryen-archive/vendor/binaryen-c.h +0 -2647
  126. binaryen-archive/vendor/js/index.es5.js +0 -5
  127. binaryen-archive/vendor/linux/libbinaryen.a +0 -0
  128. binaryen-archive/vendor/linux/libbinaryen.so +0 -0
  129. binaryen-archive/vendor/macosx/libbinaryen.a +0 -0
  130. binaryen-archive/vendor/macosx/libbinaryen.dylib +0 -0
  131. binaryen-archive/vendor/mingw64/libbinaryen.a +0 -0
  132. binaryen-archive/vendor/mingw64/libbinaryen.dll +0 -0
  133. binaryen-archive/vendor/wasm-delegations.h +0 -85
  134. binaryen-archive/virtual/features.mli +0 -23
  135. binaryen-archive/virtual/function_table.mli +0 -4
@@ -1,11 +1,17 @@
1
1
  (module
2
2
  (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
3
3
  (type $none_=>_none (func))
4
+ (type $externref_=>_i32 (func (param externref) (result i32)))
5
+ (type $externref_i32_i32_=>_i32 (func (param externref i32 i32) (result i32)))
6
+ (import "future-wasi" "write" (func $write (param externref i32 i32) (result i32)))
7
+ (global $max_int64 i64 (i64.const 9223372036854775807))
8
+ (global $test_float64_bits f64 (f64.const 1.23))
4
9
  (memory $0 1)
5
10
  (table $table 1 1 funcref)
6
- (elem (i32.const 0) $adder)
11
+ (elem $elem (i32.const 0) $adder)
7
12
  (export "adder" (func $adder))
8
13
  (export "memory" (memory $0))
14
+ (export "hello" (func $hello))
9
15
  (start $start)
10
16
  (func $adder (param $0 i32) (param $1 i32) (result i32)
11
17
  (block $add (result i32)
@@ -27,22 +33,33 @@
27
33
  )
28
34
  (func $start
29
35
  (drop
30
- (call_indirect (type $i32_i32_=>_i32)
36
+ (call_indirect $table (type $i32_i32_=>_i32)
31
37
  (i32.const 3)
32
38
  (i32.const 5)
33
39
  (i32.const 0)
34
40
  )
35
41
  )
36
42
  )
43
+ (func $hello (param $0 externref) (result i32)
44
+ (call $write
45
+ (local.get $0)
46
+ (i32.const 0)
47
+ (i32.const 1)
48
+ )
49
+ )
37
50
  )
38
51
  (module
39
52
  (type $none_=>_none (func))
53
+ (type $externref_=>_i32 (func (param externref) (result i32)))
40
54
  (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
55
+ (type $externref_i32_i32_=>_i32 (func (param externref i32 i32) (result i32)))
56
+ (import "future-wasi" "write" (func $write (param externref i32 i32) (result i32)))
41
57
  (memory $0 1)
42
58
  (table $table 1 1 funcref)
43
- (elem (i32.const 0) $adder)
59
+ (elem $elem (i32.const 0) $adder)
44
60
  (export "adder" (func $adder))
45
61
  (export "memory" (memory $0))
62
+ (export "hello" (func $hello))
46
63
  (start $start)
47
64
  (func $adder (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32)
48
65
  (i32.add
@@ -64,15 +81,26 @@
64
81
  )
65
82
  )
66
83
  )
84
+ (func $hello (; has Stack IR ;) (param $0 externref) (result i32)
85
+ (call $write
86
+ (local.get $0)
87
+ (i32.const 0)
88
+ (i32.const 1)
89
+ )
90
+ )
67
91
  )
68
92
  (module
69
93
  (type $none_=>_none (func))
94
+ (type $externref_=>_i32 (func (param externref) (result i32)))
70
95
  (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
96
+ (type $externref_i32_i32_=>_i32 (func (param externref i32 i32) (result i32)))
97
+ (import "future-wasi" "write" (func $fimport$0 (param externref i32 i32) (result i32)))
71
98
  (memory $0 1)
72
99
  (table $0 1 1 funcref)
73
100
  (elem (i32.const 0) $0)
74
101
  (export "adder" (func $0))
75
102
  (export "memory" (memory $0))
103
+ (export "hello" (func $2))
76
104
  (start $1)
77
105
  (func $0 (param $0 i32) (param $1 i32) (result i32)
78
106
  (i32.add
@@ -94,4 +122,11 @@
94
122
  )
95
123
  )
96
124
  )
125
+ (func $2 (param $0 externref) (result i32)
126
+ (call $fimport$0
127
+ (local.get $0)
128
+ (i32.const 0)
129
+ (i32.const 1)
130
+ )
131
+ )
97
132
  )
@@ -1,32 +1,61 @@
1
1
  open Binaryen
2
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
+
3
30
  let wasm_mod = Module.create ()
4
31
 
32
+ let _ = Module.set_features wasm_mod [ Module.Feature.all ]
33
+
5
34
  (* Create function type for i32 (i32, i32) *)
6
35
  let params () = Type.create [| Type.int32; Type.int32 |]
7
36
 
8
37
  let results = Type.int32
9
38
 
10
- let x () = Expression.local_get wasm_mod 0 Type.int32
39
+ let x () = Expression.Local_get.make wasm_mod 0 Type.int32
11
40
 
12
- let y () = Expression.local_get wasm_mod 1 Type.int32
41
+ let y () = Expression.Local_get.make wasm_mod 1 Type.int32
13
42
 
14
- let load = Expression.load wasm_mod 1 ~signed:true 0 0 Type.int32 (y ())
43
+ let load = Expression.Load.make wasm_mod 1 ~signed:true 0 0 Type.int32 (y ())
15
44
 
16
45
  let select =
17
- Expression.select wasm_mod
18
- (Expression.const wasm_mod (Literal.int32 1l))
46
+ Expression.Select.make wasm_mod
47
+ (Expression.Const.make wasm_mod (Literal.int32 1l))
19
48
  (x ()) load
20
49
 
21
- let bin = Expression.binary wasm_mod Op.add_int32 select (y ())
50
+ let bin = Expression.Binary.make wasm_mod Op.add_int32 select (y ())
22
51
 
23
52
  let add =
24
- Expression.block wasm_mod ~return_type:Type.int32 "add"
53
+ Expression.Block.make wasm_mod ~return_type:Type.int32 "add"
25
54
  [
26
- Expression.if_ wasm_mod
27
- (Expression.const wasm_mod (Literal.int32 0l))
28
- (Expression.unreachable wasm_mod)
29
- (Expression.null ());
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 ());
30
59
  bin;
31
60
  ]
32
61
 
@@ -34,42 +63,85 @@ let add =
34
63
  let adder = Function.add_function wasm_mod "adder" (params ()) results [||] add
35
64
 
36
65
  let call_adder =
37
- Expression.call_indirect wasm_mod "table"
38
- (Expression.const wasm_mod (Literal.int32 0l))
66
+ Expression.Call_indirect.make wasm_mod "table"
67
+ (Expression.Const.make wasm_mod (Literal.int32 0l))
39
68
  [
40
- Expression.const wasm_mod (Literal.int32 3l);
41
- Expression.const wasm_mod (Literal.int32 5l);
69
+ Expression.Const.make wasm_mod (Literal.int32 3l);
70
+ Expression.Const.make wasm_mod (Literal.int32 5l);
42
71
  ]
43
72
  (params ()) Type.int32
44
73
 
45
74
  let start =
46
75
  Function.add_function wasm_mod "start" Type.none Type.none [||]
47
- (Expression.drop wasm_mod call_adder)
76
+ (Expression.Drop.make wasm_mod call_adder)
48
77
 
49
78
  let _ = Export.add_function_export wasm_mod "adder" "adder"
50
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
+
51
90
  let _ =
52
- Table.add_table wasm_mod "table" 1 1 [ "adder" ]
53
- (Expression.const wasm_mod (Literal.int32 0l))
91
+ Table.add_active_element_segment wasm_mod "table" "elem" [ "adder" ]
92
+ (Expression.Const.make wasm_mod (Literal.int32 0l))
54
93
 
55
94
  let _ = Function.set_start wasm_mod start
56
95
 
57
96
  let _ = Memory.set_memory wasm_mod 1 Memory.unlimited "memory" [] false
58
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
+
59
123
  let _ = Module.print wasm_mod
60
124
 
125
+ (* 2. Optimize, then print the module *)
126
+
61
127
  let _ = Module.optimize wasm_mod
62
128
 
63
129
  let _ = Module.print wasm_mod
64
130
 
131
+ (* 3. Copy previous module bytes into new module, validate, and print *)
132
+
65
133
  let byts, _ = Module.write wasm_mod None
66
134
 
67
135
  let new_mod = Module.read byts
68
136
 
137
+ let _ = Module.set_features new_mod [ Module.Feature.all ]
138
+
69
139
  let _ = Module.validate new_mod
70
140
 
71
141
  let _ = Module.print new_mod
72
142
 
143
+ (* Dispose the modules 👋 *)
144
+
73
145
  let _ = Module.dispose wasm_mod
74
146
 
75
147
  let _ = Module.dispose new_mod
@@ -1,6 +1,6 @@
1
1
  (library
2
2
  (name binaryen)
3
3
  (public_name binaryen)
4
- (virtual_modules export expression features function function_table table
5
- global import literal memory module op type)
4
+ (virtual_modules element_segment export expression function global import
5
+ literal memory module op settings table type)
6
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
@@ -8,4 +8,26 @@ val add_memory_export : Module.t -> string -> string -> t
8
8
 
9
9
  val add_global_export : Module.t -> string -> string -> t
10
10
 
11
+ val get_export : Module.t -> string -> t
12
+
11
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