Module Mlang.DecoupledExpr

type offset =
| GetValueConst of int
| GetValueExpr of string
| GetValueVar of Com.Var.t
| PassPointer
| None
val generate_variable : offset -> ?⁠def_flag:bool -> ?⁠trace_flag:bool -> Com.Var.t -> string
type dflag =
| Def
| Val

Low-level M computation

Local variables

type local_var

Variable local to the computed expression

val locals_from_m : unit -> local_var * local_var

Return a couple of local variable from a MIR one, for defineness and valuation in this order.

val new_local : unit -> local_var

Create a fresh local variable

Expression constructors

type constr

Constructed decoupled expression

val dtrue : constr

True value

val dfalse : constr

False value

val lit : float -> constr

Float literal

val m_var : Com.Var.t -> offset -> dflag -> constr

Value from TGV. m_var v off df represents an access to the TGV variable v with df to read defineness or valuation. off is the access type for M array, and should be None most of the time. For array access, see access.

val let_local : local_var -> constr -> constr -> constr

Local let-binding. let_local v defining_expr body_expr is akin to OCaml let v = defining_expr in body_expr

val local_var : local_var -> constr

Access local variable value

val dand : constr -> constr -> constr

Boolean and

val dor : constr -> constr -> constr

Boolean or

val dnot : constr -> constr

Boolean not

val minus : constr -> constr

Negate value

val plus : constr -> constr -> constr

Float addition

val sub : constr -> constr -> constr

Float substraction

val mult : constr -> constr -> constr

Float multiplication

val div : constr -> constr -> constr

Float division. Care to guard for division by zero as it is not intrisectly guarranteed

val comp : string -> constr -> constr -> constr

Comparison operation. The operator is given as C-style string literal

val dfun : string -> constr list -> constr

Function call

val dinstr : string -> constr

Direct instruction

val dlow_level : string -> constr

Direct instruction, not pushed

val access : Com.Var.t -> dflag -> constr -> constr

Arbitrary access to M TGV variable. Either defineness of valuation

val ite : constr -> constr -> constr -> constr

Functionnal if-the-else construction. ite cond_expr then_expr else_expr is akin to if cond_expr then then_expr else else_expr

Decoupled expressions

type expression_composition = {
set_vars : (dflag * string * constr) list;
def_test : constr;
value_comp : constr;
}

Representation of an M computation in construction. def_test for the defineness flag, and value_comp for the actual valuation.

val build_transitive_composition : ?⁠safe_def:bool -> expression_composition -> expression_composition

Refine an expression composition to enfore M invariants. Mainly the fact that undefined value are valuated to zero. value_comp of the argument is expected to be defined assuming the expression is defined. safe_def, which defaults to false, can be set when the defined value_comp computation will evaluate to zero if def_test do, allowing the guard to be optimized away.

type t

Decoupled expression type. Closed representation of a computation.

val is_always_true : t -> bool

Tells if the expression t reprensents a value statically different to zero

type local_decls

Representation of local variables existing in an expression

val build_expression : expression_composition -> local_decls * (dflag * string * t) list * t * t

Crush Expression constructors values into closed expressions t

val format_local_declarations : Stdlib.Format.formatter -> local_decls -> unit
val format_assign : Dgfip_options.flags -> string -> Stdlib.Format.formatter -> t -> unit
val format_set_vars : Dgfip_options.flags -> Stdlib.Format.formatter -> (dflag * string * t) list -> unit