Cmm_helpersval bind : string -> Cmm.expression -> (Cmm.expression -> Cmm.expression) -> Cmm.expressionbind name arg fn is equivalent to let name = arg in fn name, or simply fn arg if arg is simple enough
val bind_load : string -> Cmm.expression -> (Cmm.expression -> Cmm.expression) -> Cmm.expressionSame as bind, but also treats loads from a variable as simple
val bind_nonvar : string -> Cmm.expression -> (Cmm.expression -> Cmm.expression) -> Cmm.expressionSame as bind, but does not treat variables as simple
Headers
val floatarray_tag : Debuginfo.t -> Cmm.expressionA constant equal to the tag for float arrays
block_header tag size creates a header with tag tag for a block of size size
Closure info for a closure of given arity and distance to environment
val alloc_float_header : Debuginfo.t -> Cmm.expressionWrappers
val alloc_floatarray_header : int -> Debuginfo.t -> Cmm.expressionval alloc_closure_header : int -> Debuginfo.t -> Cmm.expressionval alloc_infix_header : int -> Debuginfo.t -> Cmm.expressionval alloc_closure_info : arity:int -> startenv:int -> Debuginfo.t -> Cmm.expressionval alloc_boxedint32_header : Debuginfo.t -> Cmm.expressionval alloc_boxedint64_header : Debuginfo.t -> Cmm.expressionval alloc_boxedintnat_header : Debuginfo.t -> Cmm.expressionIntegers
Minimal/maximal OCaml integer values whose backend representation fits in a regular OCaml integer
val int_const : Debuginfo.t -> int -> Cmm.expressionMake an integer constant from the given integer (tags the integer)
val cint_const : int -> Cmm.data_itemval targetint_const : int -> Targetint.tval natint_const_untagged : Debuginfo.t -> Nativeint.t -> Cmm.expressionMake a Cmm constant holding the given nativeint value. Uses Cconst_int instead of Cconst_nativeint when possible to preserve peephole optimisations.
val add_const : Cmm.expression -> int -> Debuginfo.t -> Cmm.expressionAdd an integer to the given expression
val incr_int : Cmm.expression -> Debuginfo.t -> Cmm.expressionIncrement/decrement of integers
val decr_int : Cmm.expression -> Debuginfo.t -> Cmm.expressionval ignore_low_bit_int : Cmm.expression -> Cmm.expressionSimplify the given expression knowing its last bit will be irrelevant
val ignore_high_bit_int : Cmm.expression -> Cmm.expressionSimplify the given expression knowing its first bit will be irrelevant
val add_int : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionArithmetical operations on integers
val sub_int : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval lsl_int : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval mul_int : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval lsr_int : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval asr_int : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval div_int : Cmm.expression -> Cmm.expression -> Lambda.is_safe -> Debuginfo.t -> Cmm.expressionval mod_int : Cmm.expression -> Cmm.expression -> Lambda.is_safe -> Debuginfo.t -> Cmm.expressionval tag_int : Cmm.expression -> Debuginfo.t -> Cmm.expressionInteger tagging. tag_int x = (x lsl 1) + 1
val untag_int : Cmm.expression -> Debuginfo.t -> Cmm.expressionInteger untagging. untag_int x = (x asr 1)
val safe_div_bi : Lambda.is_safe -> Cmm.expression -> Cmm.expression -> Primitive.boxed_integer -> Debuginfo.t -> Cmm.expressionSpecific division operations for boxed integers
val safe_mod_bi : Lambda.is_safe -> Cmm.expression -> Cmm.expression -> Primitive.boxed_integer -> Debuginfo.t -> Cmm.expressionval mk_if_then_else : Debuginfo.t -> Cmm.expression -> Debuginfo.t -> Cmm.expression -> Debuginfo.t -> Cmm.expression -> Cmm.expressionIf-Then-Else expression mk_if_then_else dbg cond ifso_dbg ifso ifnot_dbg ifnot associates dbg to the global if-then-else expression, ifso_dbg to the then branch ifso, and ifnot_dbg to the else branch ifnot
val mk_not : Debuginfo.t -> Cmm.expression -> Cmm.expressionBoolean negation
val mk_compare_ints : Debuginfo.t -> Cmm.expression -> Cmm.expression -> Cmm.expressionInteger and float comparison that returns int not bool
val mk_compare_floats : Debuginfo.t -> Cmm.expression -> Cmm.expression -> Cmm.expressionval create_loop : Cmm.expression -> Debuginfo.t -> Cmm.expressionLoop construction (while true do expr done). Used to be represented as Cloop.
val raise_symbol : Debuginfo.t -> string -> Cmm.expressionException raising
val test_bool : Debuginfo.t -> Cmm.expression -> Cmm.expressionConvert a tagged integer into a raw integer with boolean meaning
val box_float : Debuginfo.t -> Cmm.expression -> Cmm.expressionFloat boxing and unboxing
val unbox_float : Debuginfo.t -> Cmm.expression -> Cmm.expressionval box_complex : Debuginfo.t -> Cmm.expression -> Cmm.expression -> Cmm.expressionComplex number creation and access
val complex_re : Cmm.expression -> Debuginfo.t -> Cmm.expressionval complex_im : Cmm.expression -> Debuginfo.t -> Cmm.expressionval return_unit : Debuginfo.t -> Cmm.expression -> Cmm.expressionMake the given expression return a unit value
val remove_unit : Cmm.expression -> Cmm.expressionRemove a trailing unit return if any
Blocks
val field_address : Cmm.expression -> int -> Debuginfo.t -> Cmm.expressionfield_address ptr n dbg returns an expression for the address of the nth field of the block pointed to by ptr
val get_field_gen : Asttypes.mutable_flag -> Cmm.expression -> int -> Debuginfo.t -> Cmm.expressionget_field_gen mut ptr n dbg returns an expression for the access to the nth field of the block pointed to by ptr
val set_field : Cmm.expression -> int -> Cmm.expression -> Lambda.initialization_or_assignment -> Debuginfo.t -> Cmm.expressionset_field ptr n newval init dbg returns an expression for setting the nth field of the block pointed to by ptr to newval
val get_header : Cmm.expression -> Debuginfo.t -> Cmm.expressionLoad a block's header
val get_header_without_profinfo : Cmm.expression -> Debuginfo.t -> Cmm.expressionSame as get_header, but also set all profiling bits of the header are to 0 (if profiling is enabled)
val get_tag : Cmm.expression -> Debuginfo.t -> Cmm.expressionLoad a block's tag
val get_size : Cmm.expression -> Debuginfo.t -> Cmm.expressionLoad a block's size
Arrays
val is_addr_array_hdr : Cmm.expression -> Debuginfo.t -> Cmm.expressionCheck whether the given array is an array of regular OCaml values (as opposed to unboxed floats), from its header or pointer
val is_addr_array_ptr : Cmm.expression -> Debuginfo.t -> Cmm.expressionval addr_array_length_shifted : Cmm.expression -> Debuginfo.t -> Cmm.expressionGet the length of an array from its header Shifts by one bit less than necessary, keeping one of the GC colour bits, to save an operation when returning the length as a caml integer or when comparing it to a caml integer. Assumes the header does not have any profiling info (as returned by get_header_without_profinfo)
val float_array_length_shifted : Cmm.expression -> Debuginfo.t -> Cmm.expressionval array_indexing : ?typ:Cmm.machtype_component -> int -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionFor array_indexing ?typ log2size ptr ofs dbg : Produces a pointer to the element of the array ptr on the position ofs with the given element log2size log2 element size. ofs is given as a tagged int expression. The optional ?typ argument is the C-- type of the result. By default, it is Addr, meaning we are constructing a derived pointer into the heap. If we know the pointer is outside the heap (this is the case for bigarray indexing), we give type Int instead.
val addr_array_ref : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionArray loads and stores unboxed_float_array_ref and float_array_ref differ in the boxing of the result; float_array_set takes an unboxed float
val int_array_ref : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval unboxed_float_array_ref : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval float_array_ref : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval addr_array_set : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval addr_array_initialize : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval int_array_set : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval float_array_set : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionStrings
val string_length : Cmm.expression -> Debuginfo.t -> Cmm.expressionval bigstring_length : Cmm.expression -> Debuginfo.t -> Cmm.expressionObjects
val lookup_tag : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionLookup a method by its hash, using caml_get_public_method Arguments :
val lookup_label : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionLookup a method by its offset in the method table Arguments :
val call_cached_method : Cmm.expression -> Cmm.expression -> Cmm.expression -> Cmm.expression -> Cmm.expression list -> Debuginfo.t -> Cmm.expressionLookup and call a method using the method cache Arguments :
Allocations
val make_alloc : Debuginfo.t -> int -> Cmm.expression list -> Cmm.expressionAllocate a block of regular values with the given tag
val make_float_alloc : Debuginfo.t -> int -> Cmm.expression list -> Cmm.expressionAllocate a block of unboxed floats with the given tag
Bounds checking
val make_checkbound : Debuginfo.t -> Cmm.expression list -> Cmm.expressionGenerate a Ccheckbound term
val check_bound : Lambda.is_safe -> Clambda_primitives.memory_access_size -> Debuginfo.t -> Cmm.expression -> Cmm.expression -> Cmm.expression -> Cmm.expressioncheck_bound safety access_size dbg length a2 k prefixes expression k with a check that reading access_size bits starting at position a2 in a string/bytes value of length length is within bounds, unless safety is Unsafe.
Generic application functions
Get the symbol for the generic application with n arguments, and ensure its presence in the set of defined symbols
If n is positive, get the symbol for the generic currying wrapper with n arguments, and ensure its presence in the set of defined symbols. Otherwise, do the same for the generic tuple wrapper with -n arguments.
Bigarrays
val bigarray_get : bool -> Lambda.bigarray_kind -> Lambda.bigarray_layout -> Cmm.expression -> Cmm.expression list -> Debuginfo.t -> Cmm.expressionbigarray_get unsafe kind layout b args dbg
Lambda.bigarray_kindLambda.bigarray_layoutval bigarray_set : bool -> Lambda.bigarray_kind -> Lambda.bigarray_layout -> Cmm.expression -> Cmm.expression list -> Cmm.expression -> Debuginfo.t -> Cmm.expressionbigarray_set unsafe kind layout b args newval dbg Same as bigarray_get, with newval the value being assigned
Operations on 32-bit integers
val low_32 : Debuginfo.t -> Cmm.expression -> Cmm.expressionlow_32 _ x is a value which agrees with x on at least the low 32 bits
val sign_extend_32 : Debuginfo.t -> Cmm.expression -> Cmm.expressionSign extend from 32 bits to the word size
val zero_extend_32 : Debuginfo.t -> Cmm.expression -> Cmm.expressionZero extend from 32 bits to the word size
Boxed numbers
val box_int_gen : Debuginfo.t -> Primitive.boxed_integer -> Cmm.expression -> Cmm.expressionBox a given integer, without sharing of constants
val unbox_int : Debuginfo.t -> Primitive.boxed_integer -> Cmm.expression -> Cmm.expressionUnbox a given boxed integer
val make_unsigned_int : Primitive.boxed_integer -> Cmm.expression -> Debuginfo.t -> Cmm.expressionUsed to prepare 32-bit integers on 64-bit platforms for a lsr operation
val unaligned_load_16 : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval unaligned_set_16 : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval unaligned_load_32 : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval unaligned_set_32 : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval unaligned_load_64 : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval unaligned_set_64 : Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionRaw memory accesses
val unaligned_set : Clambda_primitives.memory_access_size -> Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionunaligned_set size ptr idx newval dbg
val unaligned_load : Clambda_primitives.memory_access_size -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionunaligned_load size ptr idx dbg
val box_sized : Clambda_primitives.memory_access_size -> Debuginfo.t -> Cmm.expression -> Cmm.expressionbox_sized size dbg exp
Primitives
val simplif_primitive : Clambda_primitives.primitive -> Clambda_primitives.primitivetype unary_primitive = Cmm.expression -> Debuginfo.t -> Cmm.expressionval floatfield : int -> unary_primitiveReturn the n-th field of a float array (or float-only record), as an unboxed float
val int_as_pointer : unary_primitiveInt_as_pointer primitive
val raise_prim : Lambda.raise_kind -> unary_primitiveRaise primitive
val negint : unary_primitiveUnary negation of an OCaml integer
val offsetint : int -> unary_primitiveAdd a constant number to an OCaml integer
val offsetref : int -> unary_primitiveAdd a constant number to an OCaml integer reference
val arraylength : Lambda.array_kind -> unary_primitiveReturn the length of the array argument, as an OCaml integer
val bbswap : Primitive.boxed_integer -> unary_primitiveByte swap primitive Operates on Cmm integers (unboxed values)
val bswap16 : unary_primitive16-bit byte swap primitive Operates on Cmm integers (untagged integers)
type binary_primitive = Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval setfield : int -> Lambda.immediate_or_pointer -> Lambda.initialization_or_assignment -> binary_primitivesetfield offset value_is_ptr init ptr value dbg
val setfloatfield : int -> Lambda.initialization_or_assignment -> binary_primitivesetfloatfield offset init ptr value dbg value is expected to be an unboxed floating point number
val add_int_caml : binary_primitiveOperations on OCaml integers
val sub_int_caml : binary_primitiveval mul_int_caml : binary_primitiveval div_int_caml : Lambda.is_safe -> binary_primitiveval mod_int_caml : Lambda.is_safe -> binary_primitiveval and_int_caml : binary_primitiveval or_int_caml : binary_primitiveval xor_int_caml : binary_primitiveval lsl_int_caml : binary_primitiveval lsr_int_caml : binary_primitiveval asr_int_caml : binary_primitiveval int_comp_caml : Lambda.integer_comparison -> binary_primitiveStrings, Bytes and Bigstrings
val stringref_unsafe : binary_primitiveRegular string/bytes access. Args: string/bytes, index
val stringref_safe : binary_primitiveval string_load : Clambda_primitives.memory_access_size -> Lambda.is_safe -> binary_primitiveLoad by chunk from string/bytes, bigstring. Args: string, index
val bigstring_load : Clambda_primitives.memory_access_size -> Lambda.is_safe -> binary_primitiveArrays
val arrayref_unsafe : Lambda.array_kind -> binary_primitiveArray access. Args: array, index
val arrayref_safe : Lambda.array_kind -> binary_primitivetype ternary_primitive = Cmm.expression -> Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressionval setfield_computed : Lambda.immediate_or_pointer -> Lambda.initialization_or_assignment -> ternary_primitiveSame as setfield, except the offset is one of the arguments. Args: pointer (structure/array/...), index, value
val bytesset_unsafe : ternary_primitiveSet the byte at the given offset to the given value. Args: bytes, index, value
val bytesset_safe : ternary_primitiveval arrayset_unsafe : Lambda.array_kind -> ternary_primitiveSet the element at the given index in the given array to the given value. WARNING: if kind is Pfloatarray, then value is expected to be an _unboxed_ float. Otherwise, it is expected to be a regular caml value, including in the case where the array contains floats. Args: array, index, value
val arrayset_safe : Lambda.array_kind -> ternary_primitiveval bytes_set : Clambda_primitives.memory_access_size -> Lambda.is_safe -> ternary_primitiveSet a chunk of data in the given bytes or bigstring structure. See also string_load and bigstring_load. Note: value is expected to be an unboxed number of the given size. Args: pointer, index, value
val bigstring_set : Clambda_primitives.memory_access_size -> Lambda.is_safe -> ternary_primitiveSwitch
val transl_isout : Cmm.expression -> Cmm.expression -> Debuginfo.t -> Cmm.expressiontransl_isout h arg dbg
val make_switch : Cmm.expression -> int array -> (Cmm.expression * Debuginfo.t) array -> Debuginfo.t -> Cmm.expressionmake_switch arg cases actions dbg : Generate a Cswitch construct, or optimize as a static table lookup when possible.
val transl_int_switch : Debuginfo.t -> Cmm.expression -> int -> int -> (int * Cmm.expression) list -> Cmm.expression -> Cmm.expressiontransl_int_switch loc arg low high cases default
val transl_switch_clambda : Debuginfo.t -> Cmm.expression -> int array -> Cmm.expression array -> Cmm.expressiontransl_switch_clambda loc arg index cases
val strmatch_compile : Debuginfo.t -> Cmm.expression -> Cmm.expression option -> (string * Cmm.expression) list -> Cmm.expressionstrmatch_compile dbg arg default cases
Closures and function applications
val ptr_offset : Cmm.expression -> int -> Debuginfo.t -> Cmm.expressionAdds a constant offset to a pointer (for infix access)
val direct_apply : string -> Cmm.expression list -> Debuginfo.t -> Cmm.expressionDirect application of a function via a symbol
val generic_apply : Asttypes.mutable_flag -> Cmm.expression -> Cmm.expression list -> Debuginfo.t -> Cmm.expressionGeneric application of a function to one or several arguments. The mutable_flag argument annotates the loading of the code pointer from the closure. The Cmmgen code uses a mutable load by default, with a special case when the load is from (the first function of) the currently defined closure.
val send : Lambda.meth_kind -> Cmm.expression -> Cmm.expression -> Cmm.expression list -> Debuginfo.t -> Cmm.expressionMethod call : send kind met obj args dbg
met is a method identifier, which can be a hashed variant or an index in obj's method table, depending on kindobj is the object whose method is being calledargs is the extra arguments to the method call (Note: I'm not aware of any way for the frontend to generate any arguments other than the cache and cache position)Generic Cmm fragments
val generic_functions : bool -> Cmx_format.unit_infos list -> Cmm.phrase listGenerate generic functions
val placeholder_dbg : unit -> Debuginfo.tval placeholder_fun_dbg : human_name:string -> Debuginfo.tval entry_point : string list -> Cmm.phraseEntry point
val global_table : string list -> Cmm.phraseGenerate the caml_globals table
val reference_symbols : string list -> Cmm.phraseAdd references to the given symbols
val globals_map : (string * Digest.t option * Digest.t option * string list) list -> Cmm.phraseGenerate the caml_globals_map structure, as a marshalled string constant
val frame_table : string list -> Cmm.phraseGenerate the caml_frametable table, referencing the frametables from the given compilation units
val data_segment_table : string list -> Cmm.phraseGenerate the tables for data and code positions respectively of the given compilation units
val code_segment_table : string list -> Cmm.phraseval predef_exception : int -> string -> Cmm.phraseGenerate data for a predefined exception
val plugin_header : (Cmx_format.unit_infos * Digest.t) list -> Cmm.phraseEmit constant symbols
val cdefine_symbol : (string * Cmmgen_state.is_global) -> Cmm.data_item listProduce the data_item list corresponding to a symbol definition
val emit_block : (string * Cmmgen_state.is_global) -> nativeint -> Cmm.data_item list -> Cmm.data_item listemit_block symb white_header cont prepends to cont the header and symbol for the block. cont must already contain the fields of the block (and may contain additional data items afterwards).
val emit_float_constant : (string * Cmmgen_state.is_global) -> float -> Cmm.data_item list -> Cmm.data_item listEmit specific kinds of constant blocks as data items
val emit_string_constant : (string * Cmmgen_state.is_global) -> string -> Cmm.data_item list -> Cmm.data_item listval emit_int32_constant : (string * Cmmgen_state.is_global) -> int32 -> Cmm.data_item list -> Cmm.data_item listval emit_int64_constant : (string * Cmmgen_state.is_global) -> int64 -> Cmm.data_item list -> Cmm.data_item listval emit_nativeint_constant : (string * Cmmgen_state.is_global) -> nativeint -> Cmm.data_item list -> Cmm.data_item listval emit_float_array_constant : (string * Cmmgen_state.is_global) -> float list -> Cmm.data_item list -> Cmm.data_item listval fundecls_size : Clambda.ufunction list -> intval emit_constant_closure : (string * Cmmgen_state.is_global) -> Clambda.ufunction list -> Cmm.data_item list -> Cmm.data_item list -> Cmm.data_item listval emit_preallocated_blocks : Clambda.preallocated_block list -> Cmm.phrase list -> Cmm.phrase list