jon.recoil.org

Module Flambda2_to_jsir.To_jsir_result

Result structure used during Flambda to Js_of_ocaml IR translation.

An accumulator for the JSIR blocks and instructions.

Values of type t store complete/archived blocks, as well as a stack of "current" blocks that is still being worked on.

type t
val create : unit -> t

Create a new result structure. It is not initialised with any blocks.

val add_instr_exn : t -> Jsoo_imports.Import.Jsir.instr -> t

Add a Jsir.instr to the top of the stack of current blocks and return the address of the new block. This function raises if there are no blocks being worked on.

val maybe_add_debuginfo_exn : t -> Debuginfo.t -> pos:[ `Start | `End ] -> t

Add debugging information as an Event if it is not _none_. Raises if there are no blocks being worked on. pos controls whether we log the start of the region or the end.

val with_debuginfo_exn : t -> Debuginfo.t -> f:(t -> 'a * t) -> 'a * t

Wrap any result changes between `Start and `End debuginfos. Raises if there are no blocks being worked on.

val new_block : t -> params:Jsoo_imports.Import.Jsir.Var.t list -> t * Jsoo_imports.Import.Jsir.Addr.t

Push a new block to the stack of current blocks.

val reserve_address : t -> t * Jsoo_imports.Import.Jsir.Addr.t

Return a new address without actually creating a block corresponding to that address. This is used for recursive continuations, where we need to use the address of a continuation before actually translating the body. The caller should promise that they call new_block_with_addr with the returned address at some point before to_program_exn is called.

val new_block_with_addr_exn : t -> params:Jsoo_imports.Import.Jsir.Var.t list -> addr:Jsoo_imports.Import.Jsir.Addr.t -> t

Make a new block, but using addr. Raises if addr is not a reserved address.

val end_block_with_last_exn : t -> Jsoo_imports.Import.Jsir.last -> t

End the block at the top of the current stack, setting last to the given argument. This function raises if there are no blocks being worked on.

val invalid_switch_block : t -> t * Jsoo_imports.Import.Jsir.Addr.t

Returns the address for a special block for invalid switches, creating one if it doesn't exist already.

val get_public_method : t -> obj:Jsoo_imports.Import.Jsir.Var.t -> field:Jsoo_imports.Import.Jsir.Var.t -> t * Jsoo_imports.Import.Jsir.Var.t

Get a public method and return the function. Increments the method cache ID.

val import_compilation_unit : t -> Compilation_unit.t -> t

Register the fact that we import the (toplevel module of the) given compilation unit from the JSOO global data table. This is used to inform Js_of_ocaml that it needs to add this compilation unit to the global data table.

val global_data_var : t -> t * Jsoo_imports.Import.Jsir.Var.t
type program = {
  1. program : Jsoo_imports.Import.Jsir.program;
  2. imported_compilation_units : Compilation_unit.Set.t;
}
val to_program_exn : t -> program

Create a program with the blocks in the result, including the current block. This function raises if there are still blocks being worked on, or there is a reserved address that has not been used yet.