123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* 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 licenses/LGPLv2.1). *)(* *)(**************************************************************************)openCil_typesopenCil_datatypeletpretty_stmtfmts=Cil_printer.pp_stmtfmtsmodulePrinter=structtypet=string*(Stmt.Hptset.toptionKinstr.Hashtbl.t)moduleV=structtypet=Cil_types.stmt*boolletprettyfmtv=pretty_stmtfmtvendmoduleE=structtypet=(V.t*V.t)letsrce=fsteletdste=sndeendletiter_vertexf(_,graph)=letdo_skipostdom=lets=matchkiwithKstmts->s|_->assertfalseinPostdominators_parameters.debug"iter_vertex %d : %a\n"s.sidV.prettys;lethas_postdom=matchpostdomwithNone->false|_->trueinf(s,has_postdom)inKinstr.Hashtbl.iterdo_sgraphletiter_edges_ef(_,graph)=letdo_skipostdom=lets=matchkiwithKstmts->s|_->assertfalseinmatchpostdomwithNone->()|Somepostdom->letdo_edgep=f((s,true),(p,true))inStmt.Hptset.iterdo_edgepostdominKinstr.Hashtbl.iterdo_sgraphletvertex_name(s,_)=string_of_ints.sidletgraph_attributes(title,_)=[`Labeltitle]letdefault_vertex_attributes_g=[`Style`Filled]letdefault_edge_attributes_g=[]letvertex_attributes(s,has_postdom)=letattrib=[]inlettxt=Format.asprintf"%a"V.prettysinletattrib=(`Labeltxt)::attribinletcolor=ifhas_postdomthen0x7FFFD4else0xFF0000inletattrib=(`Shape`Box)::attribinletattrib=(`Fillcolorcolor)::attribinattribletedge_attributes_s=[]letget_subgraph_v=NoneendmodulePostdomGraph=Graph.Graphviz.Dot(Printer)letget_postdomkfgraphs=trymatchKinstr.Hashtbl.findgraph(Kstmts)with|None->Stmt.Hptset.empty|Somel->lwithNot_found->tryletpostdom=!Db.Postdominators.stmt_postdominatorskfsinletpostdom=Stmt.Hptset.removespostdominPostdominators_parameters.debug"postdom for %d:%a = %a\n"s.sidpretty_stmtsStmt.Hptset.prettypostdom;Kinstr.Hashtbl.addgraph(Kstmts)(Somepostdom);postdomwithDb.PostdominatorsTypes.Top->Kinstr.Hashtbl.addgraph(Kstmts)None;raiseDb.PostdominatorsTypes.Top(** [s_postdom] are [s] postdominators, including [s].
* We don't have to represent the relation between s and s.
* And because the postdom relation is transitive, if [p] is in [s_postdom],
* we can remove [p_postdom] from [s_postdom] in order to have a clearer graph.
*)letreducekfgraphs=letremoveps_postdom=ifStmt.Hptset.memps_postdomthentryletp_postdom=get_postdomkfgraphpinlets_postdom=Stmt.Hptset.diffs_postdomp_postdomins_postdomwithDb.PostdominatorsTypes.Top->assertfalse(* p postdom s -> cannot be top *)elses_postdom(* p has already been removed from s_postdom *)intryletpostdom=get_postdomkfgraphsinletpostdom=Stmt.Hptset.foldremovepostdompostdominPostdominators_parameters.debug"new postdom for %d:%a = %a\n"s.sidpretty_stmtsStmt.Hptset.prettypostdom;Kinstr.Hashtbl.replacegraph(Kstmts)(Somepostdom)withDb.PostdominatorsTypes.Top->()letbuild_reduced_graphkfgraphstmts=List.iter(reducekfgraph)stmtsletbuild_dotfilenamekf=matchkf.fundecwith|Definition(fct,_)->letstmts=fct.sallstmtsinletgraph=Kinstr.Hashtbl.create(List.lengthstmts)inlet_=build_reduced_graphkfgraphstmtsinletname=Kernel_function.get_namekfinlettitle="Postdominators for function "^nameinletfile=open_outfilenameinPostdomGraph.output_graphfile(title,graph);close_outfile|Declaration_->Kernel.error"cannot compute for a function without body %a"Kernel_function.prettykf(*
Local Variables:
compile-command: "make -C ../../.."
End:
*)