@ -12,7 +12,7 @@ module F = Format
file ) . Defines useful wrappers that allows us to do tricks like turn a forward cfg into a
backward one , or view a cfg as having a single instruction per node . * )
module type Node = sig
module type Node CommonS = sig
type t
type id
@ -38,26 +38,37 @@ module type Node = sig
module IdSet : PrettyPrintable . PPSet with type elt = id
end
module DefaultNode : Node with type t = Procdesc . Node . t and type id = Procdesc . Node . id = struct
type t = Procdesc . Node . t
module InstrNode : sig
type instr_index = in t
type id = Procdesc . Node . id
include
NodeCommonS
with type t = Procdesc . Node . t * instr_index
and type id = Procdesc . Node . id * instr_index
let kind = Procdesc . Node . get_kind
val compare : t -> t -> int
let id = Procdesc . Node . get_id
val to_instr : instr_index -> t -> t
end = struct
type instr_index = int [ @@ deriving compare ]
let hash = Procdesc . Node . hash
type t = Procdesc . Node . t * instr_index [ @@ deriving compare ]
let loc = Procdesc . Node . get_loc
type id = Procdesc . Node . id * instr_index [ @@ deriving compare ]
let underlying_node t = t
let kind ( t , _ ) = Procdesc . Node . get_kind t
let of_ underlying_node t = t
let underlying_node ( t , _ ) = t
let compare_id = Procdesc . Node . compare_id
let of_underlying_node t = ( t , 0 )
let pp_id = Procdesc . Node . pp_id
let id ( t , index ) = ( Procdesc . Node . get_id t , index )
let hash node = Hashtbl . hash ( id node )
let loc ( t , _ ) = Procdesc . Node . get_loc t
let pp_id fmt ( id , index ) = F . fprintf fmt " (%a: %d) " Procdesc . Node . pp_id id index
module OrderedId = struct
type t = id [ @@ deriving compare ]
@ -65,35 +76,38 @@ module DefaultNode : Node with type t = Procdesc.Node.t and type id = Procdesc.N
let pp = pp_id
end
module IdMap = Pr ocdesc. IdMap
module IdMap = Pr ettyPrintable. MakePPMap ( OrderedId )
module IdSet = PrettyPrintable . MakePPSet ( OrderedId )
let to_instr _ t = t
end
module InstrNode : sig
type instr_index = int
module type Node = sig
include NodeCommonS
include
Node with type t = Procdesc . Node . t * instr_index and type id = Procdesc . Node . id * instr_index
end = struct
type instr_index = int [ @@ deriving compare ]
val to_instr : InstrNode . instr_index -> t -> InstrNode . t
end
type t = Procdesc . Node . t * instr_index
module DefaultNode : Node with type t = Procdesc . Node . t and type id = Procdesc . Node . id = struct
type t = Procdesc . Node . t
type id = Procdesc . Node . id * instr_index [ @@ deriving compare ]
type id = Procdesc . Node . id
let kind (t , _ ) = Procdesc . Node . get_kind t
let kind = Procdesc . Node . get_kind
let underlying_node ( t , _ ) = t
let id = Procdesc . Node . get_id
let of_underlying_node t = ( t , 0 )
let hash = Procdesc . Node . hash
let id ( t , index ) = ( Procdesc . Node . get_id t , index )
let loc = Procdesc . Node . get_loc
let hash node = Hashtbl . hash ( id node )
let underlying_node t = t
let loc ( t , _ ) = Procdesc . Node . get_loc t
let of_underlying_node t = t
let pp_id fmt ( id , index ) = F . fprintf fmt " (%a: %d) " Procdesc . Node . pp_id id index
let compare_id = Procdesc . Node . compare_id
let pp_id = Procdesc . Node . pp_id
module OrderedId = struct
type t = id [ @@ deriving compare ]
@ -101,8 +115,10 @@ end = struct
let pp = pp_id
end
module IdMap = Pr ettyPrintable. MakePPMap ( OrderedId )
module IdMap = Pr ocdesc. IdMap
module IdSet = PrettyPrintable . MakePPSet ( OrderedId )
let to_instr index node = ( node , index )
end
module type S = sig
@ -325,8 +341,6 @@ module OneInstrPerNode (Base : S with module Node = DefaultNode) : sig
S with type t = Base . t and module Node = InstrNode and type instrs_dir = Instrs . not_reversed
val last_of_underlying_node : Procdesc . Node . t -> Node . t
val of_instr_opt : Procdesc . Node . t -> Sil . instr -> Node . t option
end = struct
type t = Base . t
@ -343,11 +357,6 @@ end = struct
let last_of_node node = ( node , max 0 ( Instrs . count ( Base . instrs node ) - 1 ) )
let of_instr_opt node instr =
let instrs = Procdesc . Node . get_instrs node in
Instrs . find_instr_index instrs instr | > Option . map ~ f : ( fun index -> ( node , index ) )
let last_of_underlying_node = last_of_node
let fold_normal_succs _ _ ~ init : _ ~ f : _ = (* not used *) assert false