Module Primus.Pos

A hierarchical program position.

The Pos.t is a cursor-like data structure, that describes a program position in the program term hierarchy.

type nil

uninhabited type

type top = Bap.Std.program

the top-most program term.

type ('a, 'b) level = {
  1. me : 'a Bap.Std.term;
    (*

    me current position

    *)
  2. up : 'b;
    (*

    up parent cursor

    *)
}

(t,p) level a cursor pointing to a t term, that is nested in the parent cursor p.

type level3 = (top, nil) level

the highest level of the hierarchy - a cursor the points to the whole program. This is a starting position.

type level2 = (Bap.Std.sub, level3) level

a cursor pointing to a function

type 'a level1 = ('a, level2) level

a level of arguments and basic blocks

type 'a level0 = ('a, Bap.Std.blk level1) level

a level of the basic terms, e.g., defs, jmps and phi-nodes.

type t =
  1. | Top of level3
    (*

    a program

    *)
  2. | Sub of level2
    (*

    a subroutine

    *)
  3. | Arg of Bap.Std.arg level1
    (*

    subroutine argument

    *)
  4. | Blk of Bap.Std.blk level1
    (*

    a basic block

    *)
  5. | Phi of Bap.Std.phi level0
    (*

    a phi-node

    *)
  6. | Def of Bap.Std.def level0
    (*

    a definition

    *)
  7. | Jmp of Bap.Std.jmp level0
    (*

    a jump term

    *)

a program location

val tid : t -> Bap.Std.tid

tid p is term identifier of the term enclosing position p

val get : 'a Bap.Std.tag -> t -> 'a option

get a p get a value of the attribute a associated with the given position p. Example, Pos.get address p returns a machine address of the position p.

val to_string : t -> string

to_string level a textual and human readable representation of a cursor.

val next : t -> ('p, 't) Bap.Std.cls -> 't Bap.Std.term -> (t, exn) Monads.Std.Monad.Result.result

next p cls t moves the cursor position p to the next position, that points to the term t of the class cls. Returns an error if there is no valid transition from the current program position to the specified program term.