Module Fang_asm.Asm

Assembly instructions.

type t = asm
exception Invalid_index of int

Defining instructions

type selector = int -> box

Selects a register by its zero-based index in "use" and "def" lists. These are not defined by callers: they're provided automatically to help define the instruction pretty-printer.

Raises Invalid_index if the index is out-of-bounds of the use- or def-list.

type formatter = use:selector -> def:selector -> box Fmt.t -> unit Fmt.t

A function which defines a pretty-printer for an instruction given:

  • An indexed sequence of "use" registers
  • An indexed sequence of "def" registers
  • A pretty-printer for registers
val v : ?⁠is_move:bool -> ?⁠use:box list -> ?⁠def:box list -> formatter -> t

Define a new instruction.

If is_move is true (its default value is false), then this indicates that the only behaviour of this instruction is to copy a value from one register to another.

Operations on instructions

val compare : t -> t -> int

compare t1 t2 is 0 if t1 and t2 refer to the same value produced by v. Otherwise, there exists a total order on instructions but it is unspecified.

val pp : box Fmt.t -> t Fmt.t

Transforming instructions

val modify_use : (box array -> unit) -> t -> t
val modify_def : (box array -> unit) -> t -> t
val map : (box -> box) -> t -> t
val replace : target:box -> box -> t -> t

Querying instructions

val use : t -> box iter
val def : t -> box iter
val case : move:(box -> box -> 'a) -> otherwise:(t -> 'a) -> t -> 'a

Containers of instructions

module Set : Stdlib.Set.S with type Set.elt = t
module Map : Stdlib.Map.S with type Map.key = t