123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)(** {2 Internals types}
Internals type definitions should be hidden to the outside world,
but it is not really possible to have abstract types since Slicing has to
use Db.Slicing functions... *)openCil_datatypeopenPdg_types(** {3 About options} *)(** associate a level to each function in order to control how it will be
* specialized. This is only a hint used when the tool has to make a choice,
* but it doesn't forbid to the user to do whatever he wants
* (like building slices for a [DontSlice] function). *)typelevel_option=|DontSlice(** don't build slice for the function :
ie. always call the source function. *)|DontSliceButComputeMarks(** don't slice the called functions,
* but compute the marks for them *)|MinNbSlice(** try to use existing slices, create at most one *)|MaxNbSlice(** most precise slices
(but merge slices with the same visibility,
even if they don't have the same marks) *)(** {3 About function slice} *)(** Kinds of elementary marks. *)typemark=CavofPdgTypes.Dpd.t|Spareletcompare_markm1m2=ifm1==m2then0elsematchm1,m2with|Spare,Spare->0|Cavd1,Cavd2->PdgTypes.Dpd.compared1d2|Cav_,Spare->-1|Spare,Cav_->1(** Each PDG element has 2 marks to deal with interprocedural propagation *)typepdg_mark={m1:mark;m2:mark}letpdg_mark_packed_descr=Structural_descr.p_abstract(* Ok: Dpd.t is in fact int *)letcompare_pdg_markp1p2=ifp1==p2then0elseletr=compare_markp1.m1p2.m1inifr=0thencompare_markp1.m2p2.m2elser(** Type for all the informations related to any function,
* even if we don't have its definition. *)typefct_info={fi_kf:Cil_types.kernel_function;fi_def:Cil_types.fundecoption;mutablefi_top:pdg_markoption;(** indicates if the function is marked top (=> src visible) *)mutablefi_level_option:level_option;(** level of specialisation for this function *)mutablefi_init_marks:ff_marksoption;(** the marks that must be in every slices of that function *)mutablefi_slices:fct_slicelist;(** the list of the slices already computed for this function. *)mutablefi_next_ff_num:int;(** the number to assign to the next slice. *)mutablef_called_by:called_by;(** calls in slices that call source fct *)}(** to represent where a function is called. *)andcalled_by=(fct_slice*Cil_types.stmt)list(** Function slice :
created as soon as there is a criterion to compute it,
even if the slice itself hasn't been computed yet.
*)andfct_slice={ff_fct:fct_info;ff_id:int;mutableff_marks:ff_marks;mutableff_called_by:called_by}(** [fct_id] is used to identify either a source function or a sliced one.*)andfct_id=|FctSrcoffct_info(** source function *)|FctSlicedoffct_slice(** sliced function *)andcalled_fct=|CallSrcoffct_infooption(** call the source function (might be unknown if the call uses pointer) *)|CallSliceoffct_slice(** information about a call in a slice which gives the function to call *)andcall_info=called_fctoption(** main part of a slice = mapping between the function elements
and information about them in the slice. *)andmarks_index=(pdg_mark,call_info)PdgIndex.FctIndex.tandff_marks=PdgTypes.Pdg.t*marks_indexandproject={functions:fct_infoVarinfo.Hashtbl.t;mutableactions:criterionlist;}(** Slicing criterion at the application level.
When applied, they are translated into [fct_criterion]
*)andappli_criterion=|CaGlobalDataofLocations.Zone.t(** select all that is necessary to compute the given location. *)|CaCalloffct_info(** select all that is necessary to call the given function.
* Its application generates requests to add persistent selection
* to all the function callers. *)|CaOther(** Base criterion for the functions. These are the only one that can
really generate function slices. All the other criteria are
translated in more basic ones.
Note that to build such a base criterion, the PDG has to be already
computed.
*)andfct_base_criterion=pdg_markPdgMarks.select(** Used to identify a location (zone) at a given program point.
* The boolean tell if the point is before (true) or after the statement *)andloc_point=Cil_types.stmt*Locations.Zone.t*bool(** [node_or_dpds] tells how we want to select nodes,
or some of their dependencies (see {!fct_user_crit}). *)andnode_or_dpds=CwNode|CwAddrDpds|CwDataDpds|CwCtrlDpds(** Tells which marks we want to put in the slice of a function *)andfct_user_crit=|CuSelectofpdg_markPdgMarks.select|CuTopofpdg_mark(** the function has probably no PDG,
but we nonetheless give a mark to propagate *)(** kinds of actions that can be apply to a function *)andfct_crit=|CcUserMarkoffct_user_crit(** add marks to a slice *)|CcChooseCallofCil_types.stmt(** have to choose what function to call here. *)|CcChangeCallofCil_types.stmt*called_fct(** call the [called_fct] for the given call [Cil_types.stmt] *)|CcMissingOutputsofCil_types.stmt*(pdg_markPdgMarks.select)*bool(** this call is affected to a function that doesn't compute enough
* outputs : we will have to choose between adding outputs to that slice,
* or call another one. The boolean tells if the modifications would
* change the visibility of some outputs. *)|CcMissingInputsofCil_types.stmt*(pdg_markPdgMarks.select)*bool(** the function calls a slice that has been modified :
* and doesn't compute not enough inputs.
* We will have to choose between adding marks to this function,
* and call another slice.
* The boolean tells if the modifications would
* change the visibility of some inputs. *)|CcPropagateof(pdg_markPdgMarks.select)(** simply propagate the given marks *)|CcExamineCallsofpdg_markPdgMarks.info_called_outputs(** Slicing criterion for a function. *)andfct_criterion={cf_fct:fct_id;(** Identification of the {b RESULT} of this filter.
* When it a a slice, it might be an existing slice that will be modified,
* or a new one will be created during application.
* When it is the source function, it means what the criterion has to be
* applied on each existing slice, and stored into the initial marks of
* the function.
*)cf_info:fct_crit}(** A slicing criterion is either an application level criterion,
or a function level one. *)andcriterion=CrAppliofappli_criterion|CrFctoffct_criterion(** {2 Internals values} *)(** {3 For the datatypes of these internals types} *)letdummy_pdg_mark={m1=Spare;m2=Spare}(** The whole project. *)letdummy_project={functions=Varinfo.Hashtbl.create0;actions=[]}letdummy_fct_info={fi_kf=Kernel_function.dummy();fi_def=None;fi_top=None;fi_level_option=DontSlice;fi_init_marks=None;fi_slices=[];fi_next_ff_num=0;f_called_by=[];}letdummy_marks_index=PdgIndex.FctIndex.create0letdummy_ff_marks=(PdgTypes.Pdg.top(Kernel_function.dummy()),dummy_marks_index)letdummy_fct_slice={ff_fct=dummy_fct_info;ff_id=0;ff_marks=dummy_ff_marks;ff_called_by=[]}letdummy_fct_user_crit=CuTopdummy_pdg_mark(*
Local Variables:
compile-command: "make -C ../../.."
End:
*)