123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)openServeropenCil_typesletpackage=Package.package~plugin:"studia"~name:"studia"~title:"Studia"()typeeffects={direct:stmtlist;indirect:stmtlist;}moduleEffects=structopenServer.Datatyperecordletrecord:recordRecord.signature=Record.signature()moduleLocation=Data.Jpair(Kernel_ast.Function)(Kernel_ast.Marker)letdirect=Record.fieldrecord~name:"direct"~descr:(Markdown.plain"List of statements with direct effect.")(moduleData.Jlist(Location))letindirect=Record.fieldrecord~name:"indirect"~descr:(Markdown.plain"List of statements with indirect effect.")(moduleData.Jlist(Location))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=letoutput_stmtstmt=letkf=Kernel_function.find_englobing_kfstmtinkf,Printer_tag.PStmtStart(kf,stmt)inR.default|>R.setdirect(List.mapoutput_stmteffects.direct)|>R.setindirect(List.mapoutput_stmteffects.indirect)|>R.to_jsonendletcompute_writeszone=letreads=Writes.computezoneinletaddacc=function|Writes.Assignstmt|CallDirectstmt->{accwithdirect=stmt::acc.direct}|CallIndirectstmt->{accwithindirect=stmt::acc.indirect}|FormalInit(_vi,callsites)->letcalls=List.flatten(List.mapsndcallsites)in{accwithdirect=calls@acc.direct}|GlobalInit(_vi,_initinfo)->acc(* for now ignore global initializations *)inletempty={direct=[];indirect=[];}inList.fold_leftaddemptyreadsletcompute_readszone=letreads=Reads.computezoneinletaddacc=function|Reads.Directstmt->{accwithdirect=stmt::acc.direct}|Indirectstmt->{accwithindirect=stmt::acc.indirect}inletempty={direct=[];indirect=[];}inList.fold_leftaddemptyreadsletlval_locationkinstrlval=Eva.Results.(before_kinstrkinstr|>eval_addresslval|>as_zone)let()=Request.register~package~kind:`GET~name:"getReadsLval"~descr:(Markdown.plain"Get the list of statements that read a lval.")~input:(moduleKernel_ast.Lval)~output:(moduleEffects)(fun(kinstr,lval)->compute_reads(lval_locationkinstrlval))let()=Request.register~package~kind:`GET~name:"getWritesLval"~descr:(Markdown.plain"Get the list of statements that write a lval.")~input:(moduleKernel_ast.Lval)~output:(moduleEffects)(fun(kinstr,lval)->compute_writes(lval_locationkinstrlval))