Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file nl_flow.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(****************************************************************************)(* Sail *)(* *)(* Sail and the Sail architecture models here, comprising all files and *)(* directories except the ASL-derived Sail code in the aarch64 directory, *)(* are subject to the BSD two-clause licence below. *)(* *)(* The ASL derived parts of the ARMv8.3 specification in *)(* aarch64/no_vector and aarch64/full are copyright ARM Ltd. *)(* *)(* Copyright (c) 2013-2021 *)(* Kathyrn Gray *)(* Shaked Flur *)(* Stephen Kell *)(* Gabriel Kerneis *)(* Robert Norton-Wright *)(* Christopher Pulte *)(* Peter Sewell *)(* Alasdair Armstrong *)(* Brian Campbell *)(* Thomas Bauereiss *)(* Anthony Fox *)(* Jon French *)(* Dominic Mulligan *)(* Stephen Kell *)(* Mark Wassell *)(* Alastair Reid (Arm Ltd) *)(* *)(* All rights reserved. *)(* *)(* This work was partially supported by EPSRC grant EP/K008528/1 <a *)(* href="http://www.cl.cam.ac.uk/users/pes20/rems">REMS: Rigorous *)(* Engineering for Mainstream Systems</a>, an ARM iCASE award, EPSRC IAA *)(* KTF funding, and donations from Arm. This project has received *)(* funding from the European Research Council (ERC) under the European *)(* Union’s Horizon 2020 research and innovation programme (grant *)(* agreement No 789108, ELVER). *)(* *)(* This software was developed by SRI International and the University of *)(* Cambridge Computer Laboratory (Department of Computer Science and *)(* Technology) under DARPA/AFRL contracts FA8650-18-C-7809 ("CIFV") *)(* and FA8750-10-C-0237 ("CTSRD"). *)(* *)(* Redistribution and use in source and binary forms, with or without *)(* modification, are permitted provided that the following conditions *)(* are met: *)(* 1. Redistributions of source code must retain the above copyright *)(* notice, this list of conditions and the following disclaimer. *)(* 2. Redistributions in binary form must reproduce the above copyright *)(* notice, this list of conditions and the following disclaimer in *)(* the documentation and/or other materials provided with the *)(* distribution. *)(* *)(* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' *)(* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *)(* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *)(* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR *)(* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *)(* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *)(* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *)(* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *)(* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *)(* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *)(* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *)(* SUCH DAMAGE. *)(****************************************************************************)openAstopenAst_utilletopt_nl_flow=reffalseletrecescapes(E_aux(aux,_))=matchauxwith|E_throw_->true|E_block[]->false|E_blockexps->escapes(List.hd(List.revexps))|_->falseletis_bitvector_literal(L_aux(aux,_))=matchauxwithL_bin_|L_hex_->true|_->falseletbitvector_unsigned(L_aux(aux,_))=letopenSail_libinmatchauxwith|L_binstr->uint(List.mapbin_char(Util.string_to_liststr))|L_hexstr->uint(bits_of_stringstr)|_->assertfalseletrecpat_id(P_aux(aux,_))=matchauxwithP_idid->Someid|P_as(_,id)->Someid|P_var(pat,_)->pat_idpat|_->Noneletadd_assertcond(E_aux(aux,(l,uannot))asexp)=letmsg=mk_lit_exp(L_string"")inletassertion=locate(fun_->gen_locl)(mk_exp(E_assert(cond,msg)))inmatchauxwith|E_blockexps->E_aux(E_block(assertion::exps),(l,empty_uannot))|_->E_aux(E_block(assertion::[exp]),(l,uannot))(* If we know that x != bitv, then after any let y = unsigned(x) we
will also know that y != unsigned(bitv) *)letmodify_unsignedidvalue(E_aux(aux,annot)asexp)=matchauxwith|E_let((LB_aux(LB_val(pat,E_aux(E_app(f,[E_aux(E_idid',_)]),_)),_)aslb),exp')when(string_of_idf="unsigned"||string_of_idf="UInt")&&Id.compareidid'=0->beginmatchpat_idpatwith|None->exp|Someuid->E_aux(E_let(lb,add_assert(mk_exp(E_app_infix(mk_exp(E_iduid),mk_id"!=",mk_lit_exp(L_numvalue))))exp'),annot)end|_->expletanalyze'exps=matchexpswith|E_aux(E_if(cond,then_exp,_),_)::_whenescapesthen_exp->beginmatchcondwith|E_aux(E_app_infix(E_aux(E_idid,_),op,E_aux(E_litlit,_)),_)|E_aux(E_app_infix(E_aux(E_litlit,_),op,E_aux(E_idid,_)),_)whenstring_of_idop="=="&&is_bitvector_literallit->letvalue=bitvector_unsignedlitinList.map(modify_unsignedidvalue)exps|_->expsend|_->expsletanalyzeexps=if!opt_nl_flowthenanalyze'expselseexps