Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
OCaml Binaryen DSL
This library helps you to write Webassembly text format(WAT) in OCaml source code with DSL. It helps you to write a code generator for your language to WASM.
open Binaryen_dsl.Dsl
let codegen_retain_object m =
let module Dsl =
Binaryen(struct
let ptr_ty = i32
let m = m
end)
in
let open Dsl in
let _ = def_function "retain_counter" ~params:[ ptr_ty ] ~ret_ty:none (fun ctx ->
let next_count = def_local ctx i32 in
block [
(* next_count <- obj->strong_counter *)
local_set next_count (I32.load ~offset:8 (Ptr.local_get 0));
(* next_count <- next_count + 1 *)
local_set next_count I32.((local_get next_count) + (const_i32_of_int 1));
(* obj->strong_counter <- next_count *)
I32.store ~offset:8 ~ptr:(Ptr.local_get 0) (I32.local_get next_count);
]
)
in
let _ = export_function "retain_counter" "retain_counter" in ()
let () =
let m = module_create() in
codegen_retain_object m;
print_endline (emit_text m)