123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Signature of standard domains *)openCore.AllopenMopsa_utilsmoduletypeDOMAIN=sig(** {2 Domain header} *)(** ***************** *)typet(** Type of an abstract elements. *)valid:tid(** Domain identifier *)valname:string(** Name of the domain *)valchecks:checklist(** List of checks performed by the domain *)valbottom:t(** Least abstract element of the lattice. *)valtop:t(** Greatest abstract element of the lattice. *)valis_bottom:t->bool(** [is_bottom a] tests whether [a] is bottom or not. *)(** {2 Lattice operators} *)(** ********************* *)valsubset:t->t->bool(** Partial order relation. [subset a1 a2] tests whether [a1] is
related to (or included in) [a2]. *)valjoin:t->t->t(** [join a1 a2] computes an upper bound of [a1] and [a2]. *)valmeet:t->t->t(** [meet a1 a2] computes a lower bound of [a1] and [a2]. *)valwiden:'actx->t->t->t(** [widen ctx a1 a2] computes an upper bound of [a1] and [a2] that
ensures stabilization of ascending chains. *)valmerge:t->t*change->t*change->t(** [merge pre (post1, change1) (post2, change2)] synchronizes two divergent
post-conditions [post1] and [post2] using a common pre-condition [pre].
Diverging post-conditions emerge after a fork-join trajectory in the
abstraction DAG (e.g., a reduced product).
The changes [change1] and [change2] represent a journal of internal statements
executed during the the computation of the post-conditions over the
two trajectories.
*)(** {2 Transfer functions} *)(** ********************** *)valinit:program->('a,t)man->'aflow->'apostoption(** Initialization function *)valexec:stmt->('a,t)man->'aflow->'apostoption(** Post-state of statements *)valeval:expr->('a,t)man->'aflow->'aevaloption(** Evaluation of expressions *)valask:('a,'r)query->('a,t)man->'aflow->('a,'r)casesoption(** Handler of queries *)(** {2 Printing} *)(** ************ *)valprint_state:printer->t->unit(** Printer of an abstract element. *)valprint_expr:('a,t)man->'aflow->printer->expr->unit(** Printer of an expression's value *)end(*==========================================================================*)(** {2 Registration} *)(*==========================================================================*)(** Instrument transfer functions with some useful pre/post processing *)moduleInstrument(D:DOMAIN):DOMAINwithtypet=D.t=structincludeD(* Add stmt to the changes of the domain *)letexecstmtmanflow=ifis_change_tracker_enabled()thenD.execstmtmanflow|>OptionExt.lift@@funres->Cases.map_changes(funchangesflow->man.add_changestmt[]flowchanges)reselseD.execstmtmanflow(* Remove duplicate evaluations *)letevalexpmanflow=D.evalexpmanflow|>OptionExt.lift@@Eval.remove_duplicatesman.latticeendletdomains:(moduleDOMAIN)listref=ref[]letregister_standard_domaindom=letmoduleD=(valdom:DOMAIN)indomains:=(moduleInstrument(D))::!domainsletfind_standard_domainname=List.find(fundom->letmoduleD=(valdom:DOMAIN)incompareD.namename=0)!domainsletmem_standard_domainname=List.exists(fundom->letmoduleD=(valdom:DOMAIN)incompareD.namename=0)!domainsletstandard_domain_names()=List.map(fundom->letmoduleD=(valdom:DOMAIN)inD.name)!domains