@grain/binaryen.ml 0.25.0 → 0.27.0
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.
- binaryen-archive/CHANGELOG.md +30 -0
- binaryen-archive/README.md +3 -2
- binaryen-archive/binaryen.opam +3 -3
- binaryen-archive/dune +2 -0
- binaryen-archive/esy.lock/index.json +630 -577
- binaryen-archive/esy.lock/opam/{base.v0.16.4 → base.v0.17.3}/opam +8 -6
- binaryen-archive/esy.lock/opam/{chrome-trace.3.18.2 → chrome-trace.3.20.2}/opam +5 -5
- binaryen-archive/esy.lock/opam/{dune-build-info.3.18.2 → dune-build-info.3.20.2}/opam +5 -5
- binaryen-archive/esy.lock/opam/{dune-configurator.3.18.2 → dune-configurator.3.20.2}/opam +5 -5
- binaryen-archive/esy.lock/opam/{dune-rpc.3.18.2 → dune-rpc.3.20.2}/opam +6 -5
- binaryen-archive/esy.lock/opam/{dune.3.18.2 → dune.3.20.2}/opam +8 -7
- binaryen-archive/esy.lock/opam/{dyn.3.18.2 → dyn.3.20.2}/opam +6 -6
- binaryen-archive/esy.lock/opam/{fix.20250428 → fix.20250919}/opam +3 -3
- binaryen-archive/esy.lock/opam/{js_of_ocaml-compiler.5.9.1 → js_of_ocaml-compiler.6.2.0}/opam +10 -10
- binaryen-archive/esy.lock/opam/jsonrpc.1.23.1/opam +50 -0
- binaryen-archive/esy.lock/opam/lsp.1.23.1/opam +60 -0
- binaryen-archive/esy.lock/opam/{menhir.20240715 → menhir.20250912}/opam +3 -3
- binaryen-archive/esy.lock/opam/{menhirCST.20240715 → menhirCST.20250912}/opam +4 -4
- binaryen-archive/esy.lock/opam/{menhirLib.20240715 → menhirLib.20250912}/opam +3 -3
- binaryen-archive/esy.lock/opam/{menhirSdk.20240715 → menhirSdk.20250912}/opam +3 -3
- binaryen-archive/esy.lock/opam/merlin-lib.5.6-503/opam +36 -0
- binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.17.0/opam +28 -0
- binaryen-archive/esy.lock/opam/{ocaml-lsp-server.1.12.4 → ocaml-lsp-server.1.23.1}/opam +24 -12
- binaryen-archive/esy.lock/opam/{ocaml-version.3.5.0 → ocaml-version.4.0.3}/opam +33 -28
- binaryen-archive/esy.lock/opam/ocaml_intrinsics_kernel.v0.17.1/opam +30 -0
- binaryen-archive/esy.lock/opam/ocamlc-loc.3.20.2/opam +45 -0
- binaryen-archive/esy.lock/opam/ocamlformat-lib.0.27.0/opam +68 -0
- binaryen-archive/esy.lock/opam/ocamlformat.0.27.0/opam +59 -0
- binaryen-archive/esy.lock/opam/{ordering.3.18.2 → ordering.3.20.2}/opam +6 -6
- binaryen-archive/esy.lock/opam/{ppx_yojson_conv_lib.v0.16.0 → ppx_yojson_conv_lib.v0.17.0}/opam +5 -4
- binaryen-archive/esy.lock/opam/{ppxlib.0.35.0 → ppxlib.0.37.0}/opam +5 -5
- binaryen-archive/esy.lock/opam/{re.1.12.0 → re.1.14.0}/opam +35 -27
- binaryen-archive/esy.lock/opam/{sedlex.3.4 → sedlex.3.7}/opam +3 -3
- binaryen-archive/esy.lock/opam/{sexplib0.v0.16.0 → sexplib0.v0.17.0}/opam +9 -4
- binaryen-archive/esy.lock/opam/{stdio.v0.16.0 → stdio.v0.17.0}/opam +6 -5
- binaryen-archive/esy.lock/opam/{stdune.3.18.2 → stdune.3.20.2}/opam +6 -6
- binaryen-archive/esy.lock/opam/{topkg.1.0.8 → topkg.1.1.0}/opam +2 -2
- binaryen-archive/esy.lock/opam/{uucp.16.0.0 → uucp.17.0.0}/opam +5 -5
- binaryen-archive/esy.lock/opam/{uuseg.16.0.0 → uuseg.17.0.0}/opam +4 -4
- binaryen-archive/esy.lock/opam/{xdg.3.18.2 → xdg.3.20.2}/opam +6 -5
- binaryen-archive/esy.lock/opam/{yojson.2.2.2 → yojson.3.0.0}/opam +5 -6
- binaryen-archive/package.json +9 -6
- binaryen-archive/src/expression.c +4 -4
- binaryen-archive/src/expression.js +8 -7
- binaryen-archive/src/expression.ml +4 -28
- binaryen-archive/src/expression.mli +6 -6
- binaryen-archive/src/memory.c +30 -24
- binaryen-archive/src/memory.js +17 -11
- binaryen-archive/src/memory.ml +23 -12
- binaryen-archive/src/memory.mli +4 -4
- binaryen-archive/src/module.js +6 -3
- binaryen-archive/test/dune +1 -2
- binaryen-archive/test/test.expected +25 -23
- binaryen-archive/test/test.ml +7 -5
- binaryen-archive/esy.lock/opam/base-bigarray.base/opam +0 -6
- binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.12.4/opam +0 -39
- binaryen-archive/esy.lock/opam/ocamlformat.0.24.1/opam +0 -57
- binaryen-archive/esy.lock/opam/octavius.1.2.2/opam +0 -36
- binaryen-archive/esy.lock/opam/odoc-parser.2.0.0/opam +0 -47
- binaryen-archive/esy.lock/opam/omd.1.3.2/opam +0 -50
- binaryen-archive/esy.lock/opam/result.1.5/opam +0 -25
|
@@ -16,9 +16,8 @@ doc: "https://ocaml.org/p/yojson/latest"
|
|
|
16
16
|
bug-reports: "https://github.com/ocaml-community/yojson/issues"
|
|
17
17
|
depends: [
|
|
18
18
|
"dune" {>= "2.7"}
|
|
19
|
-
"ocaml" {>= "4.
|
|
19
|
+
"ocaml" {>= "4.08"}
|
|
20
20
|
"alcotest" {with-test & >= "0.8.5"}
|
|
21
|
-
"seq" {>= "0.2.2"}
|
|
22
21
|
"odoc" {with-doc}
|
|
23
22
|
]
|
|
24
23
|
build: [
|
|
@@ -38,10 +37,10 @@ build: [
|
|
|
38
37
|
dev-repo: "git+https://github.com/ocaml-community/yojson.git"
|
|
39
38
|
url {
|
|
40
39
|
src:
|
|
41
|
-
"https://github.com/ocaml-community/yojson/releases/download/
|
|
40
|
+
"https://github.com/ocaml-community/yojson/releases/download/3.0.0/yojson-3.0.0.tbz"
|
|
42
41
|
checksum: [
|
|
43
|
-
"sha256=
|
|
44
|
-
"sha512=
|
|
42
|
+
"sha256=99414da7609b92a02474ef4b49ecda15edc8cbba5229341b124e7e4695c39610"
|
|
43
|
+
"sha512=896d0ea829a36ccadba6628800369c1a3ab9e7c64dbda8b76331889c9db481cd64e137f467481ae80a8dd5fca45d748bfa71f58641806cc1bb1a007f8291789f"
|
|
45
44
|
]
|
|
46
45
|
}
|
|
47
|
-
x-commit-hash: "
|
|
46
|
+
x-commit-hash: "b2193e8e0c88c6501710d08b836b3219673383f3"
|
binaryen-archive/package.json
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grain/binaryen.ml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "OCaml bindings for Binaryen.",
|
|
5
5
|
"author": "Oscar Spencer <oscar@grain-lang.org>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
+
"installConfig": {
|
|
8
|
+
"pnp": false
|
|
9
|
+
},
|
|
7
10
|
"dependencies": {
|
|
8
|
-
"ocaml": ">= 4.13.0 < 5.
|
|
9
|
-
"@grain/libbinaryen": "
|
|
11
|
+
"ocaml": ">= 4.13.0 < 5.4.0",
|
|
12
|
+
"@grain/libbinaryen": "117.0.0-b",
|
|
10
13
|
"@opam/dune": ">= 3.0.0",
|
|
11
14
|
"@opam/dune-configurator": ">= 3.0.0"
|
|
12
15
|
},
|
|
13
16
|
"devDependencies": {
|
|
14
|
-
"@opam/js_of_ocaml-compiler": ">=
|
|
15
|
-
"@opam/ocamlformat": "0.
|
|
16
|
-
"@opam/ocaml-lsp-server": ">= 1.9.1 <
|
|
17
|
+
"@opam/js_of_ocaml-compiler": ">= 6.0.0 < 7.0.0",
|
|
18
|
+
"@opam/ocamlformat": "0.27.0",
|
|
19
|
+
"@opam/ocaml-lsp-server": ">= 1.9.1 < 2.0.0"
|
|
17
20
|
},
|
|
18
21
|
"resolutions": {
|
|
19
22
|
"@opam/ocp-indent": "1.7.0"
|
|
@@ -442,11 +442,11 @@ caml_binaryen_pop(value _module, value _ty) {
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
CAMLprim value
|
|
445
|
-
|
|
445
|
+
caml_binaryen_ref_i31(value _module, value _val) {
|
|
446
446
|
CAMLparam2(_module, _val);
|
|
447
447
|
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
|
|
448
448
|
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
|
|
449
|
-
BinaryenExpressionRef exp =
|
|
449
|
+
BinaryenExpressionRef exp = BinaryenRefI31(module, val);
|
|
450
450
|
CAMLreturn(alloc_BinaryenExpressionRef(exp));
|
|
451
451
|
}
|
|
452
452
|
|
|
@@ -717,9 +717,9 @@ caml_binaryen_expression_id_tuple_extract(value unit) {
|
|
|
717
717
|
CAMLreturn(Val_int(BinaryenTupleExtractId()));
|
|
718
718
|
}
|
|
719
719
|
CAMLprim value
|
|
720
|
-
|
|
720
|
+
caml_binaryen_expression_id_ref_i31(value unit) {
|
|
721
721
|
CAMLparam1(unit);
|
|
722
|
-
CAMLreturn(Val_int(
|
|
722
|
+
CAMLreturn(Val_int(BinaryenRefI31Id()));
|
|
723
723
|
}
|
|
724
724
|
CAMLprim value
|
|
725
725
|
caml_binaryen_expression_id_i31_get(value unit) {
|
|
@@ -542,9 +542,9 @@ function caml_binaryen_pop(wasm_mod, typ) {
|
|
|
542
542
|
return Binaryen._BinaryenPop(wasm_mod, typ);
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
//Provides:
|
|
546
|
-
function
|
|
547
|
-
return wasm_mod.i31
|
|
545
|
+
//Provides: caml_binaryen_ref_i31
|
|
546
|
+
function caml_binaryen_ref_i31(wasm_mod, typ) {
|
|
547
|
+
return wasm_mod.ref.i31(typ);
|
|
548
548
|
}
|
|
549
549
|
|
|
550
550
|
//Provides: caml_binaryen_i31_get
|
|
@@ -812,10 +812,10 @@ function caml_binaryen_expression_id_tuple_make() {
|
|
|
812
812
|
function caml_binaryen_expression_id_tuple_extract() {
|
|
813
813
|
return Binaryen.TupleExtractId;
|
|
814
814
|
}
|
|
815
|
-
//Provides:
|
|
815
|
+
//Provides: caml_binaryen_expression_id_ref_i31
|
|
816
816
|
//Requires: Binaryen
|
|
817
|
-
function
|
|
818
|
-
return Binaryen.
|
|
817
|
+
function caml_binaryen_expression_id_ref_i31() {
|
|
818
|
+
return Binaryen.RefI31Id;
|
|
819
819
|
}
|
|
820
820
|
//Provides: caml_binaryen_expression_id_i31_get
|
|
821
821
|
//Requires: Binaryen
|
|
@@ -882,11 +882,12 @@ function caml_binaryen_expression_id_array_len() {
|
|
|
882
882
|
|
|
883
883
|
//Provides: caml_binaryen_expression_print
|
|
884
884
|
//Requires: Binaryen
|
|
885
|
+
//Requires: caml_sys_fds
|
|
885
886
|
//Requires: caml_string_of_jsstring
|
|
886
887
|
//Requires: caml_ml_output, caml_ml_string_length
|
|
887
888
|
function caml_binaryen_expression_print(expr) {
|
|
888
889
|
var text = Binaryen.emitText(expr);
|
|
889
|
-
var chanid = 1; // stdout
|
|
890
|
+
var chanid = caml_sys_fds[1].chanid; // stdout
|
|
890
891
|
var s = caml_string_of_jsstring(text);
|
|
891
892
|
caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
|
|
892
893
|
}
|
|
@@ -285,9 +285,9 @@ external id_tuple_extract : unit -> int
|
|
|
285
285
|
|
|
286
286
|
let id_tuple_extract = id_tuple_extract ()
|
|
287
287
|
|
|
288
|
-
external
|
|
288
|
+
external id_ref_i31 : unit -> int = "caml_binaryen_expression_id_ref_i31"
|
|
289
289
|
|
|
290
|
-
let
|
|
290
|
+
let id_ref_i31 = id_ref_i31 ()
|
|
291
291
|
|
|
292
292
|
external id_i31_get : unit -> int = "caml_binaryen_expression_id_i31_get"
|
|
293
293
|
|
|
@@ -394,7 +394,7 @@ let get_kind expr =
|
|
|
394
394
|
| n when n = id_rethrow -> Rethrow
|
|
395
395
|
| n when n = id_tuple_make -> TupleMake
|
|
396
396
|
| n when n = id_tuple_extract -> TupleExtract
|
|
397
|
-
| n when n =
|
|
397
|
+
| n when n = id_ref_i31 -> I31New
|
|
398
398
|
| n when n = id_i31_get -> I31Get
|
|
399
399
|
| n when n = id_call_ref -> CallRef
|
|
400
400
|
| n when n = id_ref_test -> RefTest
|
|
@@ -706,22 +706,9 @@ module Memory_init = struct
|
|
|
706
706
|
external make : Module.t -> string -> t -> t -> t -> string -> t
|
|
707
707
|
= "caml_binaryen_memory_init__bytecode" "caml_binaryen_memory_init"
|
|
708
708
|
(** Module, segment, destination, offset, size, memory_name *)
|
|
709
|
-
|
|
710
|
-
(* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
|
|
711
|
-
let make wasm_mod segment dest offset size memory_name =
|
|
712
|
-
make wasm_mod (string_of_int segment) dest offset size memory_name
|
|
713
|
-
|
|
714
709
|
external get_segment : t -> string = "caml_binaryen_memory_init_get_segment"
|
|
715
|
-
|
|
716
|
-
(* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
|
|
717
|
-
let get_segment expr = int_of_string (get_segment expr)
|
|
718
|
-
|
|
719
710
|
external set_segment : t -> string -> unit
|
|
720
711
|
= "caml_binaryen_memory_init_set_segment"
|
|
721
|
-
|
|
722
|
-
(* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
|
|
723
|
-
let set_segment expr segment = set_segment expr (string_of_int segment)
|
|
724
|
-
|
|
725
712
|
external get_dest : t -> t = "caml_binaryen_memory_init_get_dest"
|
|
726
713
|
external set_dest : t -> t -> unit = "caml_binaryen_memory_init_set_dest"
|
|
727
714
|
external get_offset : t -> t = "caml_binaryen_memory_init_get_offset"
|
|
@@ -733,20 +720,9 @@ end
|
|
|
733
720
|
module Data_drop = struct
|
|
734
721
|
external make : Module.t -> string -> t = "caml_binaryen_data_drop"
|
|
735
722
|
(** Module, segment. *)
|
|
736
|
-
|
|
737
|
-
(* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
|
|
738
|
-
let make wasm_mod segment = make wasm_mod (string_of_int segment)
|
|
739
|
-
|
|
740
723
|
external get_segment : t -> string = "caml_binaryen_data_drop_get_segment"
|
|
741
|
-
|
|
742
|
-
(* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
|
|
743
|
-
let get_segment expr = int_of_string (get_segment expr)
|
|
744
|
-
|
|
745
724
|
external set_segment : t -> string -> unit
|
|
746
725
|
= "caml_binaryen_data_drop_set_segment"
|
|
747
|
-
|
|
748
|
-
(* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
|
|
749
|
-
let set_segment expr segment = set_segment expr (string_of_int segment)
|
|
750
726
|
end
|
|
751
727
|
|
|
752
728
|
module Memory_copy = struct
|
|
@@ -820,7 +796,7 @@ module Pop = struct
|
|
|
820
796
|
end
|
|
821
797
|
|
|
822
798
|
module I31 = struct
|
|
823
|
-
external make : Module.t -> t -> t = "
|
|
799
|
+
external make : Module.t -> t -> t = "caml_binaryen_ref_i31"
|
|
824
800
|
(** Module, value *)
|
|
825
801
|
|
|
826
802
|
external get : Module.t -> t -> bool -> t = "caml_binaryen_i31_get"
|
|
@@ -256,9 +256,9 @@ module Memory_grow : sig
|
|
|
256
256
|
end
|
|
257
257
|
|
|
258
258
|
module Memory_init : sig
|
|
259
|
-
val make : Module.t ->
|
|
260
|
-
val get_segment : t ->
|
|
261
|
-
val set_segment : t ->
|
|
259
|
+
val make : Module.t -> string -> t -> t -> t -> string -> t
|
|
260
|
+
val get_segment : t -> string
|
|
261
|
+
val set_segment : t -> string -> unit
|
|
262
262
|
val get_dest : t -> t
|
|
263
263
|
val set_dest : t -> t -> unit
|
|
264
264
|
val get_offset : t -> t
|
|
@@ -268,9 +268,9 @@ module Memory_init : sig
|
|
|
268
268
|
end
|
|
269
269
|
|
|
270
270
|
module Data_drop : sig
|
|
271
|
-
val make : Module.t ->
|
|
272
|
-
val get_segment : t ->
|
|
273
|
-
val set_segment : t ->
|
|
271
|
+
val make : Module.t -> string -> t
|
|
272
|
+
val get_segment : t -> string
|
|
273
|
+
val set_segment : t -> string -> unit
|
|
274
274
|
end
|
|
275
275
|
|
|
276
276
|
module Memory_copy : sig
|
binaryen-archive/src/memory.c
CHANGED
|
@@ -8,19 +8,25 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
CAMLprim value
|
|
11
|
-
caml_binaryen_set_memory(value _module, value _initial, value _maximum, value _exportName, value
|
|
12
|
-
CAMLparam5(_module, _initial, _maximum, _exportName,
|
|
13
|
-
CAMLxparam5(_segmentPassive, _segmentOffsets, _segmentSizes, _shared
|
|
14
|
-
|
|
11
|
+
caml_binaryen_set_memory(value _module, value _initial, value _maximum, value _exportName, value _segment_names, value _segment_data, value _segmentPassive, value _segmentOffsets, value _segmentSizes, value _shared, value _memory64, value _memoryName) {
|
|
12
|
+
CAMLparam5(_module, _initial, _maximum, _exportName, _segment_names);
|
|
13
|
+
CAMLxparam5(_segment_data, _segmentPassive, _segmentOffsets, _segmentSizes, _shared);
|
|
14
|
+
CAMLxparam2(_memory64, _memoryName);
|
|
15
15
|
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
|
|
16
16
|
BinaryenIndex initial = Int_val(_initial);
|
|
17
17
|
BinaryenIndex maximum = Int_val(_maximum);
|
|
18
18
|
char* exportName = Safe_String_val(_exportName);
|
|
19
|
-
|
|
20
|
-
int
|
|
21
|
-
const char*
|
|
22
|
-
for (int i = 0; i <
|
|
23
|
-
|
|
19
|
+
_segment_names = array_of_list(_segment_names);
|
|
20
|
+
int segmentNamesLen = array_length(_segment_names);
|
|
21
|
+
const char* segment_names[segmentNamesLen];
|
|
22
|
+
for (int i = 0; i < segmentNamesLen; i++) {
|
|
23
|
+
segment_names[i] = Safe_String_val(Field(_segment_names, i));
|
|
24
|
+
}
|
|
25
|
+
_segment_data = array_of_list(_segment_data);
|
|
26
|
+
int segmentDataLen = array_length(_segment_data);
|
|
27
|
+
const char* segment_data[segmentDataLen];
|
|
28
|
+
for (int i = 0; i < segmentDataLen; i++) {
|
|
29
|
+
segment_data[i] = Safe_String_val(Field(_segment_data, i));
|
|
24
30
|
}
|
|
25
31
|
_segmentPassive = array_of_list(_segmentPassive);
|
|
26
32
|
int segmentPassiveLen = array_length(_segmentPassive);
|
|
@@ -43,12 +49,12 @@ caml_binaryen_set_memory(value _module, value _initial, value _maximum, value _e
|
|
|
43
49
|
bool shared = Bool_val(_shared);
|
|
44
50
|
bool memory64 = Bool_val(_memory64);
|
|
45
51
|
char* memoryName = Safe_String_val(_memoryName);
|
|
46
|
-
BinaryenSetMemory(module, initial, maximum, exportName,
|
|
52
|
+
BinaryenSetMemory(module, initial, maximum, exportName, segment_names, segment_data, segmentPassive, segmentOffsets, segmentSizes, segmentNamesLen, shared, memory64, memoryName);
|
|
47
53
|
CAMLreturn(Val_unit);
|
|
48
54
|
}
|
|
49
55
|
CAMLprim value
|
|
50
56
|
caml_binaryen_set_memory__bytecode(value * argv) {
|
|
51
|
-
return caml_binaryen_set_memory(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]);
|
|
57
|
+
return caml_binaryen_set_memory(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]);
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
CAMLprim value
|
|
@@ -111,28 +117,28 @@ caml_binaryen_get_num_memory_segments(value _module) {
|
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
CAMLprim value
|
|
114
|
-
caml_binaryen_get_memory_segment_byte_offset(value _module, value
|
|
115
|
-
CAMLparam2(_module,
|
|
120
|
+
caml_binaryen_get_memory_segment_byte_offset(value _module, value _name) {
|
|
121
|
+
CAMLparam2(_module, _name);
|
|
116
122
|
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
|
|
117
|
-
|
|
118
|
-
CAMLreturn(Val_int(BinaryenGetMemorySegmentByteOffset(module,
|
|
123
|
+
char* name = Safe_String_val(_name);
|
|
124
|
+
CAMLreturn(Val_int(BinaryenGetMemorySegmentByteOffset(module, name)));
|
|
119
125
|
}
|
|
120
126
|
|
|
121
127
|
CAMLprim value
|
|
122
|
-
caml_binaryen_get_memory_segment_passive(value _module, value
|
|
123
|
-
CAMLparam2(_module,
|
|
128
|
+
caml_binaryen_get_memory_segment_passive(value _module, value _name) {
|
|
129
|
+
CAMLparam2(_module, _name);
|
|
124
130
|
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
|
|
125
|
-
|
|
126
|
-
CAMLreturn(Val_bool(BinaryenGetMemorySegmentPassive(module,
|
|
131
|
+
char* name = Safe_String_val(_name);
|
|
132
|
+
CAMLreturn(Val_bool(BinaryenGetMemorySegmentPassive(module, name)));
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
CAMLprim value
|
|
130
|
-
caml_binaryen_get_memory_segment_data(value _module, value
|
|
131
|
-
CAMLparam2(_module,
|
|
136
|
+
caml_binaryen_get_memory_segment_data(value _module, value _name) {
|
|
137
|
+
CAMLparam2(_module, _name);
|
|
132
138
|
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
|
|
133
|
-
|
|
134
|
-
size_t size = BinaryenGetMemorySegmentByteLength(module,
|
|
139
|
+
char* name = Safe_String_val(_name);
|
|
140
|
+
size_t size = BinaryenGetMemorySegmentByteLength(module, name);
|
|
135
141
|
CAMLprim value bytes = caml_alloc_string(size);
|
|
136
|
-
BinaryenCopyMemorySegmentData(module,
|
|
142
|
+
BinaryenCopyMemorySegmentData(module, name, (char*)Bytes_val(bytes));
|
|
137
143
|
CAMLreturn(bytes);
|
|
138
144
|
}
|
binaryen-archive/src/memory.js
CHANGED
|
@@ -6,7 +6,8 @@ function caml_binaryen_set_memory(
|
|
|
6
6
|
initial,
|
|
7
7
|
maximum,
|
|
8
8
|
exportName,
|
|
9
|
-
|
|
9
|
+
segmentNames,
|
|
10
|
+
segmentData,
|
|
10
11
|
segmentPassives,
|
|
11
12
|
segmentOffsets,
|
|
12
13
|
segmentSizes,
|
|
@@ -14,11 +15,13 @@ function caml_binaryen_set_memory(
|
|
|
14
15
|
memory64,
|
|
15
16
|
memoryName
|
|
16
17
|
) {
|
|
18
|
+
var datas = caml_list_to_js_array(segmentData);
|
|
17
19
|
var passives = caml_list_to_js_array(segmentPassives);
|
|
18
20
|
var offsets = caml_list_to_js_array(segmentOffsets);
|
|
19
|
-
var segs = caml_list_to_js_array(
|
|
21
|
+
var segs = caml_list_to_js_array(segmentNames).map(function (name, idx) {
|
|
20
22
|
return {
|
|
21
|
-
|
|
23
|
+
name: caml_jsstring_of_string(name),
|
|
24
|
+
data: caml_convert_bytes_to_array(datas[idx]),
|
|
22
25
|
passive: caml_js_from_bool(passives[idx]),
|
|
23
26
|
offset: offsets[idx],
|
|
24
27
|
};
|
|
@@ -48,7 +51,8 @@ function caml_binaryen_set_memory__bytecode() {
|
|
|
48
51
|
arguments[7],
|
|
49
52
|
arguments[8],
|
|
50
53
|
arguments[9],
|
|
51
|
-
arguments[10]
|
|
54
|
+
arguments[10],
|
|
55
|
+
arguments[11]
|
|
52
56
|
);
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -108,20 +112,22 @@ function caml_binaryen_get_num_memory_segments(wasm_mod) {
|
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
//Provides: caml_binaryen_get_memory_segment_byte_offset
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
//Requires: caml_jsstring_of_string
|
|
116
|
+
function caml_binaryen_get_memory_segment_byte_offset(wasm_mod, name) {
|
|
117
|
+
var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
|
|
113
118
|
return info.offset;
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
//Provides: caml_binaryen_get_memory_segment_passive
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
//Requires: caml_jsstring_of_string
|
|
123
|
+
function caml_binaryen_get_memory_segment_passive(wasm_mod, name) {
|
|
124
|
+
var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
|
|
119
125
|
return info.passive;
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
//Provides: caml_binaryen_get_memory_segment_data
|
|
123
|
-
//Requires: caml_bytes_of_array
|
|
124
|
-
function caml_binaryen_get_memory_segment_data(wasm_mod,
|
|
125
|
-
var info = wasm_mod.
|
|
129
|
+
//Requires: caml_bytes_of_array, caml_jsstring_of_string
|
|
130
|
+
function caml_binaryen_get_memory_segment_data(wasm_mod, name) {
|
|
131
|
+
var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
|
|
126
132
|
return caml_bytes_of_array(info.data);
|
|
127
133
|
}
|
binaryen-archive/src/memory.ml
CHANGED
|
@@ -3,6 +3,7 @@ external set_memory :
|
|
|
3
3
|
int ->
|
|
4
4
|
int ->
|
|
5
5
|
string ->
|
|
6
|
+
string list ->
|
|
6
7
|
bytes list ->
|
|
7
8
|
bool list ->
|
|
8
9
|
Expression.t list ->
|
|
@@ -12,7 +13,7 @@ external set_memory :
|
|
|
12
13
|
string ->
|
|
13
14
|
unit = "caml_binaryen_set_memory__bytecode" "caml_binaryen_set_memory"
|
|
14
15
|
|
|
15
|
-
type segment = { data : bytes; kind : segment_kind; size : int }
|
|
16
|
+
type segment = { name : string; data : bytes; kind : segment_kind; size : int }
|
|
16
17
|
and segment_kind = Passive | Active of { offset : Expression.t }
|
|
17
18
|
|
|
18
19
|
(** Module, initial size, maximum size, export name, segments, shared, memory64, moduleName . *)
|
|
@@ -20,26 +21,36 @@ let set_memory wasm_mod initial maximum export_name (segments : segment list)
|
|
|
20
21
|
shared memory64 moduleName =
|
|
21
22
|
let split_segments segments =
|
|
22
23
|
List.fold_right
|
|
23
|
-
(fun { data; kind; size }
|
|
24
|
-
(
|
|
24
|
+
(fun { name; data; kind; size }
|
|
25
|
+
( segment_name,
|
|
26
|
+
segment_data,
|
|
27
|
+
segment_passive,
|
|
28
|
+
segment_offsets,
|
|
29
|
+
segment_sizes ) ->
|
|
25
30
|
match kind with
|
|
26
31
|
| Active { offset } ->
|
|
27
|
-
(
|
|
32
|
+
( name :: segment_name,
|
|
33
|
+
data :: segment_data,
|
|
28
34
|
false :: segment_passive,
|
|
29
35
|
offset :: segment_offsets,
|
|
30
36
|
size :: segment_sizes )
|
|
31
37
|
| Passive ->
|
|
32
|
-
(
|
|
38
|
+
( name :: segment_name,
|
|
39
|
+
data :: segment_data,
|
|
33
40
|
true :: segment_passive,
|
|
34
41
|
Expression.Null.make () :: segment_offsets,
|
|
35
42
|
size :: segment_sizes ))
|
|
36
|
-
segments ([], [], [], [])
|
|
43
|
+
segments ([], [], [], [], [])
|
|
37
44
|
in
|
|
38
|
-
let
|
|
45
|
+
let ( segment_name,
|
|
46
|
+
segment_data,
|
|
47
|
+
segment_passive,
|
|
48
|
+
segment_offsets,
|
|
49
|
+
segment_sizes ) =
|
|
39
50
|
split_segments segments
|
|
40
51
|
in
|
|
41
|
-
set_memory wasm_mod initial maximum export_name segment_data
|
|
42
|
-
segment_offsets segment_sizes shared memory64 moduleName
|
|
52
|
+
set_memory wasm_mod initial maximum export_name segment_name segment_data
|
|
53
|
+
segment_passive segment_offsets segment_sizes shared memory64 moduleName
|
|
43
54
|
|
|
44
55
|
external has_memory : Module.t -> bool = "caml_binaryen_has_memory"
|
|
45
56
|
|
|
@@ -59,11 +70,11 @@ let unlimited = -1
|
|
|
59
70
|
external get_num_segments : Module.t -> int
|
|
60
71
|
= "caml_binaryen_get_num_memory_segments"
|
|
61
72
|
|
|
62
|
-
external get_segment_byte_offset : Module.t ->
|
|
73
|
+
external get_segment_byte_offset : Module.t -> string -> int
|
|
63
74
|
= "caml_binaryen_get_memory_segment_byte_offset"
|
|
64
75
|
|
|
65
|
-
external get_segment_passive : Module.t ->
|
|
76
|
+
external get_segment_passive : Module.t -> string -> bool
|
|
66
77
|
= "caml_binaryen_get_memory_segment_passive"
|
|
67
78
|
|
|
68
|
-
external get_segment_data : Module.t ->
|
|
79
|
+
external get_segment_data : Module.t -> string -> bytes
|
|
69
80
|
= "caml_binaryen_get_memory_segment_data"
|
binaryen-archive/src/memory.mli
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type segment = { data : bytes; kind : segment_kind; size : int }
|
|
1
|
+
type segment = { name : string; data : bytes; kind : segment_kind; size : int }
|
|
2
2
|
and segment_kind = Passive | Active of { offset : Expression.t }
|
|
3
3
|
|
|
4
4
|
val set_memory :
|
|
@@ -20,6 +20,6 @@ val is_shared : Module.t -> string -> bool
|
|
|
20
20
|
val is_64 : Module.t -> string -> bool
|
|
21
21
|
val unlimited : int
|
|
22
22
|
val get_num_segments : Module.t -> int
|
|
23
|
-
val get_segment_byte_offset : Module.t ->
|
|
24
|
-
val get_segment_passive : Module.t ->
|
|
25
|
-
val get_segment_data : Module.t ->
|
|
23
|
+
val get_segment_byte_offset : Module.t -> string -> int
|
|
24
|
+
val get_segment_passive : Module.t -> string -> bool
|
|
25
|
+
val get_segment_data : Module.t -> string -> bytes
|
binaryen-archive/src/module.js
CHANGED
|
@@ -17,31 +17,34 @@ function caml_binaryen_module_parse(text) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
//Provides: caml_binaryen_module_print
|
|
20
|
+
//Requires: caml_sys_fds
|
|
20
21
|
//Requires: caml_string_of_jsstring
|
|
21
22
|
//Requires: caml_ml_output, caml_ml_string_length
|
|
22
23
|
function caml_binaryen_module_print(wasm_mod) {
|
|
23
24
|
var text = wasm_mod.emitText();
|
|
24
|
-
var chanid = 1; // stdout
|
|
25
|
+
var chanid = caml_sys_fds[1].chanid; // stdout
|
|
25
26
|
var s = caml_string_of_jsstring(text);
|
|
26
27
|
caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
//Provides: caml_binaryen_module_print_asmjs
|
|
31
|
+
//Requires: caml_sys_fds
|
|
30
32
|
//Requires: caml_string_of_jsstring
|
|
31
33
|
//Requires: caml_ml_output, caml_ml_string_length
|
|
32
34
|
function caml_binaryen_module_print_asmjs(wasm_mod) {
|
|
33
35
|
var asm = wasm_mod.emitAsmjs();
|
|
34
|
-
var chanid = 1; // stdout
|
|
36
|
+
var chanid = caml_sys_fds[1].chanid; // stdout
|
|
35
37
|
var s = caml_string_of_jsstring(asm);
|
|
36
38
|
caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
//Provides: caml_binaryen_module_print_stack_ir
|
|
42
|
+
//Requires: caml_sys_fds
|
|
40
43
|
//Requires: caml_string_of_jsstring, caml_js_from_bool
|
|
41
44
|
//Requires: caml_ml_output, caml_ml_string_length
|
|
42
45
|
function caml_binaryen_module_print_stack_ir(wasm_mod, optimize) {
|
|
43
46
|
var stackir = wasm_mod.emitStackIR(caml_js_from_bool(optimize));
|
|
44
|
-
var chanid = 1; // stdout
|
|
47
|
+
var chanid = caml_sys_fds[1].chanid; // stdout
|
|
45
48
|
var s = caml_string_of_jsstring(stackir);
|
|
46
49
|
caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
|
|
47
50
|
}
|
binaryen-archive/test/dune
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
(global $max_int64_mut (mut i64) (i64.const 9223372036854775807))
|
|
17
17
|
(global $test_float64_bits f64 (f64.const 1.23))
|
|
18
18
|
(memory $0 1)
|
|
19
|
-
(data $
|
|
20
|
-
(data $
|
|
19
|
+
(data $hello (i32.const 0) "hello")
|
|
20
|
+
(data $world "world")
|
|
21
21
|
(table $table 1 1 funcref)
|
|
22
22
|
(elem $elem (i32.const 0) $adder)
|
|
23
23
|
(export "adder" (func $adder))
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
(block $add (result i32)
|
|
29
29
|
(if
|
|
30
30
|
(i32.const 0)
|
|
31
|
-
(
|
|
31
|
+
(then
|
|
32
|
+
(unreachable)
|
|
33
|
+
)
|
|
32
34
|
)
|
|
33
35
|
(i32.add
|
|
34
36
|
(select
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
)
|
|
45
47
|
(func $start (type $1)
|
|
46
48
|
(block $start
|
|
47
|
-
(memory.init $
|
|
49
|
+
(memory.init $world
|
|
48
50
|
(i32.const 2048)
|
|
49
51
|
(i32.const 0)
|
|
50
52
|
(i32.const 5)
|
|
@@ -73,8 +75,8 @@
|
|
|
73
75
|
(type $3 (func (param anyref) (result i32)))
|
|
74
76
|
(import "future-wasi" "write" (func $write (type $2) (param anyref i32 i32) (result i32)))
|
|
75
77
|
(memory $0 1)
|
|
76
|
-
(data $
|
|
77
|
-
(data $
|
|
78
|
+
(data $hello (i32.const 0) "hello")
|
|
79
|
+
(data $world "world")
|
|
78
80
|
(table $table 1 1 funcref)
|
|
79
81
|
(elem $elem (i32.const 0) $adder)
|
|
80
82
|
(export "adder" (func $adder))
|
|
@@ -94,7 +96,7 @@
|
|
|
94
96
|
)
|
|
95
97
|
)
|
|
96
98
|
(func $start (type $1) (; has Stack IR ;)
|
|
97
|
-
(memory.init $
|
|
99
|
+
(memory.init $world
|
|
98
100
|
(i32.const 2048)
|
|
99
101
|
(i32.const 0)
|
|
100
102
|
(i32.const 5)
|
|
@@ -115,11 +117,11 @@
|
|
|
115
117
|
)
|
|
116
118
|
)
|
|
117
119
|
(module
|
|
118
|
-
(type $type
|
|
119
|
-
(type $
|
|
120
|
-
(type $
|
|
121
|
-
(type $
|
|
122
|
-
(import "future-wasi" "write" (func $fimport$0 (type $type
|
|
120
|
+
(type $type (func (param anyref i32 i32) (result i32)))
|
|
121
|
+
(type $type_1 (func (param i32 i32) (result i32)))
|
|
122
|
+
(type $type_2 (func))
|
|
123
|
+
(type $type_3 (func (param anyref) (result i32)))
|
|
124
|
+
(import "future-wasi" "write" (func $fimport$0 (type $type) (param anyref i32 i32) (result i32)))
|
|
123
125
|
(memory $0 1)
|
|
124
126
|
(data $0 (i32.const 0) "hello")
|
|
125
127
|
(data $1 "world")
|
|
@@ -129,7 +131,7 @@
|
|
|
129
131
|
(export "memory" (memory $0))
|
|
130
132
|
(export "hello" (func $2))
|
|
131
133
|
(start $1)
|
|
132
|
-
(func $0 (type $
|
|
134
|
+
(func $0 (type $type_1) (param $0 i32) (param $1 i32) (result i32)
|
|
133
135
|
(i32.add
|
|
134
136
|
(select
|
|
135
137
|
(local.get $0)
|
|
@@ -141,7 +143,7 @@
|
|
|
141
143
|
(local.get $1)
|
|
142
144
|
)
|
|
143
145
|
)
|
|
144
|
-
(func $1 (type $
|
|
146
|
+
(func $1 (type $type_2)
|
|
145
147
|
(memory.init $1
|
|
146
148
|
(i32.const 2048)
|
|
147
149
|
(i32.const 0)
|
|
@@ -154,7 +156,7 @@
|
|
|
154
156
|
)
|
|
155
157
|
)
|
|
156
158
|
)
|
|
157
|
-
(func $2 (type $
|
|
159
|
+
(func $2 (type $type_3) (param $0 anyref) (result i32)
|
|
158
160
|
(call $fimport$0
|
|
159
161
|
(local.get $0)
|
|
160
162
|
(i32.const 0)
|
|
@@ -163,11 +165,11 @@
|
|
|
163
165
|
)
|
|
164
166
|
)
|
|
165
167
|
(module
|
|
166
|
-
(type $type
|
|
167
|
-
(type $
|
|
168
|
-
(type $
|
|
169
|
-
(type $
|
|
170
|
-
(import "future-wasi" "write" (func $fimport$0 (type $type
|
|
168
|
+
(type $type (func (param anyref i32 i32) (result i32)))
|
|
169
|
+
(type $type_1 (func (param i32 i32) (result i32)))
|
|
170
|
+
(type $type_2 (func))
|
|
171
|
+
(type $type_3 (func (param anyref) (result i32)))
|
|
172
|
+
(import "future-wasi" "write" (func $fimport$0 (type $type) (param anyref i32 i32) (result i32)))
|
|
171
173
|
(memory $0 1)
|
|
172
174
|
(data $0 (i32.const 0) "hello")
|
|
173
175
|
(data $1 "world")
|
|
@@ -177,7 +179,7 @@
|
|
|
177
179
|
(export "memory" (memory $0))
|
|
178
180
|
(export "hello" (func $2))
|
|
179
181
|
(start $1)
|
|
180
|
-
(func $0 (type $
|
|
182
|
+
(func $0 (type $type_1) (param $0 i32) (param $1 i32) (result i32)
|
|
181
183
|
local.get $0
|
|
182
184
|
local.get $1
|
|
183
185
|
i32.load
|
|
@@ -186,7 +188,7 @@
|
|
|
186
188
|
local.get $1
|
|
187
189
|
i32.add
|
|
188
190
|
)
|
|
189
|
-
(func $1 (type $
|
|
191
|
+
(func $1 (type $type_2)
|
|
190
192
|
i32.const 2048
|
|
191
193
|
i32.const 0
|
|
192
194
|
i32.const 5
|
|
@@ -196,7 +198,7 @@
|
|
|
196
198
|
call $0
|
|
197
199
|
drop
|
|
198
200
|
)
|
|
199
|
-
(func $2 (type $
|
|
201
|
+
(func $2 (type $type_3) (param $0 anyref) (result i32)
|
|
200
202
|
local.get $0
|
|
201
203
|
i32.const 0
|
|
202
204
|
i32.const 1
|