123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290(****************************************************************************)(* 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 *)(****************************************************************************)openAstmoduleBig_int=Nat_big_nummoduleKid=structtypet=kidletcompare(Kid_aux(Varv1,_))(Kid_aux(Varv2,_))=String.comparev1v2endmoduleKind=structtypet=kindletcompare(K_aux(aux1,_))(K_aux(aux2,_))=match(aux1,aux2)with|K_int,K_int->0|K_type,K_type->0|K_bool,K_bool->0|K_int,_->1|_,K_int->-1|K_type,_->1|_,K_type->-1endmoduleKOpt=structtypet=kinded_idletcompare(KOpt_aux(KOpt_kind(k1,kid1),_))(KOpt_aux(KOpt_kind(k2,kid2),_))=letlex_ordc1c2=ifc1=0thenc2elsec1inlex_ord(Kid.comparekid1kid2)(Kind.comparek1k2)endmoduleId=structtypet=idletcompareid1id2=match(id1,id2)with|Id_aux(And_bool,_),Id_aux(And_bool,_)->0|Id_aux(Or_bool,_),Id_aux(Or_bool,_)->0|Id_aux(Idx,_),Id_aux(Idy,_)->String.comparexy|Id_aux(Operatorx,_),Id_aux(Operatory,_)->String.comparexy|Id_aux(Id_,_),_->-1|_,Id_aux(Id_,_)->1|Id_aux(Operator_,_),_->-1|_,Id_aux(Operator_,_)->1|Id_aux(And_bool,_),_->-1|_,Id_aux(And_bool,_)->1endletlex_ordfgx1x2y1y2=matchfx1x2with0->gy1y2|n->nletrecnexp_compare(Nexp_aux(nexp1,_))(Nexp_aux(nexp2,_))=letlex_ord(c1,c2)=ifc1=0thenc2elsec1inmatch(nexp1,nexp2)with|Nexp_idv1,Nexp_idv2->Id.comparev1v2|Nexp_varkid1,Nexp_varkid2->Kid.comparekid1kid2|Nexp_constantc1,Nexp_constantc2->Big_int.comparec1c2|Nexp_app(op1,args1),Nexp_app(op2,args2)->letlex1=Id.compareop1op2inletlex2=List.lengthargs1-List.lengthargs2inletlex3=iflex2=0thenList.fold_left2(funln1n2->lex_ord(l,nexp_comparen1n2))0args1args2else0inlex_ord(lex1,lex_ord(lex2,lex3))|Nexp_times(n1a,n1b),Nexp_times(n2a,n2b)|Nexp_sum(n1a,n1b),Nexp_sum(n2a,n2b)|Nexp_minus(n1a,n1b),Nexp_minus(n2a,n2b)->lex_ord(nexp_comparen1an2a,nexp_comparen1bn2b)|Nexp_expn1,Nexp_expn2->nexp_comparen1n2|Nexp_negn1,Nexp_negn2->nexp_comparen1n2|Nexp_if(i1,t1,e1),Nexp_if(i2,t2,e2)->letlex1=nc_comparei1i2inletlex2=nexp_comparet1t2inletlex3=nexp_comparee1e2inlex_ord(lex1,lex_ord(lex2,lex3))|Nexp_constant_,_->-1|_,Nexp_constant_->1|Nexp_id_,_->-1|_,Nexp_id_->1|Nexp_var_,_->-1|_,Nexp_var_->1|Nexp_neg_,_->-1|_,Nexp_neg_->1|Nexp_exp_,_->-1|_,Nexp_exp_->1|Nexp_minus_,_->-1|_,Nexp_minus_->1|Nexp_sum_,_->-1|_,Nexp_sum_->1|Nexp_times_,_->-1|_,Nexp_times_->1|Nexp_if_,_->-1|_,Nexp_if_->1andnc_compare(NC_aux(nc1,_))(NC_aux(nc2,_))=match(nc1,nc2)with|NC_idid1,NC_idid2->Id.compareid1id2|NC_equal(t1,t2),NC_equal(t3,t4)|NC_not_equal(t1,t2),NC_not_equal(t3,t4)->lex_ordtyp_arg_comparetyp_arg_comparet1t3t2t4|NC_ge(n1,n2),NC_ge(n3,n4)|NC_gt(n1,n2),NC_gt(n3,n4)|NC_le(n1,n2),NC_le(n3,n4)|NC_lt(n1,n2),NC_lt(n3,n4)->lex_ordnexp_comparenexp_comparen1n3n2n4|NC_set(n1,s1),NC_set(n2,s2)->lex_ordnexp_compare(Util.compare_listNat_big_num.compare)n1n2s1s2|NC_or(nc1,nc2),NC_or(nc3,nc4)|NC_and(nc1,nc2),NC_and(nc3,nc4)->lex_ordnc_comparenc_comparenc1nc3nc2nc4|NC_app(f1,args1),NC_app(f2,args2)->lex_ordId.compare(Util.compare_listtyp_arg_compare)f1f2args1args2|NC_varv1,NC_varv2->Kid.comparev1v2|NC_true,NC_true|NC_false,NC_false->0|NC_equal_,_->-1|_,NC_equal_->1|NC_ge_,_->-1|_,NC_ge_->1|NC_gt_,_->-1|_,NC_gt_->1|NC_le_,_->-1|_,NC_le_->1|NC_lt_,_->-1|_,NC_lt_->1|NC_not_equal_,_->-1|_,NC_not_equal_->1|NC_set_,_->-1|_,NC_set_->1|NC_or_,_->-1|_,NC_or_->1|NC_and_,_->-1|_,NC_and_->1|NC_app_,_->-1|_,NC_app_->1|NC_var_,_->-1|_,NC_var_->1|NC_true,_->-1|_,NC_true->1|NC_id_,_->-1|_,NC_id_->1andtyp_compare(Typ_aux(t1,_))(Typ_aux(t2,_))=match(t1,t2)with|Typ_internal_unknown,Typ_internal_unknown->0|Typ_idid1,Typ_idid2->Id.compareid1id2|Typ_varkid1,Typ_varkid2->Kid.comparekid1kid2|Typ_fn(ts1,t2),Typ_fn(ts3,t4)->(matchUtil.compare_listtyp_comparets1ts3with0->typ_comparet2t4|n->n)|Typ_bidir(t1,t2),Typ_bidir(t3,t4)->(matchtyp_comparet1t3with0->typ_comparet2t4|n->n)|Typ_tuplets1,Typ_tuplets2->Util.compare_listtyp_comparets1ts2|Typ_exist(ks1,nc1,t1),Typ_exist(ks2,nc2,t2)->(matchUtil.compare_listKOpt.compareks1ks2with|0->(matchnc_comparenc1nc2with0->typ_comparet1t2|n->n)|n->n)|Typ_app(id1,ts1),Typ_app(id2,ts2)->(matchId.compareid1id2with0->Util.compare_listtyp_arg_comparets1ts2|n->n)|Typ_internal_unknown,_->-1|_,Typ_internal_unknown->1|Typ_id_,_->-1|_,Typ_id_->1|Typ_var_,_->-1|_,Typ_var_->1|Typ_fn_,_->-1|_,Typ_fn_->1|Typ_bidir_,_->-1|_,Typ_bidir_->1|Typ_tuple_,_->-1|_,Typ_tuple_->1|Typ_exist_,_->-1|_,Typ_exist_->1andtyp_arg_compare(A_aux(ta1,_))(A_aux(ta2,_))=match(ta1,ta2)with|A_nexpn1,A_nexpn2->nexp_comparen1n2|A_typt1,A_typt2->typ_comparet1t2|A_boolnc1,A_boolnc2->nc_comparenc1nc2|A_nexp_,_->-1|_,A_nexp_->1|A_typ_,_->-1|_,A_typ_->1letbit_compareb1b2=letopenBitinmatch(b1,b2)withB0,B0->0|B0,B1->-1|B1,B0->1|B1,B1->0letlit_compare(L_aux(l1,_))(L_aux(l2,_))=match(l1,l2)with|L_unit,L_unit->0|L_unit,_->-1|_,L_unit->1|L_true,L_true->0|L_true,_->-1|_,L_true->1|L_false,L_false->0|L_false,_->-1|_,L_false->1|L_numn1,L_numn2->Big_int_Z.compare_big_intn1n2|L_num_,_->-1|_,L_num_->1|L_hexh1,L_hexh2->List.comparebit_compare(BitList.of_hex_lith1)(BitList.of_hex_lith2)|L_hex_,_->-1|_,L_hex_->1|L_binb1,L_binb2->List.comparebit_compare(BitList.of_bin_litb1)(BitList.of_bin_litb2)|L_bin_,_->-1|_,L_bin_->1|L_strings1,L_strings2->String.compares1s2|L_string_,_->-1|_,L_string_->1|L_realr1,L_realr2->Q.compare(Util.Rational.from_rocqr1)(Util.Rational.from_rocqr2)moduleNexp=structtypet=nexpletcompare=nexp_compareendmoduleNC=structtypet=n_constraintletcompare=nc_compareendmoduleTyp=structtypet=typletcompare=typ_compareendmoduleTypArg=structtypet=typ_argletcompare=typ_arg_compareendmoduleLit=structtypet=litletcompare=lit_compareendmoduleBindings=Map.Make(Id)moduleIdSet=Set.Make(Id)moduleKBindings=Map.Make(Kid)moduleKidSet=Set.Make(Kid)moduleKOptSet=Set.Make(KOpt)moduleKOptMap=Map.Make(KOpt)moduleNexpSet=Set.Make(Nexp)moduleNexpMap=Map.Make(Nexp)moduleTypMap=Map.Make(Typ)moduleNCMap=Map.Make(NC)moduleLitSet=Set.Make(Lit)