better names in AbstractDomain and TransferFunctions modules

Reviewed By: jeremydubreil

Differential Revision: D3140288

fb-gh-sync-id: 0bc08a4
fbshipit-source-id: 0bc08a4
master
Sam Blackshear 9 years ago committed by Facebook Github Bot 6
parent 967dcec7f1
commit c499645f6f

@ -9,7 +9,7 @@
module F = Format module F = Format
module type AbstractDomain = sig module type S = sig
type astate type astate
val initial : astate val initial : astate
@ -18,45 +18,43 @@ module type AbstractDomain = sig
val join : astate -> astate -> astate val join : astate -> astate -> astate
val widen : prev:astate -> next:astate -> num_iters:int -> astate val widen : prev:astate -> next:astate -> num_iters:int -> astate
val pp : F.formatter -> astate -> unit val pp : F.formatter -> astate -> unit
end end
module BottomLiftedAbstractDomain (A : AbstractDomain) : AbstractDomain = struct module BottomLifted (Domain : S) = struct
type astate = type astate =
| Bottom | Bottom
| NonBottom of A.astate | NonBottom of Domain.astate
let is_bottom astate = let is_bottom astate =
astate = Bottom astate = Bottom
let initial = NonBottom A.initial let initial = NonBottom Domain.initial
let (<=) ~lhs ~rhs = match lhs, rhs with let (<=) ~lhs ~rhs = match lhs, rhs with
| Bottom, _ -> true | Bottom, _ -> true
| _ , Bottom -> false | _ , Bottom -> false
| NonBottom lhs, NonBottom rhs -> A.(<=) ~lhs ~rhs | NonBottom lhs, NonBottom rhs -> Domain.(<=) ~lhs ~rhs
let join astate1 astate2 = let join astate1 astate2 =
match astate1, astate2 with match astate1, astate2 with
| Bottom, _ -> astate2 | Bottom, _ -> astate2
| _, Bottom -> astate1 | _, Bottom -> astate1
| NonBottom a1, NonBottom a2 -> NonBottom (A.join a1 a2) | NonBottom a1, NonBottom a2 -> NonBottom (Domain.join a1 a2)
let widen ~prev ~next ~num_iters = let widen ~prev ~next ~num_iters =
match prev, next with match prev, next with
| Bottom, _ -> next | Bottom, _ -> next
| _, Bottom -> prev | _, Bottom -> prev
| NonBottom prev, NonBottom next -> NonBottom (A.widen ~prev ~next ~num_iters) | NonBottom prev, NonBottom next -> NonBottom (Domain.widen ~prev ~next ~num_iters)
let pp fmt = function let pp fmt = function
| Bottom -> F.fprintf fmt "_|_" | Bottom -> F.fprintf fmt "_|_"
| NonBottom astate -> A.pp fmt astate | NonBottom astate -> Domain.pp fmt astate
end end
(* lift a set to a domain. the elements of the set should be drawn from a *finite* collection of (* lift a set to a domain. the elements of the set should be drawn from a *finite* collection of
possible values, since the widening operator here is just union. *) possible values, since the widening operator here is just union. *)
module FiniteSetDomain (S : PrettyPrintable.PPSet) = struct module FiniteSet (S : PrettyPrintable.PPSet) = struct
include S include S
type astate = t type astate = t
@ -65,5 +63,4 @@ module FiniteSetDomain (S : PrettyPrintable.PPSet) = struct
let (<=) ~lhs ~rhs = subset lhs rhs let (<=) ~lhs ~rhs = subset lhs rhs
let join = union let join = union
let widen ~prev ~next ~num_iters:_ = union prev next let widen ~prev ~next ~num_iters:_ = union prev next
end end

@ -9,14 +9,11 @@
module L = Logging module L = Logging
open AbstractDomain
open TransferFunctions
module Make module Make
(C : ProcCfg.Wrapper) (C : ProcCfg.Wrapper)
(Sched : Scheduler.S) (Sched : Scheduler.S)
(A : AbstractDomain) (A : AbstractDomain.S)
(T : TransferFunctions with type astate = A.astate) = struct (T : TransferFunctions.S with type astate = A.astate) = struct
module S = Sched (C) module S = Sched (C)
module M = ProcCfg.NodeIdMap (C) module M = ProcCfg.NodeIdMap (C)

@ -13,7 +13,7 @@ module PvarSet = PrettyPrintable.MakePPSet(struct
let pp_element = (Pvar.pp pe_text) let pp_element = (Pvar.pp pe_text)
end) end)
module Domain = AbstractDomain.FiniteSetDomain(PvarSet) module Domain = AbstractDomain.FiniteSet(PvarSet)
module TransferFunctions = struct module TransferFunctions = struct
type astate = Domain.astate type astate = Domain.astate

@ -18,7 +18,7 @@ module VarSet = PrettyPrintable.MakePPSet(struct
let pp_element = CopyPropagation.pp_var let pp_element = CopyPropagation.pp_var
end) end)
module Domain = AbstractDomain.FiniteSetDomain(VarSet) module Domain = AbstractDomain.FiniteSet(VarSet)
(* compilers 101-style backward transfer functions for liveness analysis. gen a variable when it is (* compilers 101-style backward transfer functions for liveness analysis. gen a variable when it is
read, kill the variable when it is assigned *) read, kill the variable when it is assigned *)

@ -8,7 +8,7 @@
*) *)
module type TransferFunctions = sig module type S = sig
type astate type astate
(* {A} instr {A'}. [caller_pdesc] is the procdesc of the current procedure *) (* {A} instr {A'}. [caller_pdesc] is the procdesc of the current procedure *)

@ -10,9 +10,6 @@
module F = Format module F = Format
module L = Logging module L = Logging
open AbstractDomain
open TransferFunctions
(** utilities for writing abstract domains/transfer function tests *) (** utilities for writing abstract domains/transfer function tests *)
(** structured language that makes it easy to write small test programs in OCaml *) (** structured language that makes it easy to write small test programs in OCaml *)
@ -126,8 +123,8 @@ end
module Make module Make
(C : ProcCfg.Wrapper with type node = Cfg.Node.t) (C : ProcCfg.Wrapper with type node = Cfg.Node.t)
(S : Scheduler.S) (S : Scheduler.S)
(A : AbstractDomain) (A : AbstractDomain.S)
(T : TransferFunctions with type astate = A.astate) = struct (T : TransferFunctions.S with type astate = A.astate) = struct
open StructuredSil open StructuredSil

Loading…
Cancel
Save