Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file scattered.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162(****************************************************************************)(* 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_defsopenAst_utilletfuncl_id(FCL_aux(FCL_Funcl(id,_),_))=idletreclast_scattered_funclid=function|DEF_scattered(SD_aux(SD_funclfuncl,_))::_whenId.compare(funcl_idfuncl)id=0->false|_::defs->last_scattered_funcliddefs|[]->trueletreclast_scattered_mapclid=function|DEF_scattered(SD_aux(SD_mapcl(mid,_),_))::_whenId.comparemidid=0->false|_::defs->last_scattered_mapcliddefs|[]->true(* Nothing cares about these and the AST should be changed *)letfake_rec_optl=Rec_aux(Rec_nonrec,gen_locl)letno_tannot_optl=Typ_annot_opt_aux(Typ_annot_opt_none,gen_locl)letrecget_union_clausesid=function|DEF_scattered(SD_aux(SD_unioncl(uid,tu),_))::defswhenId.compareiduid=0->tu::get_union_clausesiddefs|_::defs->get_union_clausesiddefs|[]->[]letrecfilter_union_clausesid=function|DEF_scattered(SD_aux(SD_unioncl(uid,tu),_))::defswhenId.compareiduid=0->filter_union_clausesiddefs|def::defs->def::filter_union_clausesiddefs|[]->[]letrecdescatter'funclsmapcls=function(* For scattered functions we collect all the seperate function
clauses until we find the last one, then we turn that function
clause into a DEF_fundef containing all the clauses. *)|DEF_scattered(SD_aux(SD_funclfuncl,(l,_)))::defswhenlast_scattered_funcl(funcl_idfuncl)defs->letclauses=matchBindings.find_opt(funcl_idfuncl)funclswith|Someclauses->List.rev(funcl::clauses)|None->[funcl]inDEF_fundef(FD_aux(FD_function(fake_rec_optl,no_tannot_optl,clauses),(gen_locl,Type_check.empty_tannot)))::descatter'funclsmapclsdefs|DEF_scattered(SD_aux(SD_funclfuncl,_))::defs->letid=funcl_idfunclinbeginmatchBindings.find_optidfunclswith|Someclauses->descatter'(Bindings.addid(funcl::clauses)funcls)mapclsdefs|None->descatter'(Bindings.addid[funcl]funcls)mapclsdefsend(* Scattered mappings are handled the same way as scattered functions *)|DEF_scattered(SD_aux(SD_mapcl(id,mapcl),(l,tannot)))::defswhenlast_scattered_mapcliddefs->letclauses=matchBindings.find_optidmapclswith|Someclauses->List.rev(mapcl::clauses)|None->[mapcl]inDEF_mapdef(MD_aux(MD_mapping(id,no_tannot_optl,clauses),(gen_locl,tannot)))::descatter'funclsmapclsdefs|DEF_scattered(SD_aux(SD_mapcl(id,mapcl),_))::defs->beginmatchBindings.find_optidmapclswith|Someclauses->descatter'funcls(Bindings.addid(mapcl::clauses)mapcls)defs|None->descatter'funcls(Bindings.addid[mapcl]mapcls)defsend(* For scattered unions, when we find a union declaration we
immediately grab all the future clauses and turn it into a
regular union declaration. *)|DEF_scattered(SD_aux(SD_variant(id,typq),(l,_)))::defs->lettus=get_union_clausesiddefsinbeginmatchtuswith|[]->raise(Reporting.err_generall"No clauses found for scattered union type")|_->DEF_type(TD_aux(TD_variant(id,typq,tus,false),(gen_locl,Type_check.empty_tannot)))::descatter'funclsmapcls(filter_union_clausesiddefs)end(* Therefore we should never see SD_unioncl... *)|DEF_scattered(SD_aux(SD_unioncl_,(l,_)))::_->raise(Reporting.err_unreachablel__POS__"Found union clause during de-scattering")|def::defs->def::descatter'funclsmapclsdefs|[]->[]letdescatterast={astwithdefs=descatter'Bindings.emptyBindings.emptyast.defs}