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: provide type to select instruction #46

Merged
merged 2 commits into from Jan 9, 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
4 changes: 3 additions & 1 deletion src/expression.ml
Expand Up @@ -65,7 +65,9 @@ external unary : Module.t -> Op.t -> t -> t = "caml_binaryen_unary"

external binary : Module.t -> Op.t -> t -> t -> t = "caml_binaryen_binary"

external select : Module.t -> t -> t -> t -> t = "caml_binaryen_select"
external select : Module.t -> t -> t -> t -> Type.t -> t = "caml_binaryen_select"
let select wasm_mod cond tru fals =
select wasm_mod cond tru fals Type.auto
(** Module, condition, true branch, false branch. *)

external drop : Module.t -> t -> t = "caml_binaryen_drop"
Expand Down
12 changes: 10 additions & 2 deletions test/test.expected
Expand Up @@ -3,7 +3,11 @@
(func $adder (param $0 i32) (param $1 i32) (result i32)
(block $add (result i32)
(i32.add
(local.get $0)
(select
(local.get $0)
(local.get $1)
(i32.const 1)
)
(local.get $1)
)
)
Expand All @@ -13,7 +17,11 @@
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(func $0 (param $0 i32) (param $1 i32) (result i32)
(i32.add
(local.get $0)
(select
(local.get $0)
(local.get $1)
(i32.const 1)
)
(local.get $1)
)
)
Expand Down
4 changes: 3 additions & 1 deletion test/test.ml
Expand Up @@ -12,7 +12,9 @@ let x = Expression.local_get wasm_mod 0 Type.int32

let y = Expression.local_get wasm_mod 1 Type.int32

let add = Expression.block wasm_mod ~return_type:Type.int32 "add" [Expression.binary wasm_mod Op.add_int32 x y]
let select = Expression.select wasm_mod (Expression.const wasm_mod (Literal.int32 1l)) x y

let add = Expression.block wasm_mod ~return_type:Type.int32 "add" [Expression.binary wasm_mod Op.add_int32 select y]

(* Create the add function *)
let adder = Function.add_function wasm_mod "adder" params results [||] add
Expand Down