123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)(** Slicing module public macros that should be used to avoid using the type
* concrete definition from other modules.
*)(**/**)openCil_typesopenPdg_types(**/**)(** {2 Options} *)letstr_level_optionopt=matchoptwith|SlicingInternals.DontSlice->"DontSlice"|SlicingInternals.DontSliceButComputeMarks->"DontSliceButComputeMarks"|SlicingInternals.MinNbSlice->"MinNbSlice"|SlicingInternals.MaxNbSlice->"MaxNbSlice"lettranslate_num_to_slicing_leveln=matchnwith|0->SlicingInternals.DontSlice|1->SlicingInternals.DontSliceButComputeMarks|2->SlicingInternals.MinNbSlice|3->SlicingInternals.MaxNbSlice|_->raiseSlicingTypes.WrongSlicingLevelletget_default_level_optiondefined_function=ifdefined_function||(SlicingParameters.Mode.SliceUndef.get())thentranslate_num_to_slicing_level(SlicingParameters.Mode.Calls.get())elseSlicingInternals.DontSlice(** {2 Getting [fct_info] and others } *)(** {4 getting [svar]} *)letfi_svarfi=Kernel_function.get_vifi.SlicingInternals.fi_kfletff_svarff=fi_svar(ff.SlicingInternals.ff_fct)(** {4 getting [fct_info]} *)(** Get the fct_info if it exists or build a new fct_info. *)letget_kf_fikf=letfct_var=Kernel_function.get_vikfinletproj=SlicingState.get()intryCil_datatype.Varinfo.Hashtbl.findproj.SlicingInternals.functionsfct_varwithNot_found->letfi_def,is_def=matchkf.fundecwith|Declaration_->None,false|Definition_whenEva.Analysis.use_spec_instead_of_definitionkf->None,false|Definition(def,_)->Somedef,trueinletnew_fi={SlicingInternals.fi_kf=kf;SlicingInternals.fi_def=fi_def;SlicingInternals.fi_top=None;SlicingInternals.fi_level_option=get_default_level_optionis_def;SlicingInternals.fi_init_marks=None;SlicingInternals.fi_slices=[];SlicingInternals.fi_next_ff_num=1;SlicingInternals.f_called_by=[]}inCil_datatype.Varinfo.Hashtbl.addproj.SlicingInternals.functionsfct_varnew_fi;new_filetfold_fifacc=letproj=SlicingState.get()inCil_datatype.Varinfo.Hashtbl.fold(fun_vfiacc->faccfi)proj.SlicingInternals.functionsacc(** {4 getting num id} *)letget_ff_idff=ff.SlicingInternals.ff_id(** {4 getting names} *)letfi_namefi=letsvar=fi_svarfiinsvar.Cil_types.vname(** get the name of the function corresponding to that slice. *)letff_nameff=letfi=ff.SlicingInternals.ff_fctinletff_id=get_ff_idffinletfct_name=fi_namefiin(fct_name^"_slice_"^(string_of_int(ff_id)))letf_namef=matchfwith|SlicingInternals.FctSrcfct->fi_namefct|SlicingInternals.FctSlicedff->ff_nameffletff_src_nameff=fi_nameff.SlicingInternals.ff_fct(** {4 getting [kernel_function]} *)letget_fi_kffi=fi.SlicingInternals.fi_kfletget_ff_kfff=letfi=ff.SlicingInternals.ff_fctinget_fi_kffiletget_pdg_kfpdg=PdgTypes.Pdg.get_kfpdg(** {4 getting PDG} *)letget_fi_pdgfi=letkf=get_fi_kffiinPdg.Api.getkfletget_ff_pdgff=get_fi_pdgff.SlicingInternals.ff_fct(** {4 getting the slicing level} *)letff_slicing_levelff=ff.SlicingInternals.ff_fct.SlicingInternals.fi_level_optionletchange_fi_slicing_levelfislicing_level=fi.SlicingInternals.fi_level_option<-slicing_level(** @raise SlicingTypes.WrongSlicingLevel if [n] is not valid.
* *)letchange_slicing_levelkfn=letslicing_level=translate_num_to_slicing_levelninletfi=get_kf_fikfin(* build if if it doesn't exist *)change_fi_slicing_levelfislicing_level(** {2 functions and slices} *)letfi_slicesfi=fi.SlicingInternals.fi_slices(** {4 Comparisons} *)letequal_fifi1fi2=letv1=fi_svarfi1inletv2=fi_svarfi2inCil_datatype.Varinfo.equalv1v2letequal_ffff1ff2=(equal_fiff1.SlicingInternals.ff_fctff2.SlicingInternals.ff_fct)&&((get_ff_idff1)=(get_ff_idff2))(** {2 Calls} *)letsame_callc1c2=(c1.sid=c2.sid)letsame_ff_call(f1,c1)(f2,c2)=equal_fff1f2&&same_callc1c2letis_call_stmtstmt=matchstmt.skindwith|Instr(Call_|Local_init(_,ConsInit_,_))->true|_->falseletget_called_kfcall_stmt=matchcall_stmt.skindwith|Instr(Call_)->(matchEva.Results.calleecall_stmtwith|[kf]->kf|_->raiseSlicingTypes.PtrCallExpr)|Instr(Local_init(_,ConsInit(f,_,_),_))->Globals.Functions.getf|_->invalid_arg"Not a call statement !"letis_variadickf=letvarf=Kernel_function.get_vikfinmatchvarf.vtypewith|TFun(_,_,is_variadic,_)->is_variadic|_->assertfalse(** get the [fct_info] of the called function, if we know it *)letget_fi_callcall=tryletkf=get_called_kfcallinifis_variadickfthenNoneelseletfct_info=get_kf_fikfinSomefct_infowithSlicingTypes.PtrCallExpr->Noneletis_src_fun_calledkf=letfi=get_kf_fikfinmatchfi.SlicingInternals.f_called_bywith[]->false|_->trueletis_src_fun_visiblekf=letis_fi_topfi=matchfi.SlicingInternals.fi_topwithNone->false|Some_->trueinis_src_fun_calledkf||is_fi_top(get_kf_fikf)letfi_has_persistent_selectionfi=(matchfi.SlicingInternals.fi_init_markswithNone->false|_->true)lethas_persistent_selectionkf=letfi=get_kf_fikfinfi_has_persistent_selectionfi(*
Local Variables:
compile-command: "make -C ../../.."
End:
*)