@grain/binaryen.ml 0.35.0 → 0.37.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 +31 -0
- binaryen-archive/binaryen.opam +3 -3
- binaryen-archive/esy.lock/index.json +339 -462
- binaryen-archive/esy.lock/opam/base.v0.17.3/opam +1 -1
- binaryen-archive/esy.lock/opam/{chrome-trace.3.21.1 → chrome-trace.3.24.2}/opam +6 -8
- binaryen-archive/esy.lock/opam/{cmdliner.1.3.0 → cmdliner.2.1.1}/opam +26 -10
- binaryen-archive/esy.lock/opam/{dune-build-info.3.21.1 → dune-build-info.3.24.2}/opam +6 -8
- binaryen-archive/esy.lock/opam/{dune-configurator.3.21.1 → dune-configurator.3.24.2}/opam +6 -8
- binaryen-archive/esy.lock/opam/{dune-rpc.3.21.1 → dune-rpc.3.20.2}/opam +5 -5
- binaryen-archive/esy.lock/opam/{dune.3.21.1 → dune.3.24.2}/opam +13 -9
- binaryen-archive/esy.lock/opam/{dyn.3.21.1 → dyn.3.20.2}/opam +6 -6
- binaryen-archive/esy.lock/opam/fix.20250919/opam +1 -0
- binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.6.4.1/opam +67 -0
- binaryen-archive/esy.lock/opam/ocaml-lsp-server.1.23.1/opam +2 -2
- binaryen-archive/esy.lock/opam/{ocaml-version.4.0.3 → ocaml-version.4.1.3}/opam +3 -3
- binaryen-archive/esy.lock/opam/{ocaml_intrinsics_kernel.v0.17.1 → ocaml_intrinsics_kernel.v0.17.2}/opam +3 -5
- binaryen-archive/esy.lock/opam/ocamlbuild.0.16.1/opam +1 -0
- binaryen-archive/esy.lock/opam/{ocamlc-loc.3.21.1 → ocamlc-loc.3.20.2}/opam +6 -6
- binaryen-archive/esy.lock/opam/ocamlfind.1.9.8/opam +2 -1
- binaryen-archive/esy.lock/opam/{ocamlformat-lib.0.27.0 → ocamlformat-lib.0.29.0}/opam +7 -6
- binaryen-archive/esy.lock/opam/{ocamlformat-rpc-lib.0.28.1 → ocamlformat-rpc-lib.0.29.0}/opam +4 -4
- binaryen-archive/esy.lock/opam/{ocamlformat.0.27.0 → ocamlformat.0.29.0}/opam +6 -5
- binaryen-archive/esy.lock/opam/{ocp-indent.1.7.0 → ocp-indent.1.9.0}/opam +10 -9
- binaryen-archive/esy.lock/opam/{ordering.3.21.1 → ordering.3.20.2}/opam +6 -6
- binaryen-archive/esy.lock/opam/{ppxlib.0.37.0 → ppxlib.0.39.0~5.6preview}/opam +12 -13
- binaryen-archive/esy.lock/opam/{stdune.3.21.1 → stdune.3.20.2}/opam +7 -9
- binaryen-archive/esy.lock/opam/{xdg.3.21.1 → xdg.3.24.2}/opam +6 -8
- binaryen-archive/package.json +9 -5
- binaryen-archive/src/dune +4 -1
- binaryen-archive/src/expression.c +345 -0
- binaryen-archive/src/expression.js +243 -11
- binaryen-archive/src/expression.ml +106 -0
- binaryen-archive/src/expression.mli +72 -0
- binaryen-archive/src/heap_type.c +19 -0
- binaryen-archive/src/heap_type.js +12 -0
- binaryen-archive/src/heap_type.ml +10 -1
- binaryen-archive/src/heap_type.mli +8 -1
- binaryen-archive/src/memory.c +6 -1
- binaryen-archive/src/memory.js +2 -2
- binaryen-archive/src/memory.ml +1 -1
- binaryen-archive/src/memory.mli +1 -1
- binaryen-archive/src/module.js +7 -20
- binaryen-archive/src/module.ml +9 -0
- binaryen-archive/src/module.mli +2 -0
- binaryen-archive/src/module_feature.c +12 -0
- binaryen-archive/src/module_feature.js +12 -0
- binaryen-archive/src/ocaml_helpers.c +9 -0
- binaryen-archive/src/ocaml_helpers.h +5 -0
- binaryen-archive/src/ocaml_helpers.js +11 -0
- binaryen-archive/src/passes.ml +13 -4
- binaryen-archive/src/passes.mli +14 -5
- binaryen-archive/src/type.c +5 -3
- binaryen-archive/src/type.js +2 -3
- binaryen-archive/src/type.ml +4 -1
- binaryen-archive/src/type.mli +1 -1
- binaryen-archive/src/type_builder.c +180 -0
- binaryen-archive/src/type_builder.js +116 -0
- binaryen-archive/src/type_builder.ml +67 -0
- binaryen-archive/src/type_builder.mli +28 -0
- binaryen-archive/test/test.expected +188 -25
- binaryen-archive/test/test.ml +131 -4
- binaryen-archive/esy.lock/opam/base-bytes.base/opam +0 -10
- binaryen-archive/esy.lock/opam/fs-io.3.21.1/opam +0 -41
- binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.6.2.0/opam +0 -56
- binaryen-archive/esy.lock/opam/stdlib-shims.0.3.0/opam +0 -31
- binaryen-archive/esy.lock/opam/top-closure.3.21.1/opam +0 -40
binaryen-archive/src/module.ml
CHANGED
|
@@ -98,6 +98,15 @@ module Feature = struct
|
|
|
98
98
|
|
|
99
99
|
let call_indirect_overlong = call_indirect_overlong ()
|
|
100
100
|
|
|
101
|
+
external relaxed_atomics : unit -> t = "caml_binaryen_feature_relaxed_atomics"
|
|
102
|
+
|
|
103
|
+
let relaxed_atomics = relaxed_atomics ()
|
|
104
|
+
|
|
105
|
+
external custom_page_sizes : unit -> t
|
|
106
|
+
= "caml_binaryen_feature_custom_page_sizes"
|
|
107
|
+
|
|
108
|
+
let custom_page_sizes = custom_page_sizes ()
|
|
109
|
+
|
|
101
110
|
external all : unit -> t = "caml_binaryen_feature_all"
|
|
102
111
|
|
|
103
112
|
let all = all ()
|
binaryen-archive/src/module.mli
CHANGED
|
@@ -155,6 +155,18 @@ caml_binaryen_feature_call_indirect_overlong(value unit) {
|
|
|
155
155
|
CAMLreturn(Val_int(BinaryenFeatureCallIndirectOverlong()));
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
CAMLprim value
|
|
159
|
+
caml_binaryen_feature_relaxed_atomics(value unit) {
|
|
160
|
+
CAMLparam1(unit);
|
|
161
|
+
CAMLreturn(Val_int(BinaryenFeatureRelaxedAtomics()));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
CAMLprim value
|
|
165
|
+
caml_binaryen_feature_custom_page_sizes(value unit) {
|
|
166
|
+
CAMLparam1(unit);
|
|
167
|
+
CAMLreturn(Val_int(BinaryenFeatureCustomPageSizes()));
|
|
168
|
+
}
|
|
169
|
+
|
|
158
170
|
CAMLprim value
|
|
159
171
|
caml_binaryen_feature_all(value unit) {
|
|
160
172
|
CAMLparam1(unit);
|
|
@@ -140,6 +140,18 @@ function caml_binaryen_feature_call_indirect_overlong() {
|
|
|
140
140
|
return Binaryen.Features.BulkMemoryOpt;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
//Provides: caml_binaryen_feature_relaxed_atomics
|
|
144
|
+
//Requires: Binaryen
|
|
145
|
+
function caml_binaryen_feature_relaxed_atomics() {
|
|
146
|
+
return Binaryen.Features.RelaxedAtomics;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//Provides: caml_binaryen_feature_custom_page_sizes
|
|
150
|
+
//Requires: Binaryen
|
|
151
|
+
function caml_binaryen_feature_custom_page_sizes() {
|
|
152
|
+
return Binaryen.Features.CustomPageSizes;
|
|
153
|
+
}
|
|
154
|
+
|
|
143
155
|
//Provides: caml_binaryen_feature_all
|
|
144
156
|
//Requires: Binaryen
|
|
145
157
|
function caml_binaryen_feature_all() {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <caml/fail.h>
|
|
4
4
|
#include <caml/memory.h>
|
|
5
5
|
#include <caml/callback.h>
|
|
6
|
+
#include <caml/alloc.h>
|
|
6
7
|
|
|
7
8
|
#include "ocaml_helpers.h"
|
|
8
9
|
|
|
@@ -102,6 +103,14 @@ value alloc_BinaryenElementSegmentRef(BinaryenElementSegmentRef elem)
|
|
|
102
103
|
return v;
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
/* Allocating an OCaml custom block to hold the given TypeBuilderRef */
|
|
107
|
+
value alloc_TypeBuilderRef(TypeBuilderRef builder)
|
|
108
|
+
{
|
|
109
|
+
value v = caml_alloc_custom(&binaryen_ops, sizeof(TypeBuilderRef), 0, 1);
|
|
110
|
+
TypeBuilderRef_val(v) = builder;
|
|
111
|
+
return v;
|
|
112
|
+
}
|
|
113
|
+
|
|
105
114
|
CAMLprim value
|
|
106
115
|
array_of_list(value list) {
|
|
107
116
|
CAMLparam1(list);
|
|
@@ -23,6 +23,7 @@ static struct custom_operations binaryen_ops = {
|
|
|
23
23
|
|
|
24
24
|
#define BinaryenModuleRef_val(v) (*((BinaryenModuleRef*) Data_custom_val(v)))
|
|
25
25
|
#define BinaryenType_val(v) (*((BinaryenType*) Data_custom_val(v)))
|
|
26
|
+
#define BinaryenPackedType_val(v) Int_val(v)
|
|
26
27
|
#define BinaryenHeapType_val(v) (*((BinaryenHeapType*) Data_custom_val(v)))
|
|
27
28
|
#define BinaryenExpressionRef_val(v) (*((BinaryenExpressionRef*) Data_custom_val(v)))
|
|
28
29
|
#define BinaryenOp_val(v) (*((BinaryenOp*) Data_custom_val(v)))
|
|
@@ -33,6 +34,7 @@ static struct custom_operations binaryen_ops = {
|
|
|
33
34
|
#define BinaryenExportRef_val(v) (*((BinaryenExportRef*) Data_custom_val(v)))
|
|
34
35
|
#define BinaryenTableRef_val(v) (*((BinaryenTableRef*) Data_custom_val(v)))
|
|
35
36
|
#define BinaryenElementSegmentRef_val(v) (*((BinaryenElementSegmentRef*) Data_custom_val(v)))
|
|
37
|
+
#define TypeBuilderRef_val(v) (*((TypeBuilderRef*) Data_custom_val(v)))
|
|
36
38
|
|
|
37
39
|
#define Val_none Val_int(0)
|
|
38
40
|
#define Some_val(v) Field(v, 0)
|
|
@@ -78,6 +80,9 @@ value alloc_BinaryenTableRef(BinaryenTableRef table);
|
|
|
78
80
|
/* Allocating an OCaml custom block to hold the given BinaryenElementSegmentRef */
|
|
79
81
|
value alloc_BinaryenElementSegmentRef(BinaryenElementSegmentRef elem);
|
|
80
82
|
|
|
83
|
+
/* Allocating an OCaml custom block to hold the given TypeBuilderRef */
|
|
84
|
+
value alloc_TypeBuilderRef(TypeBuilderRef builder);
|
|
85
|
+
|
|
81
86
|
CAMLprim value
|
|
82
87
|
array_of_list(value list);
|
|
83
88
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//Provides: caml_ml_output_str_stdout
|
|
2
|
+
//Requires: caml_ml_std_channel_id
|
|
3
|
+
//Requires: caml_string_of_jsstring
|
|
4
|
+
//Requires: caml_ml_output, caml_ml_string_length
|
|
5
|
+
function caml_ml_output_str_stdout(text) {
|
|
6
|
+
var chanid = caml_ml_std_channel_id[1]; // stdout
|
|
7
|
+
|
|
8
|
+
const raw_string = caml_string_of_jsstring(text);
|
|
9
|
+
const length = caml_ml_string_length(raw_string);
|
|
10
|
+
caml_ml_output(chanid, raw_string, 0, length);
|
|
11
|
+
}
|
binaryen-archive/src/passes.ml
CHANGED
|
@@ -16,6 +16,9 @@ let dae = "dae"
|
|
|
16
16
|
removed *)
|
|
17
17
|
let dae_optimizing = "dae-optimizing"
|
|
18
18
|
|
|
19
|
+
(** Experimental reimplementation of DAE *)
|
|
20
|
+
let dae_2 = "dae-2"
|
|
21
|
+
|
|
19
22
|
(** refine and merge abstract (never-created) types *)
|
|
20
23
|
let abstract_type_refining = "abstract-type-refining"
|
|
21
24
|
|
|
@@ -106,6 +109,9 @@ let generate_global_effects = "generate-global-effects"
|
|
|
106
109
|
(** refine the types of globals *)
|
|
107
110
|
let global_refining = "global-refining"
|
|
108
111
|
|
|
112
|
+
(** globally optimize struct values, also emitting ref.cast_desc_eq *)
|
|
113
|
+
let gsi_desc_cast = "gsi-desc-cast"
|
|
114
|
+
|
|
109
115
|
(** globally optimize struct values *)
|
|
110
116
|
let gsi = "gsi"
|
|
111
117
|
|
|
@@ -152,9 +158,6 @@ let inlining_optimizing = "inlining-optimizing"
|
|
|
152
158
|
(** lower away binaryen intrinsics *)
|
|
153
159
|
let intrinsic_lowering = "intrinsic-lowering"
|
|
154
160
|
|
|
155
|
-
(** wrap imports and exports for JavaScript promise integration *)
|
|
156
|
-
let jspi = "jspi"
|
|
157
|
-
|
|
158
161
|
(** legalizes i64 types on the import/export boundary *)
|
|
159
162
|
let legalize_js_interface = "legalize-js-interface"
|
|
160
163
|
|
|
@@ -321,6 +324,9 @@ let symbolmap = "symbolmap"
|
|
|
321
324
|
(** removes operations incompatible with js *)
|
|
322
325
|
let remove_non_js_ops = "remove-non-js-ops"
|
|
323
326
|
|
|
327
|
+
(** replaces relaxed SIMD instructions with unreachable *)
|
|
328
|
+
let remove_relaxed_simd = "remove-relaxed-simd"
|
|
329
|
+
|
|
324
330
|
(** removes imports and replaces them with nops *)
|
|
325
331
|
let remove_imports = "remove-imports"
|
|
326
332
|
|
|
@@ -468,6 +474,9 @@ let strip_eh = "strip-eh"
|
|
|
468
474
|
(** strip the wasm target features section *)
|
|
469
475
|
let strip_target_features = "strip-target-features"
|
|
470
476
|
|
|
477
|
+
(** strip all toolchain-specific code annotations *)
|
|
478
|
+
let strip_toolchain_annotations = "strip-toolchain-annotations"
|
|
479
|
+
|
|
471
480
|
(** translate old Phase 3 EH instructions to new ones with exnref *)
|
|
472
481
|
let translate_to_exnref = "translate-to-exnref"
|
|
473
482
|
|
|
@@ -486,7 +495,7 @@ let type_finalizing = "type-finalizing"
|
|
|
486
495
|
(** merge types to their supertypes where possible *)
|
|
487
496
|
let type_merging = "type-merging"
|
|
488
497
|
|
|
489
|
-
(** create new
|
|
498
|
+
(** create new types to help other optimizations *)
|
|
490
499
|
let type_ssa = "type-ssa"
|
|
491
500
|
|
|
492
501
|
(** mark all types as non-final (open) *)
|
binaryen-archive/src/passes.mli
CHANGED
|
@@ -16,6 +16,9 @@ val dae_optimizing : t
|
|
|
16
16
|
(** removes arguments to calls in an lto-like manner, and optimizes where we
|
|
17
17
|
removed *)
|
|
18
18
|
|
|
19
|
+
val dae_2 : t
|
|
20
|
+
(** Experimental reimplementation of DAE *)
|
|
21
|
+
|
|
19
22
|
val abstract_type_refining : t
|
|
20
23
|
(** refine and merge abstract (never-created) types *)
|
|
21
24
|
|
|
@@ -106,6 +109,9 @@ val generate_global_effects : t
|
|
|
106
109
|
val global_refining : t
|
|
107
110
|
(** refine the types of globals *)
|
|
108
111
|
|
|
112
|
+
val gsi_desc_cast : t
|
|
113
|
+
(** globally optimize struct values, also emitting ref.cast_desc_eq *)
|
|
114
|
+
|
|
109
115
|
val gsi : t
|
|
110
116
|
(** globally optimize struct values *)
|
|
111
117
|
|
|
@@ -149,9 +155,6 @@ val inlining_optimizing : t
|
|
|
149
155
|
val intrinsic_lowering : t
|
|
150
156
|
(** lower away binaryen intrinsics *)
|
|
151
157
|
|
|
152
|
-
val jspi : t
|
|
153
|
-
(** wrap imports and exports for JavaScript promise integration *)
|
|
154
|
-
|
|
155
158
|
val legalize_js_interface : t
|
|
156
159
|
(** legalizes i64 types on the import/export boundary *)
|
|
157
160
|
|
|
@@ -316,6 +319,9 @@ val symbolmap : t
|
|
|
316
319
|
val remove_non_js_ops : t
|
|
317
320
|
(** removes operations incompatible with js *)
|
|
318
321
|
|
|
322
|
+
val remove_relaxed_simd : t
|
|
323
|
+
(** replaces relaxed SIMD instructions with unreachable *)
|
|
324
|
+
|
|
319
325
|
val remove_imports : t
|
|
320
326
|
(** removes imports and replaces them with nops *)
|
|
321
327
|
|
|
@@ -352,7 +358,7 @@ val reorder_globals : t
|
|
|
352
358
|
val reorder_locals : t
|
|
353
359
|
(** sorts locals by access frequency *)
|
|
354
360
|
|
|
355
|
-
val reorder_types: t
|
|
361
|
+
val reorder_types : t
|
|
356
362
|
(** sorts private types by access frequency *)
|
|
357
363
|
|
|
358
364
|
val rereloop : t
|
|
@@ -460,6 +466,9 @@ val strip_eh : t
|
|
|
460
466
|
val strip_target_features : t
|
|
461
467
|
(** strip the wasm target features section *)
|
|
462
468
|
|
|
469
|
+
val strip_toolchain_annotations : t
|
|
470
|
+
(** strip all toolchain-specific code annotations *)
|
|
471
|
+
|
|
463
472
|
val translate_to_exnref : t
|
|
464
473
|
(** translate old Phase 3 EH instructions to new ones with exnref *)
|
|
465
474
|
|
|
@@ -479,7 +488,7 @@ val type_merging : t
|
|
|
479
488
|
(** merge types to their supertypes where possible *)
|
|
480
489
|
|
|
481
490
|
val type_ssa : t
|
|
482
|
-
(** create new
|
|
491
|
+
(** create new types to help other optimizations *)
|
|
483
492
|
|
|
484
493
|
val type_unfinalizing : t
|
|
485
494
|
(** mark all types as non-final (open) *)
|
binaryen-archive/src/type.c
CHANGED
|
@@ -147,14 +147,16 @@ caml_binaryen_type_create(value tys) {
|
|
|
147
147
|
CAMLprim value
|
|
148
148
|
caml_binaryen_type_expand(value _ty) {
|
|
149
149
|
CAMLparam1(_ty);
|
|
150
|
+
CAMLlocal2(typeArray, field);
|
|
150
151
|
BinaryenType ty = BinaryenType_val(_ty);
|
|
151
152
|
int arity = BinaryenTypeArity(ty);
|
|
152
153
|
BinaryenType* buf = malloc(sizeof(BinaryenType) * arity);
|
|
153
154
|
BinaryenTypeExpand(ty, buf);
|
|
154
155
|
|
|
155
|
-
|
|
156
|
+
typeArray = caml_alloc(arity, 0);
|
|
156
157
|
for (int i = 0; i < arity; i++) {
|
|
157
|
-
|
|
158
|
+
field = alloc_BinaryenType(buf[i]);
|
|
159
|
+
Store_field(typeArray, i, field);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
free(buf);
|
|
@@ -176,4 +178,4 @@ caml_binaryen_type_from_heap_type(value _ty, value _nullable) {
|
|
|
176
178
|
bool nullable = Bool_val(_nullable);
|
|
177
179
|
BinaryenType ty = BinaryenTypeFromHeapType(heapTy, nullable);
|
|
178
180
|
CAMLreturn(alloc_BinaryenType(ty));
|
|
179
|
-
}
|
|
181
|
+
}
|
binaryen-archive/src/type.js
CHANGED
|
@@ -67,8 +67,7 @@ function caml_binaryen_type_structref() {
|
|
|
67
67
|
//Provides: caml_binaryen_type_arrayref
|
|
68
68
|
//Requires: Binaryen
|
|
69
69
|
function caml_binaryen_type_arrayref() {
|
|
70
|
-
|
|
71
|
-
return Binaryen._BinaryenTypeArrayref();
|
|
70
|
+
return Binaryen.arrayref;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
//Provides: caml_binaryen_type_stringref
|
|
@@ -131,4 +130,4 @@ function caml_binaryen_type_is_nullable(typ) {
|
|
|
131
130
|
//Requires: Binaryen
|
|
132
131
|
function caml_binaryen_type_from_heap_type(typ, nullable) {
|
|
133
132
|
return Binaryen._BinaryenTypeFromHeapType(typ, nullable);
|
|
134
|
-
}
|
|
133
|
+
}
|
binaryen-archive/src/type.ml
CHANGED
|
@@ -75,5 +75,8 @@ let auto = auto ()
|
|
|
75
75
|
external create : t array -> t = "caml_binaryen_type_create"
|
|
76
76
|
external expand : t -> t array = "caml_binaryen_type_expand"
|
|
77
77
|
external is_nullable : t -> bool = "caml_binaryen_type_is_nullable"
|
|
78
|
-
|
|
78
|
+
|
|
79
|
+
external from_heap_type : Heap_type.t -> bool -> t
|
|
80
|
+
= "caml_binaryen_type_from_heap_type"
|
|
81
|
+
|
|
79
82
|
external get_heap_type : t -> Heap_type.t = "caml_binaryen_type_get_heap_type"
|
binaryen-archive/src/type.mli
CHANGED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#define CAML_NAME_SPACE
|
|
2
|
+
#include <caml/alloc.h>
|
|
3
|
+
#include <caml/mlvalues.h>
|
|
4
|
+
#include <caml/fail.h>
|
|
5
|
+
#include <caml/memory.h>
|
|
6
|
+
|
|
7
|
+
#include "binaryen-c.h"
|
|
8
|
+
#include "ocaml_helpers.h"
|
|
9
|
+
|
|
10
|
+
CAMLprim value
|
|
11
|
+
caml_type_builder_create(value _size) {
|
|
12
|
+
CAMLparam1(_size);
|
|
13
|
+
BinaryenIndex size = Int_val(_size);
|
|
14
|
+
CAMLreturn(alloc_TypeBuilderRef(TypeBuilderCreate(size)));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
CAMLprim value
|
|
18
|
+
caml_type_builder_grow(value _builder, value _count) {
|
|
19
|
+
CAMLparam2(_builder, _count);
|
|
20
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
21
|
+
BinaryenIndex count = Int_val(_count);
|
|
22
|
+
TypeBuilderGrow(builder, count);
|
|
23
|
+
CAMLreturn(Val_unit);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
CAMLprim value
|
|
27
|
+
caml_type_builder_get_size(value _builder) {
|
|
28
|
+
CAMLparam1(_builder);
|
|
29
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
30
|
+
CAMLreturn(Val_int(TypeBuilderGetSize(builder)));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
CAMLprim value
|
|
34
|
+
caml_type_builder_set_signature_type(value _builder, value _index, value _paramTypes, value _resultTypes) {
|
|
35
|
+
CAMLparam4(_builder, _index, _paramTypes, _resultTypes);
|
|
36
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
37
|
+
BinaryenIndex index = Int_val(_index);
|
|
38
|
+
BinaryenType paramTypes = BinaryenType_val(_paramTypes);
|
|
39
|
+
BinaryenType resultTypes = BinaryenType_val(_resultTypes);
|
|
40
|
+
TypeBuilderSetSignatureType(builder, index, paramTypes, resultTypes);
|
|
41
|
+
CAMLreturn(Val_unit);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
CAMLprim value
|
|
45
|
+
caml_type_builder_set_struct_type(value _builder, value _index, value _fieldTypes, value _fieldPackedTypes, value _fieldMutables, value _numFields) {
|
|
46
|
+
CAMLparam5(_builder, _index, _fieldTypes, _fieldPackedTypes, _fieldMutables);
|
|
47
|
+
CAMLxparam1(_numFields);
|
|
48
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
49
|
+
BinaryenIndex index = Int_val(_index);
|
|
50
|
+
_fieldTypes = array_of_list(_fieldTypes);
|
|
51
|
+
int fieldTypesLen = array_length(_fieldTypes);
|
|
52
|
+
BinaryenType fieldTypes[fieldTypesLen];
|
|
53
|
+
for (int i = 0; i < fieldTypesLen; i++) {
|
|
54
|
+
fieldTypes[i] = BinaryenType_val(Field(_fieldTypes, i));
|
|
55
|
+
}
|
|
56
|
+
_fieldPackedTypes = array_of_list(_fieldPackedTypes);
|
|
57
|
+
int fieldPackedTypesLen = array_length(_fieldPackedTypes);
|
|
58
|
+
BinaryenPackedType fieldPackedTypes[fieldPackedTypesLen];
|
|
59
|
+
for (int i = 0; i < fieldPackedTypesLen; i++) {
|
|
60
|
+
fieldPackedTypes[i] = BinaryenPackedType_val(Field(_fieldPackedTypes, i));
|
|
61
|
+
}
|
|
62
|
+
_fieldMutables = array_of_list(_fieldMutables);
|
|
63
|
+
int fieldMutablesLen = array_length(_fieldMutables);
|
|
64
|
+
bool fieldMutables[fieldMutablesLen];
|
|
65
|
+
for (int i = 0; i < fieldMutablesLen; i++) {
|
|
66
|
+
fieldMutables[i] = Bool_val(Field(_fieldMutables, i));
|
|
67
|
+
}
|
|
68
|
+
int numFields = Int_val(_numFields);
|
|
69
|
+
TypeBuilderSetStructType(builder, index, fieldTypes, fieldPackedTypes, fieldMutables, numFields);
|
|
70
|
+
CAMLreturn(Val_unit);
|
|
71
|
+
}
|
|
72
|
+
CAMLprim value
|
|
73
|
+
caml_type_builder_set_struct_type__bytecode(value * argv) {
|
|
74
|
+
return caml_type_builder_set_struct_type(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
CAMLprim value
|
|
78
|
+
caml_type_builder_set_array_type(value _builder, value _index, value _elementType, value _elementPackedType, value _elementMutable) {
|
|
79
|
+
CAMLparam5(_builder, _index, _elementType, _elementPackedType, _elementMutable);
|
|
80
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
81
|
+
BinaryenIndex index = Int_val(_index);
|
|
82
|
+
BinaryenType elementType = BinaryenType_val(_elementType);
|
|
83
|
+
BinaryenPackedType elementPackedType = BinaryenPackedType_val(_elementPackedType);
|
|
84
|
+
bool elementMutable = Bool_val(_elementMutable);
|
|
85
|
+
TypeBuilderSetArrayType(builder, index, elementType, elementPackedType, elementMutable);
|
|
86
|
+
CAMLreturn(Val_unit);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
CAMLprim value
|
|
90
|
+
caml_type_builder_get_temp_heap_type(value _builder, value _index) {
|
|
91
|
+
CAMLparam2(_builder, _index);
|
|
92
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
93
|
+
BinaryenIndex index = Int_val(_index);
|
|
94
|
+
CAMLreturn(alloc_BinaryenHeapType(TypeBuilderGetTempHeapType(builder, index)));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
CAMLprim value
|
|
98
|
+
caml_type_builder_get_temp_tuple_type(value _builder, value _types) {
|
|
99
|
+
CAMLparam2(_builder, _types);
|
|
100
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
101
|
+
_types = array_of_list(_types);
|
|
102
|
+
int typesLen = array_length(_types);
|
|
103
|
+
BinaryenType types[typesLen];
|
|
104
|
+
for (int i = 0; i < typesLen; i++) {
|
|
105
|
+
types[i] = BinaryenType_val(Field(_types, i));
|
|
106
|
+
}
|
|
107
|
+
CAMLreturn(alloc_BinaryenType(TypeBuilderGetTempTupleType(builder, types, typesLen)));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
CAMLprim value
|
|
111
|
+
caml_type_builder_get_temp_ref_type(value _builder, value _heapType, value _nullable) {
|
|
112
|
+
CAMLparam3(_builder, _heapType, _nullable);
|
|
113
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
114
|
+
BinaryenHeapType heapType = BinaryenHeapType_val(_heapType);
|
|
115
|
+
bool nullable = Bool_val(_nullable);
|
|
116
|
+
CAMLreturn(alloc_BinaryenType(TypeBuilderGetTempRefType(builder, heapType, nullable)));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
CAMLprim value
|
|
120
|
+
caml_type_builder_set_sub_type(value _builder, value _index, value _superType) {
|
|
121
|
+
CAMLparam3(_builder, _index, _superType);
|
|
122
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
123
|
+
BinaryenIndex index = Int_val(_index);
|
|
124
|
+
BinaryenHeapType superType = BinaryenHeapType_val(_superType);
|
|
125
|
+
TypeBuilderSetSubType(builder, index, superType);
|
|
126
|
+
CAMLreturn(Val_unit);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
CAMLprim value
|
|
130
|
+
caml_type_builder_set_open(value _builder, value _index) {
|
|
131
|
+
CAMLparam2(_builder, _index);
|
|
132
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
133
|
+
BinaryenIndex index = Int_val(_index);
|
|
134
|
+
TypeBuilderSetOpen(builder, index);
|
|
135
|
+
CAMLreturn(Val_unit);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
CAMLprim value
|
|
139
|
+
caml_type_builder_create_rec_group(value _builder, value _index, value _length) {
|
|
140
|
+
CAMLparam3(_builder, _index, _length);
|
|
141
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
142
|
+
BinaryenIndex index = Int_val(_index);
|
|
143
|
+
BinaryenIndex length = Int_val(_length);
|
|
144
|
+
TypeBuilderCreateRecGroup(builder, index, length);
|
|
145
|
+
CAMLreturn(Val_unit);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
CAMLprim value
|
|
149
|
+
caml_conv_heap_type(BinaryenHeapType heapType) {
|
|
150
|
+
return alloc_BinaryenHeapType(heapType);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
CAMLprim value caml_type_builder_build_and_dispose(value _builder) {
|
|
154
|
+
CAMLparam1(_builder);
|
|
155
|
+
CAMLlocal5(arr, ok, error, tuple, field);
|
|
156
|
+
TypeBuilderRef builder = TypeBuilderRef_val(_builder);
|
|
157
|
+
BinaryenIndex size = TypeBuilderGetSize(builder);
|
|
158
|
+
BinaryenHeapType heapTypes[size + 1];
|
|
159
|
+
BinaryenIndex errorIndex;
|
|
160
|
+
TypeBuilderErrorReason errorReason;
|
|
161
|
+
bool success =
|
|
162
|
+
TypeBuilderBuildAndDispose(builder, heapTypes, &errorIndex, &errorReason);
|
|
163
|
+
if (success) {
|
|
164
|
+
arr = caml_alloc(size, 0);
|
|
165
|
+
for (mlsize_t i = 0; i < (mlsize_t)size; i++) {
|
|
166
|
+
field = alloc_BinaryenHeapType(heapTypes[i]);
|
|
167
|
+
Store_field(arr, i, field);
|
|
168
|
+
}
|
|
169
|
+
ok = caml_alloc_small(1, 0);
|
|
170
|
+
Store_field(ok, 0, arr);
|
|
171
|
+
CAMLreturn(ok);
|
|
172
|
+
} else {
|
|
173
|
+
error = caml_alloc_small(1, 1);
|
|
174
|
+
tuple = caml_alloc_small(2, 0);
|
|
175
|
+
Field(tuple, 0) = Val_int(errorIndex);
|
|
176
|
+
Field(tuple, 1) = Val_int(errorReason);
|
|
177
|
+
Store_field(error, 0, tuple);
|
|
178
|
+
CAMLreturn(error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//Provides: caml_type_builder_create
|
|
2
|
+
//Requires: Binaryen
|
|
3
|
+
function caml_type_builder_create(size) {
|
|
4
|
+
return new Binaryen.TypeBuilder(size);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//Provides: caml_type_builder_grow
|
|
8
|
+
function caml_type_builder_grow(builder, count) {
|
|
9
|
+
builder.grow(count);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//Provides: caml_type_builder_get_size
|
|
13
|
+
function caml_type_builder_get_size(builder) {
|
|
14
|
+
return builder.getSize();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//Provides: caml_type_builder_set_signature_type
|
|
18
|
+
function caml_type_builder_set_signature_type(
|
|
19
|
+
builder,
|
|
20
|
+
index,
|
|
21
|
+
paramTypes,
|
|
22
|
+
resultTypes
|
|
23
|
+
) {
|
|
24
|
+
builder.setSignatureType(index, paramTypes, resultTypes);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//Provides: caml_type_builder_set_struct_type
|
|
28
|
+
//Requires: caml_list_to_js_array
|
|
29
|
+
//Requires: caml_js_from_bool
|
|
30
|
+
function caml_type_builder_set_struct_type(
|
|
31
|
+
builder,
|
|
32
|
+
index,
|
|
33
|
+
fieldTypes,
|
|
34
|
+
fieldPackedTypes,
|
|
35
|
+
fieldMutables,
|
|
36
|
+
numFields
|
|
37
|
+
) {
|
|
38
|
+
var types = caml_list_to_js_array(fieldTypes);
|
|
39
|
+
var packedTypes = caml_list_to_js_array(fieldPackedTypes);
|
|
40
|
+
var mutables = caml_list_to_js_array(fieldMutables);
|
|
41
|
+
var fields = types.map(function (type, idx) {
|
|
42
|
+
return {
|
|
43
|
+
type,
|
|
44
|
+
packedType: packedTypes[idx],
|
|
45
|
+
mutable: caml_js_from_bool(mutables[idx]),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
builder.setStructType(index, fields);
|
|
49
|
+
}
|
|
50
|
+
//Provides: caml_type_builder_set_struct_type__bytecode
|
|
51
|
+
//Requires: caml_type_builder_set_struct_type
|
|
52
|
+
function caml_type_builder_set_struct_type__bytecode() {
|
|
53
|
+
return caml_type_builder_set_struct_type(
|
|
54
|
+
arguments[0],
|
|
55
|
+
arguments[1],
|
|
56
|
+
arguments[2],
|
|
57
|
+
arguments[3],
|
|
58
|
+
arguments[4],
|
|
59
|
+
arguments[5]
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//Provides: caml_type_builder_set_array_type
|
|
64
|
+
function caml_type_builder_set_array_type(
|
|
65
|
+
builder,
|
|
66
|
+
index,
|
|
67
|
+
elementType,
|
|
68
|
+
elementPackedType,
|
|
69
|
+
elementMutable
|
|
70
|
+
) {
|
|
71
|
+
builder.setArrayType(index, elementType, elementPackedType, elementMutable);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//Provides: caml_type_builder_get_temp_heap_type
|
|
75
|
+
function caml_type_builder_get_temp_heap_type(builder, index) {
|
|
76
|
+
return builder.getTempHeapType(index);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//Provides: caml_type_builder_get_temp_tuple_type
|
|
80
|
+
//Requires: caml_list_to_js_array
|
|
81
|
+
function caml_type_builder_get_temp_tuple_type(builder, types) {
|
|
82
|
+
var tupleTypes = caml_list_to_js_array(types);
|
|
83
|
+
return builder.getTempTupleType(tupleTypes);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//Provides: caml_type_builder_get_temp_ref_type
|
|
87
|
+
//Requires: caml_js_from_bool
|
|
88
|
+
function caml_type_builder_get_temp_ref_type(builder, heapType, nullable) {
|
|
89
|
+
return builder.getTempRefType(heapType, caml_js_from_bool(nullable));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//Provides: caml_type_builder_set_sub_type
|
|
93
|
+
function caml_type_builder_set_sub_type(builder, index, superType) {
|
|
94
|
+
builder.setSubType(index, superType);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//Provides: caml_type_builder_set_open
|
|
98
|
+
function caml_type_builder_set_open(builder, index) {
|
|
99
|
+
builder.setOpen(index);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//Provides: caml_type_builder_create_rec_group
|
|
103
|
+
function caml_type_builder_create_rec_group(builder, index, length) {
|
|
104
|
+
builder.createRecGroup(index, length);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//Provides: caml_type_builder_build_and_dispose
|
|
108
|
+
//Requires: caml_js_to_array
|
|
109
|
+
function caml_type_builder_build_and_dispose(builder) {
|
|
110
|
+
try {
|
|
111
|
+
var types = builder.buildAndDispose();
|
|
112
|
+
return [0, caml_js_to_array(types)];
|
|
113
|
+
} catch (e) {
|
|
114
|
+
return [1, [0, e.index, e.reason]];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
type t
|
|
2
|
+
|
|
3
|
+
type struct_field = {
|
|
4
|
+
type_ : Type.t;
|
|
5
|
+
packed_type : Packed_type.t;
|
|
6
|
+
mutable_ : bool;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
(* Source: https://github.com/WebAssembly/binaryen/blob/64ba23996a10e229d46e41eb37736a55af87f79a/src/binaryen-c.h#L3618 *)
|
|
10
|
+
type error =
|
|
11
|
+
| SelfSupertype of int
|
|
12
|
+
| InvalidSupertype of int
|
|
13
|
+
| ForwardSupertypeReference of int
|
|
14
|
+
| ForwardChildReference of int
|
|
15
|
+
|
|
16
|
+
external make : int -> t = "caml_type_builder_create"
|
|
17
|
+
external grow : t -> int -> unit = "caml_type_builder_grow"
|
|
18
|
+
external size : t -> int = "caml_type_builder_get_size"
|
|
19
|
+
|
|
20
|
+
external set_signature_type : t -> int -> Type.t -> Type.t -> unit
|
|
21
|
+
= "caml_type_builder_set_signature_type"
|
|
22
|
+
|
|
23
|
+
external set_struct_type :
|
|
24
|
+
t -> int -> Type.t list -> Packed_type.t list -> bool list -> int -> unit
|
|
25
|
+
= "caml_type_builder_set_struct_type__bytecode"
|
|
26
|
+
"caml_type_builder_set_struct_type"
|
|
27
|
+
|
|
28
|
+
let set_struct_type builder index fields =
|
|
29
|
+
let split_fields fields =
|
|
30
|
+
List.fold_right
|
|
31
|
+
(fun { type_; packed_type; mutable_ } (types, packed_types, mutables) ->
|
|
32
|
+
(type_ :: types, packed_type :: packed_types, mutable_ :: mutables))
|
|
33
|
+
fields ([], [], [])
|
|
34
|
+
in
|
|
35
|
+
let types, packed_types, mutables = split_fields fields in
|
|
36
|
+
set_struct_type builder index types packed_types mutables (List.length types)
|
|
37
|
+
|
|
38
|
+
external set_array_type : t -> int -> Type.t -> Packed_type.t -> bool -> unit
|
|
39
|
+
= "caml_type_builder_set_array_type"
|
|
40
|
+
|
|
41
|
+
external get_temp_heap_type : t -> int -> Heap_type.t
|
|
42
|
+
= "caml_type_builder_get_temp_heap_type"
|
|
43
|
+
|
|
44
|
+
external get_temp_tuple_type : t -> Type.t list -> Type.t
|
|
45
|
+
= "caml_type_builder_get_temp_tuple_type"
|
|
46
|
+
|
|
47
|
+
external get_temp_ref_type : t -> Heap_type.t -> bool -> Type.t
|
|
48
|
+
= "caml_type_builder_get_temp_ref_type"
|
|
49
|
+
|
|
50
|
+
external set_sub_type : t -> int -> Heap_type.t -> unit
|
|
51
|
+
= "caml_type_builder_set_sub_type"
|
|
52
|
+
|
|
53
|
+
external set_open : t -> int -> unit = "caml_type_builder_set_open"
|
|
54
|
+
|
|
55
|
+
external create_rec_group : t -> int -> int -> unit
|
|
56
|
+
= "caml_type_builder_create_rec_group"
|
|
57
|
+
|
|
58
|
+
external build_and_dispose : t -> (Heap_type.t array, int * int) result
|
|
59
|
+
= "caml_type_builder_build_and_dispose"
|
|
60
|
+
|
|
61
|
+
let build_and_dispose builder =
|
|
62
|
+
match build_and_dispose builder with
|
|
63
|
+
| Ok types -> Ok (Array.to_list types)
|
|
64
|
+
| Error (idx, 0) -> Error (SelfSupertype idx)
|
|
65
|
+
| Error (idx, 1) -> Error (InvalidSupertype idx)
|
|
66
|
+
| Error (idx, 2) -> Error (ForwardSupertypeReference idx)
|
|
67
|
+
| Error (idx, _) -> Error (ForwardChildReference idx)
|