123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat a l'energie atomique et aux energies *)(* 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). *)(* *)(**************************************************************************)letdkey=Wp_parameters.register_category"rte"typet={name:string;cint:bool;kernel:(unit->bool);option:string;status:unit->RteGen.Api.status_accessor;}letoptionname=tryname=""||Dynamic.Parameter.Bool.getname()with_->falseletstatusdbkf=try(* Absolutely forbidden to use 'set' from RteGen.Api :
this disables the generation of the associated RTE. *)let(_,_,get)=db()ingetkfwithFailure_->Wp_parameters.warning~once:true"Missing RTE plug-in: can not generate conditions";falseletalways_=trueletconfigure~update~generatekfcintrte=ifnotrte.cint||rte.kernel()thenbegin(* need RTE guard, but kernel option is set *)ifnot(statusrte.statuskf)thenbeginifoptionrte.optionthenletmsg=ifgeneratethen"generate"else"missing"inWp_parameters.debug~dkey"function %a: %s rte for %s"Kernel_function.prettykfmsgrte.name;elseWp_parameters.warning~once:true~current:false"-wp-rte can annotate %s because %s is not set"rte.namerte.option;update:=true;endendelseifgeneratethenmatchcintwith|Cint.Machine->()(* RTE has been set *)|Cint.Natural->Wp_parameters.warning~once:true~current:false"-wp-rte and model nat require kernel to warn against %s"rte.nameletgenerator=[{name="memory access";kernel=always;option="-rte-mem";cint=false;status=RteGen.Api.get_memAccess_status};{name="division by zero";kernel=always;option="-rte-div";cint=false;status=RteGen.Api.get_divMod_status};{name="signed overflow";cint=true;kernel=Kernel.SignedOverflow.get;option="";status=RteGen.Api.get_signedOv_status};{name="unsigned overflow";cint=true;kernel=Kernel.UnsignedOverflow.get;option="";status=RteGen.Api.get_unsignedOv_status};{name="signed downcast";cint=true;option="";kernel=Kernel.SignedDowncast.get;status=RteGen.Api.get_signed_downCast_status};{name="unsigned downcast";cint=true;option="";kernel=Kernel.UnsignedDowncast.get;status=RteGen.Api.get_unsignedDownCast_status};{name="invalid bool value";cint=false;option="-warn-invalid-bool";kernel=Kernel.InvalidBool.get;status=RteGen.Api.get_bool_value_status};]letgeneratemodelkf=letupdate=reffalseinletcint=WpContext.on_context(model,WpContext.Kfkf)Cint.current()inList.iter(configure~update~generate:truekfcint)generator;if!updatethenRteGen.Api.annotate_kfkfletgenerate_allmodel=Wp_parameters.iter_kf(generatemodel)letmissing_guardsmodelkf=letupdate=reffalseinletcint=WpContext.on_context(model,WpContext.Kfkf)Cint.current()inList.iter(configure~update~generate:falsekfcint)generator;!update(* -------------------------------------------------------------------------- *)