@ -17,6 +17,24 @@ module Function = Function
module Global = Global
module Global = Global
module GlobalDefn = GlobalDefn
module GlobalDefn = GlobalDefn
module Intrinsic = struct
include Intrinsics
module Intrinsic_to_String = Bijection . Make ( Intrinsics ) ( String )
let t_to_name =
Iter . of_list all
| > Iter . map ~ f : ( fun i -> ( i , Variants . to_name i ) )
| > Intrinsic_to_String . of_iter
let to_string i = Intrinsic_to_String . find_left i t_to_name
let of_name s =
try Some ( Intrinsic_to_String . find_right s t_to_name )
with Not_found -> None
let pp ppf i = Format . pp_print_string ppf ( to_string i )
end
type inst =
type inst =
| Move of { reg_exps : ( Reg . t * Exp . t ) iarray ; loc : Loc . t }
| Move of { reg_exps : ( Reg . t * Exp . t ) iarray ; loc : Loc . t }
| Load of { reg : Reg . t ; ptr : Exp . t ; len : Exp . t ; loc : Loc . t }
| Load of { reg : Reg . t ; ptr : Exp . t ; len : Exp . t ; loc : Loc . t }
@ -28,6 +46,8 @@ type inst =
| Free of { ptr : Exp . t ; loc : Loc . t }
| Free of { ptr : Exp . t ; loc : Loc . t }
| Nondet of { reg : Reg . t option ; msg : string ; loc : Loc . t }
| Nondet of { reg : Reg . t option ; msg : string ; loc : Loc . t }
| Abort of { loc : Loc . t }
| Abort of { loc : Loc . t }
| Intrinsic of
{ reg : Reg . t option ; name : Intrinsic . t ; args : Exp . t iarray ; loc : Loc . t }
[ @@ deriving compare , equal , hash , sexp ]
[ @@ deriving compare , equal , hash , sexp ]
type cmnd = inst iarray [ @@ deriving compare , equal , hash , sexp ]
type cmnd = inst iarray [ @@ deriving compare , equal , hash , sexp ]
@ -258,6 +278,10 @@ let pp_inst fs inst =
( Option . pp " %a := " Reg . pp )
( Option . pp " %a := " Reg . pp )
reg msg Loc . pp loc
reg msg Loc . pp loc
| Abort { loc } -> pf " @[<2>abort;@] \t %a " Loc . pp loc
| Abort { loc } -> pf " @[<2>abort;@] \t %a " Loc . pp loc
| Intrinsic { reg ; name ; args ; loc } ->
pf " @[<2>%aintrinsic %a(%a);@] \t %a "
( Option . pp " %a := " Reg . pp )
reg Intrinsic . pp name ( IArray . pp " ,@ " Exp . pp ) args Loc . pp loc
let pp_actuals pp_actual fs actuals =
let pp_actuals pp_actual fs actuals =
Format . fprintf fs " @ (@[%a@]) " ( IArray . pp " ,@ " pp_actual ) actuals
Format . fprintf fs " @ (@[%a@]) " ( IArray . pp " ,@ " pp_actual ) actuals
@ -352,6 +376,7 @@ module Inst = struct
let free ~ ptr ~ loc = Free { ptr ; loc }
let free ~ ptr ~ loc = Free { ptr ; loc }
let nondet ~ reg ~ msg ~ loc = Nondet { reg ; msg ; loc }
let nondet ~ reg ~ msg ~ loc = Nondet { reg ; msg ; loc }
let abort ~ loc = Abort { loc }
let abort ~ loc = Abort { loc }
let intrinsic ~ reg ~ name ~ args ~ loc = Intrinsic { reg ; name ; args ; loc }
let loc = function
let loc = function
| Move { loc ; _ }
| Move { loc ; _ }
@ -363,18 +388,23 @@ module Inst = struct
| Alloc { loc ; _ }
| Alloc { loc ; _ }
| Free { loc ; _ }
| Free { loc ; _ }
| Nondet { loc ; _ }
| Nondet { loc ; _ }
| Abort { loc ; _ } ->
| Abort { loc ; _ }
| Intrinsic { loc ; _ } ->
loc
loc
let union_locals inst vs =
let union_locals inst vs =
match inst with
match inst with
| Move { reg_exps ; _ } ->
| Move { reg_exps ; _ } ->
IArray . fold ~ f : ( fun ( reg , _ ) vs -> Reg . Set . add reg vs ) reg_exps vs
IArray . fold ~ f : ( fun ( reg , _ ) vs -> Reg . Set . add reg vs ) reg_exps vs
| Load { reg ; _ } | Alloc { reg ; _ } | Nondet { reg = Some reg ; _ } ->
| Load { reg ; _ }
| Alloc { reg ; _ }
| Nondet { reg = Some reg ; _ }
| Intrinsic { reg = Some reg ; _ } ->
Reg . Set . add reg vs
Reg . Set . add reg vs
| Store _ | Memcpy _ | Memmov _ | Memset _ | Free _
| Store _ | Memcpy _ | Memmov _ | Memset _ | Free _
| Nondet { reg = None ; _ }
| Nondet { reg = None ; _ }
| Abort _ ->
| Abort _
| Intrinsic { reg = None ; _ } ->
vs
vs
let locals inst = union_locals inst Reg . Set . empty
let locals inst = union_locals inst Reg . Set . empty
@ -392,6 +422,7 @@ module Inst = struct
| Free { ptr ; loc = _ } -> f ptr s
| Free { ptr ; loc = _ } -> f ptr s
| Nondet { reg = _ ; msg = _ ; loc = _ } -> s
| Nondet { reg = _ ; msg = _ ; loc = _ } -> s
| Abort { loc = _ } -> s
| Abort { loc = _ } -> s
| Intrinsic { reg = _ ; name = _ ; args ; loc = _ } -> IArray . fold ~ f args s
end
end
(* * Jumps *)
(* * Jumps *)