You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.2 KiB
102 lines
3.2 KiB
9 years ago
|
(*
|
||
|
* Copyright (c) 2016 - present Facebook, Inc.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* This source code is licensed under the BSD style license found in the
|
||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||
|
*)
|
||
|
|
||
8 years ago
|
open! IStd
|
||
|
|
||
9 years ago
|
(** Control-flow graph for a single procedure (as opposed to cfg.ml, which represents a cfg for a
|
||
|
file). Defines useful wrappers that allows us to do tricks like turn a forward cfg to into a
|
||
|
backward one, or view a cfg as having a single instruction per block *)
|
||
|
|
||
9 years ago
|
type index = Node_index | Instr_index of int
|
||
|
|
||
9 years ago
|
module type Node = sig
|
||
|
type t
|
||
|
type id
|
||
|
|
||
8 years ago
|
val kind : t -> Procdesc.Node.nodekind
|
||
9 years ago
|
val id : t -> id
|
||
8 years ago
|
val hash : t -> int
|
||
8 years ago
|
val loc : t -> Location.t
|
||
8 years ago
|
val underlying_node : t -> Procdesc.Node.t
|
||
8 years ago
|
val compare_id : id -> id -> int
|
||
9 years ago
|
val pp_id : Format.formatter -> id -> unit
|
||
|
end
|
||
|
|
||
|
module type S = sig
|
||
9 years ago
|
type t
|
||
|
type node
|
||
9 years ago
|
include (Node with type t := node)
|
||
9 years ago
|
|
||
9 years ago
|
(** get the instructions from a node *)
|
||
|
val instrs : node -> Sil.instr list
|
||
8 years ago
|
|
||
9 years ago
|
(** explode a block into its instructions and an optional id for the instruction. the purpose of
|
||
|
this is to specify a policy for fine-grained storage of invariants by the abstract
|
||
|
interpreter. the interpreter will forget invariants at program points where the id is None,
|
||
|
and remember them otherwise *)
|
||
|
val instr_ids : node -> (Sil.instr * id option) list
|
||
8 years ago
|
|
||
9 years ago
|
val succs : t -> node -> node list
|
||
8 years ago
|
|
||
9 years ago
|
(** all predecessors (normal and exceptional) *)
|
||
|
val preds : t -> node -> node list
|
||
8 years ago
|
|
||
9 years ago
|
(** non-exceptional successors *)
|
||
|
val normal_succs : t -> node -> node list
|
||
8 years ago
|
|
||
9 years ago
|
(** non-exceptional predecessors *)
|
||
|
val normal_preds : t -> node -> node list
|
||
8 years ago
|
|
||
9 years ago
|
(** exceptional successors *)
|
||
|
val exceptional_succs : t -> node -> node list
|
||
8 years ago
|
|
||
9 years ago
|
(** exceptional predescessors *)
|
||
|
val exceptional_preds : t -> node -> node list
|
||
8 years ago
|
|
||
9 years ago
|
val start_node : t -> node
|
||
8 years ago
|
|
||
9 years ago
|
val exit_node : t -> node
|
||
8 years ago
|
|
||
8 years ago
|
val proc_desc : t -> Procdesc.t
|
||
8 years ago
|
|
||
9 years ago
|
val nodes : t -> node list
|
||
8 years ago
|
|
||
8 years ago
|
val from_pdesc : Procdesc.t -> t
|
||
8 years ago
|
|
||
|
val is_loop_head : Procdesc.t -> node -> bool
|
||
9 years ago
|
end
|
||
|
|
||
8 years ago
|
module DefaultNode : Node with type t = Procdesc.Node.t and type id = Procdesc.Node.id
|
||
9 years ago
|
|
||
8 years ago
|
module InstrNode : Node with type t = Procdesc.Node.t and type id = Procdesc.Node.id * index
|
||
9 years ago
|
|
||
9 years ago
|
(** Forward CFG with no exceptional control-flow *)
|
||
8 years ago
|
module Normal : S with type t = Procdesc.t
|
||
9 years ago
|
and type node = DefaultNode.t
|
||
|
and type id = DefaultNode.id
|
||
9 years ago
|
|
||
9 years ago
|
(** Forward CFG with exceptional control-flow *)
|
||
8 years ago
|
module Exceptional : S with type t = Procdesc.t * DefaultNode.t list Procdesc.IdMap.t
|
||
9 years ago
|
and type node = DefaultNode.t
|
||
|
and type id = DefaultNode.id
|
||
9 years ago
|
|
||
9 years ago
|
(** Wrapper that reverses the direction of the CFG *)
|
||
|
module Backward (Base : S) : S with type t = Base.t
|
||
|
and type node = Base.node
|
||
|
and type id = Base.id
|
||
9 years ago
|
|
||
9 years ago
|
module OneInstrPerNode (Base : S with type node = DefaultNode.t and type id = DefaultNode.id) :
|
||
9 years ago
|
S with type t = Base.t
|
||
9 years ago
|
and type node = Base.node
|
||
|
and type id = Base.id * index
|
||
9 years ago
|
|
||
8 years ago
|
module NodeIdMap (CFG : S) : Caml.Map.S with type key = CFG.id
|
||
9 years ago
|
|
||
8 years ago
|
module NodeIdSet (CFG : S) : Caml.Set.S with type elt = CFG.id
|