123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172(****************************************************************************)(* 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_utilopenPrintfletopt_interactive=reffalsemoduleState=structtypeistate={ctx:Initial_check.ctx;ast:Type_check.typed_ast;effect_info:Effects.side_effect_info;env:Type_check.Env.t;default_sail_dir:string;config:Yojson.Basic.toption;}letinitial_istateconfigdefault_sail_dir={ctx=Initial_check.initial_ctx;ast=empty_ast;effect_info=Effects.empty_side_effect_info;env=Type_check.initial_env;default_sail_dir;config;}endopenStateletargstr="<"^str^">"|>Util.yellow|>Util.clearletcommandstr=str|>Util.green|>Util.cleartypeaction=|ArgStringofstring*(string->action)|ArgIntofstring*(int->action)|Actionof(State.istate->State.istate)|ActionUnitof(State.istate->unit)letcommands=ref[]letget_commandcmd=List.assoc_optcmd!commandsletall_commands()=!commandsletreflect_typaction=letopenType_checkinletrecarg_typs=function|ArgString(_,next)->string_typ::arg_typs(next"")|ArgInt(_,next)->int_typ::arg_typs(next0)|Action_->[]|ActionUnit_->[]inmatchactionwithAction_->function_typ[unit_typ]unit_typ|_->function_typ(arg_typsaction)unit_typletgenerate_helpnamehelpaction=letrecargs=function|ArgString(hint,next)->arghint::args(next"")|ArgInt(hint,next)->arghint::args(next0)|Action_->[]|ActionUnit_->[]inletargs=argsactioninlethelp=matchString.split_on_char':'helpwith|[]->assertfalse|prefix::splits->List.map(funsplit->matchString.split_on_char' 'splitwith|[]->assertfalse|subst::rest->ifStr.string_match(Str.regexp"^[0-9]+")subst0then(letnum_str=Str.matched_stringsubstinletnum_end=Str.match_end()inletpunct=String.subsubstnum_end(String.lengthsubst-num_end)inList.nthargs(int_of_stringnum_str)^punct^" "^String.concat" "rest)elsecommand(":"^subst)^" "^String.concat" "rest)splits|>String.concat""|>funrest->prefix^restinsprintf"%s %s - %s"Util.(name|>green|>clear)(String.concat", "args)helpletrun_actionistatecmdargumentaction=letargs=String.split_on_char','argumentinletreccallargsaction=match(args,action)with|x::xs,ArgString(hint,next)->callxs(next(String.trimx))|x::xs,ArgInt(hint,next)->letx=String.trimxinifStr.string_match(Str.regexp"^[0-9]+$")x0thencallxs(next(int_of_stringx))elsefailwith(sprintf"%s argument %s must be an non-negative integer"(commandcmd)(arghint))|_,Actionact->actistate|_,ActionUnitact->actistate;istate|_,_->failwith(sprintf"Bad arguments for %s, see (%s %s)"(commandcmd)(command":help")(commandcmd))incallargsactionletregister_command~name~helpaction=commands:=(":"^name,(help,action))::!commands