Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file dhunk_analysis.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(**************************************************************************)(* 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). *)(* *)(**************************************************************************)moduleV=structtypet=Dba.idtypelabel=tletlabelx=xletcreatex=xletequal=(=)lethash=Hashtbl.hashletcompare=Stdlib.compareletprettyfmtx=Format.pp_print_intfmtxendmoduleE=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.prettyv2endmoduleG_0=Graph.Persistent.Digraph.ConcreteBidirectional(V)moduleG_1=structmoduleV=VmoduleE=Einclude(G_0:moduletypeofG_0withmoduleV:=VandmoduleE:=E)endmoduleG=structincludeG_1(*
let vertex_name v =
Format.asprintf "%i" v
let graph_attributes _ = []
let edge_attributes _ = []
let default_edge_attributes _ = []
let vertex_attributes _ = []
let default_vertex_attributes _ = []
let get_subgraph _ = None
*)end(* Graph printing. Useful for debugging. *)(*
module Output = Graph.Graphviz.Dot(G)
*)moduleDhunk_regex=Fixpoint.Regex.Make(G.E)moduleReduce=Fixpoint.Reduce.Make(G)(Dhunk_regex)moduleWto_alg=Fixpoint.Wto.Make(G.V)openDba2Codexletaddr_of_target{Dba.base;Dba.id}=assert(id=0);baseletgraph_of_dhunkdhunk:G.t*(Dba.id*Virtual_address.toption)list=letopenDba.Instrinletnext=function|Assign(_,_,nxt)->[Jump_Innernxt]|SJump(Dba.JInnernxt,_)->[Jump_Innernxt]|SJump(Dba.JOutertarget,_)->[Jump_Outer(addr_of_targettarget)]|DJump_->[Jump_Dynamic]|If(_,Dba.JInnerift_nxt,iff_nxt)->[Jump_Innerift_nxt;Jump_Inneriff_nxt]|If(_,Dba.JOuterift_addr,iff_nxt)->[Jump_Outer(addr_of_targetift_addr);Jump_Inneriff_nxt]|Stop_->raise@@Invalid_argument"regex_of_dhunk: stop encountered"|Assert(_,nxt)->[Jump_Innernxt]|Assume(_,nxt)->[Jump_Innernxt]|Nondet(_,nxt)->[Jump_Innernxt]|Undef(_,nxt)->[Jump_Innernxt]inletadd_exit_or_edgeid(acc_gr,acc_exits)=function|Jump_Innernxt->G.add_edgeacc_gridnxt,acc_exits|Jump_Outeraddr->acc_gr,(id,Someaddr)::acc_exits|Jump_Dynamic->acc_gr,(id,None)::acc_exitsinletrecauxacc_graphacc_exitsid=ifid>=Dhunk.lengthdhunkthenacc_graph,acc_exitselseleti=matchDhunk.instdhunkidwithSomei->i|_->raise@@Failure"graph_of_dhunk: Dhunk.get"inletacc_graph',acc_exits'=List.fold_left(add_exit_or_edgeid)(acc_graph,acc_exits)@@nextiinauxacc_graph'acc_exits'(id+1)inauxG.(add_vertexempty0)[]0letexit_regexesdhunk:(Dba.id*Dhunk_regex.t*Virtual_address.toption)list=letgraph,exits=graph_of_dhunkdhunkinletwto=Wto_alg.partition~pref:(fun__->0)~init:0~succs:(G.succgraph)inletregexes=Reduce.compute_exprsgraphwtoinList.map(fun(id,addr)->(id,Hashtbl.findregexesid,addr))exits