Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Conversion of i64 literals #96

Merged
merged 5 commits into from Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions js/expression.ml
Expand Up @@ -115,18 +115,17 @@ let const wasm_mod lit =
| Int32 value ->
let scope = get wasm_mod "i32" in
meth_call scope "const" [| inject value |]
| Int64 value ->
| Int64 (low, high) ->
let scope = get wasm_mod "i64" in
meth_call scope "const" [| inject value |]
meth_call scope "const" [| inject low; inject high |]
| Float32Bits value ->
let scope = get wasm_mod "f32" in
meth_call scope "const_bits" [| inject value |]
| Float64Bits value ->
| Float64Bits (low, high) ->
let scope = get wasm_mod "f64" in
meth_call scope "const_bits" [| inject value |]
meth_call scope "const_bits" [| inject low; inject high |]
| Float32 value ->
let scope = get wasm_mod "f32" in
(* TODO: Investigate if this needs the Int32 conversion stuff *)
meth_call scope "const" [| inject value |]
| Float64 value ->
let scope = get wasm_mod "f64" in
Expand Down
12 changes: 8 additions & 4 deletions js/literal.ml
@@ -1,21 +1,25 @@
(* This is a hack around Binaryen's stack allocations *)
type jsoo =
| Int32 of int32
| Int64 of int64
| Int64 of int32 * int32
| Float32Bits of int32
| Float64Bits of int64
| Float64Bits of int32 * int32
| Float32 of float
| Float64 of float

type t = jsoo

let int32 value = Int32 value

let int64 value = Int64 value
let int64 value =
Int64
(Int64.to_int32 value, Int64.to_int32 (Int64.shift_right_logical value 32))

let float32_bits value = Float32Bits value

let float64_bits value = Float64Bits value
let float64_bits value =
Float64Bits
(Int64.to_int32 value, Int64.to_int32 (Int64.shift_right_logical value 32))

let float32 value = Float32 value

Expand Down
4 changes: 2 additions & 2 deletions src/literal.ml
Expand Up @@ -15,9 +15,9 @@ external float64 : float -> t = "caml_binaryen_literal_float64"
(* Hacks for Binaryen.js stack allocations, Don't use in binaryen.native *)
type jsoo =
| Int32 of int32
| Int64 of int64
| Int64 of int32 * int32
| Float32Bits of int32
| Float64Bits of int64
| Float64Bits of int32 * int32
| Float32 of float
| Float64 of float

Expand Down
2 changes: 2 additions & 0 deletions test/test.expected
Expand Up @@ -4,6 +4,8 @@
(memory $0 1)
(table $table 1 1 funcref)
(elem (i32.const 0) $adder)
(global $max_int64 i64 (i64.const 9223372036854775807))
(global $test_float64_bits f64 (f64.const 1.23))
(export "adder" (func $adder))
(export "memory" (memory $0))
(start $start)
Expand Down
8 changes: 8 additions & 0 deletions test/test.ml
Expand Up @@ -48,6 +48,14 @@ let start =

let _ = Export.add_function_export wasm_mod "adder" "adder"

let _ =
Global.add_global wasm_mod "max_int64" Type.int64 false
(Expression.const wasm_mod (Literal.int64 Int64.max_int))

let _ =
Global.add_global wasm_mod "test_float64_bits" Type.float64 false
(Expression.const wasm_mod (Literal.float64_bits 0x3FF3AE147AE147AEL))

let _ =
Table.add_table wasm_mod "table" 1 1 [ "adder" ]
(Expression.const wasm_mod (Literal.int32 0l))
Expand Down
4 changes: 2 additions & 2 deletions virtual/literal.mli
Expand Up @@ -15,9 +15,9 @@ val float64 : float -> t
(* Hacks for Binaryen.js stack allocations *)
type jsoo =
| Int32 of int32
| Int64 of int64
| Int64 of int32 * int32
| Float32Bits of int32
| Float64Bits of int64
| Float64Bits of int32 * int32
| Float32 of float
| Float64 of float

Expand Down