123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)moduletypeS=Graph.Graphviz.GraphWithDotAttrsletinitial_service_rootscg=letroots=Options.Service_roots.get()inletroots=ifKernel_function.Set.is_emptyrootsthen(* if possible, use the main function as initial root *)tryKernel_function.Set.singleton(fst(Globals.entry_point()))withGlobals.No_such_entry_point_->(* otherwise use every uncalled function *)Cg.G.fold_vertex(funvset->ifCg.G.in_degreecgv=0thenKernel_function.Set.addvsetelseset)cgKernel_function.Set.emptyelserootsin(* Add the callees of initial roots as roots *)Kernel_function.Set.fold(funvset->Cg.G.fold_succKernel_function.Set.addcgvset)rootsroots(* Intermediate module because of Ocaml:
"The parameter cannot be eliminated in the result type.
Please bind the argument to a module identifier." *)moduleG_for_S=structletdatatype_name="Callgraph.Cg"moduleV=structincludeCg.G.Vletid=Kernel_function.get_idletname=Kernel_function.get_nameletattributes=Cg.Graphviz_attributes.vertex_attributesletentry_point()=trySome(fst(Globals.entry_point()))withGlobals.No_such_entry_point_->Noneendinclude(Cg.G:Graph.Sig.GwithmoduleV:=Vandtypet=Cg.G.t)endmoduleS=Service_graph.Make(G_for_S)moduleG=S.Service_graphmoduleGraphviz_attributes=S.TPletentry_point=S.entry_pointletis_rootkf=(S.vertexkf).Service_graph.is_rootmoduleState=State_builder.Option_ref(S.Service_graph.Datatype)(structletname="Callgraph.Services"letdependencies=[Cg.self;Kernel.MainFunction.self]end)moduleStateHook=Hook.Build(S.Service_graph.Datatype)(* eta-expansion required to mask optional argument [?project] *)letis_computed()=State.is_computed()letself=State.selfletadd_hook=StateHook.extendletcompute()=letcg=Cg.get()inletisr=initial_service_rootscginletisr_names=Kernel_function.Set.fold(funkfacc->Datatype.String.Set.add(Kernel_function.get_namekf)acc)isrDatatype.String.Set.emptyinletsg=S.computecgisr_namesinState.mark_as_computed();StateHook.applysg;sgletget()=State.memocomputeletcompute()=ignore(compute())moduleSubgraph=Subgraph.Make(G)(S.Service_graph.Datatype)(structletself=State.selfletname=State.nameletget=getletvertex=S.vertexend)letdump()=letsg=Subgraph.get()inService_graph.frama_c_displayfalse;Options.dumpS.output_graphsg(*
Local Variables:
compile-command: "make -C ../../.."
End:
*)