123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176(****************************************************************************)(* 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"). *)(* *)(* SPDX-License-Identifier: BSD-2-Clause *)(****************************************************************************)openAst_defsopenType_checkopenInteractive.StatemoduleStringMap=Map.Make(String)typetarget={name:string;options:(Flag.t*Arg.spec*string)list;pre_parse_hook:unit->unit;pre_initial_check_hook:stringlist->unit;pre_rewrites_hook:typed_ast->Effects.side_effect_info->Env.t->unit;rewrites:(string*Rewrites.rewriter_arglist)list;action:stringoption->istate->unit;asserts_termination:bool;supports_abstract_types:bool;supports_runtime_config:bool;}letnametgt=tgt.nameletrun_pre_parse_hooktgt=tgt.pre_parse_hookletrun_pre_rewrites_hooktgt=tgt.pre_rewrites_hookletrun_pre_initial_check_hooktgt=tgt.pre_initial_check_hookletactiontgt=tgt.actionletrewritestgt=Rewrites.instantiate_rewritestgt.rewritesletasserts_terminationtgt=tgt.asserts_terminationletsupports_abstract_typestgt=tgt.supports_abstract_typesletsupports_runtime_configtgt=tgt.supports_runtime_configletregistered=ref[]lettargets=refStringMap.emptyletthe_target=refNoneletregister~name?flag?description:desc?(options=[])?(pre_parse_hook=fun()->())?(pre_initial_check_hook=fun_->())?(pre_rewrites_hook=fun___->())?(rewrites=[])?(asserts_termination=false)?(supports_abstract_types=false)?(supports_runtime_config=false)action=letset_target()=match!the_targetwith|None->the_target:=Somename|Sometgt->prerr_endline("Cannot use multiple Sail targets simultaneously: "^tgt^" and "^name);exit1inletdesc=matchdescwithSomedesc->desc|None->"invoke the Sail "^name^" target"inletflag=matchflagwithSomeflag->flag|None->nameinlettgt={name;options=(Flag.create~prefix:[flag]"",Arg.Unitset_target,desc)::options;pre_parse_hook;pre_initial_check_hook;pre_rewrites_hook;rewrites;action;asserts_termination;supports_abstract_types;supports_runtime_config;}inregistered:=name::!registered;targets:=StringMap.addnametgt!targets;tgtletempty_action__=()letget_the_target()=match!the_targetwithSomename->StringMap.find_optname!targets|None->Noneletget~name=StringMap.find_optname!targetsletextract_registered()=letnames=!registeredinregistered:=[];List.revnamesletextract_options()=letopts=StringMap.bindings!targets|>List.map(fun(_,tgt)->tgt.options)|>List.concatintargets:=StringMap.map(funtgt->{tgtwithoptions=[]})!targets;optslet()=letopenInteractiveinActionUnit(fun_->List.iter(fun(name,_)->print_endlinename)(StringMap.bindings!targets))|>register_command~name:"list_targets"~help:"list available Sail targets for use with :target";ArgString("target",funname->Action(funistate->matchget~namewith|Sometgt->letrws=rewritestgtinletctx,ast,effect_info,env=Rewrites.rewriteistate.ctxistate.effect_infoistate.envrwsistate.astin{istatewithctx;ast;env;effect_info}|None->print_endline("No target "^name);istate))|>register_command~name:"rewrites"~help:"perform rewrites for a target. See :list_targets for a list of targets";ArgString("target",funname->ArgString("out",funout->ActionUnit(funistate->matchget~namewith|Sometgt->actiontgt(Someout)istate|None->print_endline("No target "^name))))|>register_command~name:"target"~help:"invoke Sail target. See :list_targets for a list of targets. out parameter is equivalent to command line -o \
option"