Skip to content

Commit

Permalink
chore: Add missing vec128 literal type
Browse files Browse the repository at this point in the history
  • Loading branch information
peblair committed Oct 22, 2023
1 parent 74c8ce4 commit 95a1949
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/literal.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ caml_binaryen_literal_float64_bits(value _i64) {
struct BinaryenLiteral lit = BinaryenLiteralFloat64Bits(i64);
CAMLreturn(alloc_BinaryenLiteral(lit));
}

CAMLprim value
caml_binaryen_literal_vec128(value _x) {
CAMLparam1(_x);
const uint8_t* x = (uint8_t*)Safe_Bytes_val(_x);
BinaryenLiteral lit = BinaryenLiteralVec128(x);
CAMLreturn(alloc_BinaryenLiteral(lit));
}
6 changes: 6 additions & 0 deletions src/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ function caml_binaryen_literal_float64_bits(i64) {
// Hack around Binaryen.js
return { type: 'float64_bits', value: i64 };
}

//Provides: caml_binaryen_literal_vec128
function caml_binaryen_literal_vec128(x) {
// Hack around Binaryen.js
return { type: 'vec_128', value: i64 };
}
1 change: 1 addition & 0 deletions src/literal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ external int32 : int32 -> t = "caml_binaryen_literal_int32"
external int64 : int64 -> t = "caml_binaryen_literal_int64"
external float32_bits : int32 -> t = "caml_binaryen_literal_float32_bits"
external float64_bits : int64 -> t = "caml_binaryen_literal_float64_bits"
external vec128 : Bytes.t -> t = "caml_binaryen_literal_vec128"

let float32 n = float32_bits @@ Int32.bits_of_float n

Expand Down
1 change: 1 addition & 0 deletions src/literal.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ val float32_bits : int32 -> t
val float64_bits : int64 -> t
val float32 : float -> t
val float64 : float -> t
val vec128 : Bytes.t -> t
1 change: 1 addition & 0 deletions src/ocaml_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static struct custom_operations binaryen_ops = {
#define Is_some(v) Is_block(v)

#define Safe_String_val(v) ((char *)memcpy(malloc(caml_string_length(v) + 1), String_val(v), caml_string_length(v) + 1))
#define Safe_Bytes_val(v) ((char *)memcpy(malloc(caml_string_length(v) + 1), Bytes_val(v), caml_string_length(v) + 1))

/* Allocating an OCaml custom block to hold the given BinaryenFunctionRef */
value alloc_BinaryenFunctionRef(BinaryenFunctionRef fun);
Expand Down

0 comments on commit 95a1949

Please sign in to comment.