@ -12,7 +12,7 @@ module F = Format
file ) . Defines useful wrappers that allows us to do tricks like turn a forward cfg into a
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 . * )
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 t
type id
type id
@ -38,26 +38,37 @@ module type Node = sig
module IdSet : PrettyPrintable . PPSet with type elt = id
module IdSet : PrettyPrintable . PPSet with type elt = id
end
end
module DefaultNode : Node with type t = Procdesc . Node . t and type id = Procdesc . Node . id = struct
module InstrNode : sig
type t = Procdesc . Node . t
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
module OrderedId = struct
type t = id [ @@ deriving compare ]
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
let pp = pp_id
end
end
module IdMap = Pr ocdesc. IdMap
module IdMap = Pr ettyPrintable. MakePPMap ( OrderedId )
module IdSet = PrettyPrintable . MakePPSet ( OrderedId )
module IdSet = PrettyPrintable . MakePPSet ( OrderedId )
let to_instr _ t = t
end
end
module InstrNode : sig
module type Node = sig
type instr_index = int
include NodeCommonS
include
val to_instr : InstrNode . instr_index -> t -> InstrNode . t
Node with type t = Procdesc . Node . t * instr_index and type id = Procdesc . Node . id * instr_index
end
end = struct
type instr_index = int [ @@ deriving compare ]
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
module OrderedId = struct
type t = id [ @@ deriving compare ]
type t = id [ @@ deriving compare ]
@ -101,8 +115,10 @@ end = struct
let pp = pp_id
let pp = pp_id
end
end
module IdMap = Pr ettyPrintable. MakePPMap ( OrderedId )
module IdMap = Pr ocdesc. IdMap
module IdSet = PrettyPrintable . MakePPSet ( OrderedId )
module IdSet = PrettyPrintable . MakePPSet ( OrderedId )
let to_instr index node = ( node , index )
end
end
module type S = sig
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
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 last_of_underlying_node : Procdesc . Node . t -> Node . t
val of_instr_opt : Procdesc . Node . t -> Sil . instr -> Node . t option
end = struct
end = struct
type t = Base . t
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 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 last_of_underlying_node = last_of_node
let fold_normal_succs _ _ ~ init : _ ~ f : _ = (* not used *) assert false
let fold_normal_succs _ _ ~ init : _ ~ f : _ = (* not used *) assert false