From 95a1949487a4a538682346dc909c49d3a544069f Mon Sep 17 00:00:00 2001 From: Philip Blair Date: Sun, 22 Oct 2023 18:43:41 +0200 Subject: [PATCH] chore: Add missing vec128 literal type --- src/literal.c | 8 ++++++++ src/literal.js | 6 ++++++ src/literal.ml | 1 + src/literal.mli | 1 + src/ocaml_helpers.h | 1 + 5 files changed, 17 insertions(+) diff --git a/src/literal.c b/src/literal.c index 2d3a9e8b..2370f070 100644 --- a/src/literal.c +++ b/src/literal.c @@ -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)); +} diff --git a/src/literal.js b/src/literal.js index fe11e970..69b7381b 100644 --- a/src/literal.js +++ b/src/literal.js @@ -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 }; +} diff --git a/src/literal.ml b/src/literal.ml index 477d6d65..b049727c 100644 --- a/src/literal.ml +++ b/src/literal.ml @@ -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 diff --git a/src/literal.mli b/src/literal.mli index 9efe03a9..b2fe0d7b 100644 --- a/src/literal.mli +++ b/src/literal.mli @@ -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 diff --git a/src/ocaml_helpers.h b/src/ocaml_helpers.h index 3e926eaf..1c23fa96 100644 --- a/src/ocaml_helpers.h +++ b/src/ocaml_helpers.h @@ -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);