123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- Array Dimensions --- *)(* -------------------------------------------------------------------------- *)(* private *)typet=[`Fix|`Ext]listletof_dims=List.map(functionNone->`Ext|Some_->`Fix)letcompare(ps:t)(qs:t)=Stdlib.comparepsqsletrecpp_hdimsfmt=function|[]->()|`Fix::ps->pp_ndims`Fix1fmtps|`Ext::ps->pp_ndims`Ext1fmtpsandpp_ndimspkfmt=function|q::qswhenp=q->pp_ndimsp(succk)fmtqs|ps->pp_kdimpkfmt;pp_hdimsfmtpsandpp_kdimpkfmt=beginifp=`FixthenFormat.pp_print_charfmt'd';ifp=`ExtthenFormat.pp_print_charfmt'w';ifk>1thenFormat.pp_print_intfmtk;endletpp_suffix_idfmt=function|[]|[`Fix]->()|ps->Format.pp_print_charfmt'_';pp_hdimsfmtpsletprettyfmtps=pp_hdimsfmtps(* -------------------------------------------------------------------------- *)(* --- Compilation Environment --- *)(* -------------------------------------------------------------------------- *)openLang.Ftypeenv={size_var:varlist;(* size variables *)size_val:termlist;(* size values *)index_var:varlist;(* index variables *)index_val:termlist;(* index values *)index_range:predlist;(* indices are in range of size variables *)index_offset:termlist;(* polynomial of indices multiplied by previous sizes *)length:termoption;(* number of array cells ; None is infinite *)}letreccollectrank=function|[]->{size_var=[];size_val=[];index_var=[];index_val=[];index_range=[];index_offset=[];length=Somee_one;}|d::ds->letdenv=collect(succrank)dsinletk_base=matchrankwith0->"i"|1->"j"|_->"k"inletk_var=Lang.freshvar~basename:k_baseQed.Logic.Intinletk_val=e_vark_varinletk_ofs=e_prod(k_val::denv.size_val)inmatchdwith|`Ext->{denvwithindex_var=k_var::denv.index_var;index_val=k_val::denv.index_val;index_offset=k_ofs::denv.index_offset;length=None;}|`Fix->letn_base=matchrankwith0->"n"|1->"m"|_->"d"inletn_var=Lang.freshvar~basename:n_baseQed.Logic.Intinletn_val=e_varn_varinletk_inf=p_leqe_zerok_valinletk_sup=p_ltk_valn_valinletlength=matchdenv.lengthwith|None->None|Somelen->Some(e_muln_vallen)in{size_var=n_var::denv.size_var;size_val=n_val::denv.size_val;index_var=k_var::denv.index_var;index_val=k_val::denv.index_val;index_offset=k_ofs::denv.index_offset;index_range=k_inf::k_sup::denv.index_range;length;}letcc_env=collect0letreccc_dimsns=matchnswith|[]->[]|Somen::ns->e_intn::cc_dimsns|None::ns->cc_dimsnsletcc_tauteds=Lang.t_matrixte(List.lengthds)(* -------------------------------------------------------------------------- *)(* --- Dimension Merging --- *)(* -------------------------------------------------------------------------- *)letrecdo_mergeds1ds2=matchds1,ds2with|[],[]->[]|[],_|_,[]->raiseExit|d1::ds1,d2::ds2->letd=matchd1,d2with|None,_|_,None->None|Somen1,Somen2->ifn1=n2thend1elseraiseExitind::do_mergeds1ds2letmergeds1ds2=trySome(do_mergeds1ds2)withExit->None(* -------------------------------------------------------------------------- *)