123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146(**************************************************************************)(* *)(* This file is part of the Frama-C's Luncov plug-in. *)(* *)(* Copyright (C) 2012-2022 *)(* 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 LICENSE) *)(* *)(**************************************************************************)openCommonsopenCil_types(** Define the kind of strategy to apply when performing vwap analysis **)typestrategy=ANNOT_PARAM|ANNOT_LABEL|ANNOT_FUN|ANNOT_ALL|ANNOT_NONE|ANNOT_LABPARAM(* For assume insertion *)letluncov_vwap_emitter=Emitter.create"LuncovVWAP"[Emitter.Code_annot]~correctness:[]~tuning:[]letprint_label_statusfdata=letlabels=Data_labels.get_label_idsdatainList.iter(funi->letl=Data_labels.get_statusdataiinFormat.fprintff"label #%d: %a"iData_labels.pp_statusl)labelsletto_strategys=matchswith|"none"->ANNOT_NONE|"all"->ANNOT_ALL|"function"->ANNOT_FUN|"param"->ANNOT_PARAM|"label"->ANNOT_LABEL|"label+param"->ANNOT_LABPARAM|_->assertfalseclassannot_collectorsidannots=object(self)inheritVisitor.frama_c_inplacevallabel_kf_id=Instrument_label.get_kf_ididvalmutablelabel_kf=Kernel_function.dummy()valmutablein_label=false(* precond s \notin {ANNOT_NONE} *)method!vfuncfundec=letkf=Option.getself#current_kfinifKernel_function.get_idkf=label_kf_idthenbeginlabel_kf<-kf;ifs=ANNOT_PARAM||s=ANNOT_LABPARAM||s=ANNOT_ALLthenself#collect_param_annotationsfundec;ifs=ANNOT_PARAMthenCil.SkipChildrenelseCil.DoChildrenendelseCil.SkipChildren(* precond s \notin {ANNOT_NONE, ANNOT_PARAM} *)method!vstmt_auxstmt=matchInstrument.is_stmt_by_sidstmt.sidwith|[lblid]whenlblid=id->in_label<-true;self#collect_stmt_annotationsstmt;Cil.ChangeDoChildrenPost(stmt,funstmt->in_label<-false;stmt)|_->ifs=ANNOT_ALL||s=ANNOT_FUN||(in_label&&s=ANNOT_LABEL)thenself#collect_stmt_annotationsstmt;Cil.DoChildrenmethodprivatecollect_param_annotationsfdec=letvars=collect_fun_paramfdecinletfirst_stmt=List.hdfdec.sbody.bstmtsinself#collect_value_annotationsfirst_stmtvarsmethodprivatecollect_stmt_annotationsstmt=letvars=collect_variablesstmtinself#collect_value_annotationsstmtvarsmethodprivatecollect_value_annotationsstmtvars=leton_varvar=matchCommons.exp_to_pred~at:stmtvarwith|Somep->Queue.add(label_kf,stmt,p)annots|_->()inCil_datatype.ExpStructEq.Set.iteron_varvarsendletadd_future_annot(kf,stmt,pred)=Options.debug~level:2"add value annotation `%a` at %a"Printer.pp_predicate_nodepred.pred_contentPrinter.pp_location(Cil_datatype.Stmt.locstmt);lettop_pred=Logic_const.toplevel_predicate~kind:Checkpredinletcode_annotation=Logic_const.new_code_annotation(AAssert([],top_pred))inAnnotations.add_code_annot~kfluncov_vwap_emitterstmtcode_annotation;letprops=Property.ip_of_code_annotkfstmtcode_annotationinList.iter(funprop->Property_status.emitluncov_vwap_emitter~hyps:[]propProperty_status.True)propsletwvap_property_checkerstratvalueprj=let_,wp_check=Wp_singlecore.wp_property_checkerinletcheck~labelip=letnew_ast=Ast.get()inletannots=Queue.create()inletcollect_annots()=Visitor.visitFramacFile(newannot_collectorstratlabelannots)new_astinCommons.with_projectvalueprjcollect_annots();Queue.iteradd_future_annotannots;wp_check~labelipin("WVAP",check)letcompute?(force=false)datahdata=letstrat=to_strategy(Options.Strategy.get())inOptions.feedback"start combined detection (aka VWAP)";Options.debug"%a"print_label_statusdata;EVA.compute~forcedatahdata;Options.debug"%a"print_label_statusdata;letprj=Project.current()inbeginmatchstratwith|ANNOT_NONE->Wp_singlecore.compute~forcedatahdata|_->Wp_singlecore.compute~force~checker:(wvap_property_checkerstratprj)datahdataend;Options.debug"%a"print_label_statusdata;Options.feedback"combined detection done"