Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file cfg_analysis.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121(**************************************************************************)(* This file is part of the Codex semantics library. *)(* *)(* Copyright (C) 2013-2025 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* 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, version 2.1. *)(* *)(* It 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. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file LICENSE). *)(* *)(**************************************************************************)(** The CFG is created from the instruction graph like so: the vertices are the
* basic blocks of the instruction graph, and every edge is labelled with the
* DBA instructions contained in their destination basic block, plus an
* expression assumed to be zero or non-zero if the source basic block ended
* with a conditional jump. *)moduleV_hashable=structtypecall_stack=Virtual_address.tlist(** CFG vertex type: a basic block, characterized by a leader address and a
* call stack. *)typet=Virtual_address.t*call_stacklethash(addr,stack)=Hashtbl.hash(Virtual_address.to_intaddr,List.mapVirtual_address.to_intstack)letreccompare_listcmpl1l2=matchl1,l2with|[],[]->0|x::xs,y::ys->letc=cmpxyinifc=0thencompare_listcmpxsyselsec|[],_::_->-1|_::_,[]->1letcompare(a1,s1)(a2,s2)=letc=Virtual_address.comparea1a2inifc=0thencompare_listVirtual_address.compares1s2elsecletequalxy=comparexy=0endmoduleV=structincludeBasic_types.Collection_make.Hashed(V_hashable)typecall_stack=V_hashable.call_stacktypelabel=tletlabelx=xletcreatex=xlethash=V_hashable.hashletequal=V_hashable.equalletpp_stackfmtstack=letopenFormatinifstack<>[]thenfprintffmt"_";pp_print_list~pp_sep:(funfmt()->fprintffmt"_")Virtual_address.ppfmtstackletprettyfmt(leader,stack)=letopenFormatinfprintffmt"%a%a"Virtual_address.ppleaderpp_stackstackendmoduleE=structtypevertex=V.ttypet=vertex*vertextypelabel=unitletcreatex()y=(x,y)letlabel_=()letsrc(x,_)=xletdst(_,y)=yletcompare(x1,x2)(y1,y2)=letc=V.comparex1y1inifc<>0thencelseV.comparex2y2letequalxy=comparexy=0lethash(x,y)=Hashtbl.hash(V.hashx,V.hashy)letprettyfmt(v1,v2)=Format.fprintffmt"(%a->%a)"V.prettyv1V.prettyv2endmoduleCfg_0=Graph.Imperative.Digraph.ConcreteBidirectional(V)moduleCfg=struct(* Include and constrain using destructive substitution in order to redefine
* modules [V] and [E]. *)moduleV=VmoduleE=Einclude(Cfg_0:moduletypeofCfg_0withmoduleV:=VandmoduleE:=E)endmoduleCfgRegex=Fixpoint.Regex.Make(Cfg.E)moduleReduce=Fixpoint.Reduce.Make(Cfg)(CfgRegex)moduleWto=Fixpoint.Wto.Make(Cfg.V)