123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2025 *)(* 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). *)(* *)(**************************************************************************)openServerletpackage=Package.package~plugin:"studia"~name:"studia"~title:"Studia"()typeeffects={direct:Printer_tag.localizablelist;indirect:Printer_tag.localizablelist}letempty={direct=[];indirect=[];}moduleEffects=structopenServer.Datatyperecordletrecord:recordRecord.signature=Record.signature()letdirect=Record.fieldrecord~name:"direct"~descr:(Markdown.plain"List of statements with direct effect.")(moduleData.Jlist(Kernel_ast.Marker))letindirect=Record.fieldrecord~name:"indirect"~descr:(Markdown.plain"List of statements with indirect effect.")(moduleData.Jlist(Kernel_ast.Marker))letdata=Record.publishrecord~package~name:"effects"~descr:(Markdown.plain"Statements that read or write a location.")moduleR:Record.Swithtyper=record=(valdata)typet=effectsletjtype=R.jtypeletto_jsoneffects=R.default|>R.setdirecteffects.direct|>R.setindirecteffects.indirect|>R.to_jsonendletstmt_marker=Printer_tag.localizable_of_stmtletglobal_markervi=Printer_tag.localizable_of_declaration(SGlobalvi)letcompute_writeszone=tryletreads=Writes.computezoneinletaddacc=function|Writes.Assignstmt|CallDirectstmt->{accwithdirect=stmt_markerstmt::acc.direct}|CallIndirectstmt->{accwithindirect=stmt_markerstmt::acc.indirect}|FormalInit(_vi,callsites)->letcalls=List.concat_mapsndcallsitesin{accwithdirect=List.mapstmt_markercalls@acc.direct}|GlobalInit(vi,_initinfo)->{accwithdirect=global_markervi::acc.direct}inList.fold_leftaddemptyreadswithexn->Options.warning"Error when computing writes (%s)"(Printexc.to_stringexn);emptyletcompute_readszone=tryletreads=Reads.computezoneinletaddacc=function|Reads.Directstmt->{accwithdirect=stmt_markerstmt::acc.direct}|Indirectstmt->{accwithindirect=stmt_markerstmt::acc.indirect}inList.fold_leftaddemptyreadswithexn->Options.warning"Error when computing reads (%s)"(Printexc.to_stringexn);emptyletlval_locationkinstrlval=Eva.Results.(before_kinstrkinstr|>eval_addresslval|>as_zone)lettlval_locationkinstrtlval=letcvalue=Eva.Results.(before_kinstrkinstr|>get_cvalue_model)inletterm=Logic_const.term(TLvaltlval)(Cil.typeOfTermLvaltlval)inletaccess=Locations.Readinletzones=Eva.Logic_inout.tlval_to_zonesCode_annotcvalueaccessterminmatchzoneswith|Somezones->zones.over|None->Data.failure"Cannot evaluate the memory location of %a"Printer.pp_term_lvaltlvalletmarker_location(marker:Printer_tag.localizable)=matchmarkerwith|PLval(_kf,kinstr,lval)->lval_locationkinstrlval|PGlobal(GVar(vi,_,_)|GVarDecl(vi,_))|PVDecl(_,_,vi)->Locations.zone_of_varinfovi|PTermLval(_kf,kinstr,_property,tlval)->tlval_locationkinstrtlval|_->Data.failure"%a is not an lvalue"Printer_tag.pp_localizablemarkerlet()=Request.register~package~kind:`GET~name:"getReadsLval"~descr:(Markdown.plain"Get the list of statements that read a lval.")~input:(moduleKernel_ast.Marker)~output:(moduleEffects)(funmarker->compute_reads(marker_locationmarker))let()=Request.register~package~kind:`GET~name:"getWritesLval"~descr:(Markdown.plain"Get the list of statements that write a lval.")~input:(moduleKernel_ast.Marker)~output:(moduleEffects)(funmarker->compute_writes(marker_locationmarker))