Skip to content

Commit becea05

Browse files
committed
feat!: Upgrade to Binaryen v129
Full Diff: WebAssembly/binaryen@version_128...version_129 API Additions: * Data_segment * Data_segment.get_num_segments * Data_segment.get_segment * Data_segment.get_segment_by_index * Data_segment.get_segment_name * Data_segment.get_segment_byte_offset * Data_segment.get_segment_byte_length * Data_segment.get_segment_passive * Data_segment.get_segment_data * Module.Feature.multibyte API Changes: * Table.add_table -> Now takes an optional `init` expression API Removals: * Memory.get_num_segments -> became Data_segment.get_num_segments * Memory.get_segment_byte_offset -> became Data_segment.get_segment_byte_offset * Memory.get_segment_passive -> became Data_segment.get_segment_passive * Memory.get_segment_data -> became Data_segment.get_segment_data NOTE: This needs the prs for v126, v127 & v128 merged first. This is blocked on libbinaryen v129 releasing
1 parent 65f71e8 commit becea05

30 files changed

Lines changed: 463 additions & 271 deletions

binaryen.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ depends: [
1616
"dune" {>= "3.0.0"}
1717
"dune-configurator" {>= "3.0.0"}
1818
"js_of_ocaml-compiler" {>= "6.0.0" < "7.0.0"}
19-
"libbinaryen" {>= "128.0.0" < "129.0.0"}
19+
"libbinaryen" {>= "129.0.0" < "130.0.0"}
2020
]
2121
x-maintenance-intent: ["0.(latest)"]

esy.lock/index.json

Lines changed: 149 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esy.lock/opam/dune-configurator.3.22.0/opam renamed to esy.lock/opam/dune-configurator.3.22.1/opam

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"resolutions": {
2222
"@opam/ocp-indent": "1.9.0",
23-
"@grain/libbinaryen": "git+https://github.com/grain-lang/libbinaryen.git#a51764b23fc63415cf19e375e6d6fcdb6f756d38"
23+
"@grain/libbinaryen": "git+https://github.com/grain-lang/libbinaryen.git#f34739d7270408fc1069dbe6bb3c7068e07fef06"
2424
},
2525
"esy": {
2626
"build": "dune build -p binaryen"

src/data_segment.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#define CAML_NAME_SPACE
2+
#include <caml/mlvalues.h>
3+
#include <caml/fail.h>
4+
#include <caml/memory.h>
5+
#include <caml/alloc.h>
6+
7+
#include "binaryen-c.h"
8+
#include "ocaml_helpers.h"
9+
10+
11+
CAMLprim value
12+
caml_binaryen_get_num_memory_segments(value _module) {
13+
CAMLparam1(_module);
14+
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
15+
CAMLreturn(Val_int(BinaryenGetNumMemorySegments(module)));
16+
}
17+
18+
CAMLprim value caml_binaryen_get_data_segment(value _module, value _name) {
19+
CAMLparam2(_module, _name);
20+
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
21+
char* name = Safe_String_val(_name);
22+
BinaryenDataSegmentRef segment = BinaryenGetDataSegment(module, name);
23+
if (segment == NULL) {
24+
CAMLreturn(Val_none);
25+
} else {
26+
CAMLreturn(caml_alloc_some(alloc_BinaryenDataSegmentRef(segment)));
27+
}
28+
}
29+
30+
CAMLprim value caml_binaryen_get_data_segment_by_index(value _module, value _index) {
31+
CAMLparam2(_module, _index);
32+
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
33+
int index = Int_val(_index);
34+
BinaryenDataSegmentRef segment = BinaryenGetDataSegmentByIndex(module, index);
35+
CAMLreturn(alloc_BinaryenDataSegmentRef(segment));
36+
}
37+
38+
CAMLprim value caml_binaryen_data_segment_get_name(value _module, value _segment) {
39+
CAMLparam2(_module, _segment);
40+
BinaryenDataSegmentRef segment = BinaryenDataSegmentRef_val(_segment);
41+
const char* name = BinaryenDataSegmentGetName(segment);
42+
CAMLreturn(caml_copy_string(name));
43+
}
44+
45+
CAMLprim value
46+
caml_binaryen_get_memory_segment_byte_offset(value _module, value _segment) {
47+
CAMLparam2(_module, _segment);
48+
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
49+
BinaryenDataSegmentRef segment = BinaryenDataSegmentRef_val(_segment);
50+
if (BinaryenGetMemorySegmentPassive(segment)) {
51+
CAMLreturn(Val_none);
52+
} else {
53+
int offset = BinaryenGetMemorySegmentByteOffset(module, segment);
54+
CAMLreturn(caml_alloc_some(Val_int(offset)));
55+
}
56+
}
57+
58+
CAMLprim value
59+
caml_binaryen_get_memory_segment_byte_length(value _segment) {
60+
CAMLparam1(_segment);
61+
BinaryenDataSegmentRef segment = BinaryenDataSegmentRef_val(_segment);
62+
int length = BinaryenGetMemorySegmentByteLength(segment);
63+
CAMLreturn(Val_int(length));
64+
}
65+
66+
CAMLprim value
67+
caml_binaryen_get_memory_segment_passive(value _segment) {
68+
CAMLparam1(_segment);
69+
BinaryenDataSegmentRef segment = BinaryenDataSegmentRef_val(_segment);
70+
CAMLreturn(Val_bool(BinaryenGetMemorySegmentPassive(segment)));
71+
}
72+
73+
CAMLprim value
74+
caml_binaryen_get_memory_segment_data(value _module, value _segment) {
75+
CAMLparam2(_module, _segment);
76+
BinaryenDataSegmentRef segment = BinaryenDataSegmentRef_val(_segment);
77+
size_t size = BinaryenGetMemorySegmentByteLength(segment);
78+
CAMLprim value bytes = caml_alloc_string(size);
79+
BinaryenCopyMemorySegmentData(segment, (char*)Bytes_val(bytes));
80+
CAMLreturn(bytes);
81+
}

src/data_segment.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
//Provides: caml_binaryen_get_num_memory_segments
3+
function caml_binaryen_get_num_memory_segments(wasm_mod) {
4+
return wasm_mod.getNumMemorySegments();
5+
}
6+
7+
//Provides: caml_binaryen_get_data_segment
8+
//Requires: caml_jsstring_of_string, to_option
9+
function caml_binaryen_get_data_segment(wasm_mod, name) {
10+
return to_option(wasm_mod.getDataSegment(caml_jsstring_of_string(name)));
11+
}
12+
13+
//Provides: caml_binaryen_get_data_segment_by_index
14+
function caml_binaryen_get_data_segment_by_index(wasm_mod, index) {
15+
return wasm_mod.getDataSegmentByIndex(index);
16+
}
17+
18+
// Provides: caml_binaryen_data_segment_get_name
19+
// Requires: caml_string_of_jsstring
20+
function caml_binaryen_data_segment_get_name(wasm_mod, segment) {
21+
var info = wasm_mod.getMemorySegmentInfo(segment);
22+
return caml_string_of_jsstring(info.name);
23+
}
24+
25+
//Provides: caml_binaryen_get_memory_segment_byte_offset
26+
//Requires: to_option
27+
function caml_binaryen_get_memory_segment_byte_offset(wasm_mod, segment) {
28+
var info = wasm_mod.getMemorySegmentInfo(segment);
29+
return to_option(info.offset);
30+
}
31+
32+
//Provides: caml_binaryen_get_memory_segment_byte_length
33+
//Requires: Binaryen
34+
function caml_binaryen_get_memory_segment_byte_length(segment) {
35+
return Binaryen._BinaryenGetMemorySegmentByteLength(segment);
36+
}
37+
38+
//Provides: caml_binaryen_get_memory_segment_passive
39+
//Requires: Binaryen
40+
function caml_binaryen_get_memory_segment_passive(segment) {
41+
return Binaryen._BinaryenGetMemorySegmentPassive(segment);
42+
}
43+
44+
//Provides: caml_binaryen_get_memory_segment_data
45+
//Requires: caml_bytes_of_array
46+
function caml_binaryen_get_memory_segment_data(wasm_mod, segment) {
47+
var info = wasm_mod.getMemorySegmentInfo(segment);
48+
return caml_bytes_of_array(info.data);
49+
}

0 commit comments

Comments
 (0)