123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883(******************************************************************************)(* ASLRef *)(******************************************************************************)(*
* SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
* SPDX-License-Identifier: BSD-3-Clause
*)(******************************************************************************)(* Disclaimer: *)(* This material covers both ASLv0 (viz, the existing ASL pseudocode language *)(* which appears in the Arm Architecture Reference Manual) and ASLv1, a new, *)(* experimental, and as yet unreleased version of ASL. *)(* This material is work in progress, more precisely at pre-Alpha quality as *)(* per Arm’s quality standards. *)(* In particular, this means that it would be premature to base any *)(* production tool development on this material. *)(* However, any feedback, question, query and feature request would be most *)(* welcome; those can be sent to Arm’s Architecture Formal Team Lead *)(* Jade Alglave <jade.alglave@arm.com>, or by raising issues or PRs to the *)(* herdtools7 github repository. *)(******************************************************************************)(** Provide some instrumentation backends for {!Interpreter} and {!Typing}. *)moduleSemanticsRule=structtypet=|Lit|Call|CTC|EExprList|EExprListM|ESideEffectFreeExpr|ELocalVar|EGlobalVar|EUndefIdent|Binop|BinopAnd|BinopOr|BinopImpl|Unop|ECondSimple|ECond|ESlice|ECall|EGetArray|ESliceOrEGetArrayError|ERecord|EGetBitField|EGetBitFields|EConcat|ETuple|EUnknown|EPattern|LEDiscard|LELocalVar|LEGlobalVar|LEMultiAssign|LEUndefIdentV0|LEUndefIdentV1|LESlice|LESetArray|LESetField|LESetFields|LEDestructuring|Slices|SliceSingle|SliceLength|SliceRange|SliceStar|PAll|PAny|PGeq|PLeq|PNot|PRange|PSingle|PMask|PTuple|LDDiscard|LDVar|LDTyped|LDTuple|LDUninitialisedTyped|SPass|SAssignCall|SAssignTuple|SAssign|SReturnOne|SReturnSome|SReturnNone|SSeq|SCall|SCond|SCase|SAssert|SWhile|SRepeat|SFor|SThrowNone|SThrowSomeTyped|SThrowSome|STry|SDeclSome|SDeclNone|SDebug|FUndefIdent|FPrimitive|FBadArity|FCall|Block|Loop|For|Catch|CatchNamed|CatchOtherwise|CatchNone|CatchNoThrow|TopLevel|FindCatcher|RethrowImplicit|ReadValueFrom|BuildGlobalEnvletto_string:t->string=function|Lit->"Lit"|Call->"Call"|CTC->"CTC"|EExprList->"EExprList"|EExprListM->"EExprListM"|ESideEffectFreeExpr->"ESideEffectFreeExpr"|ELocalVar->"ELocalVar"|EGlobalVar->"EGlobalVar"|Binop->"Binop"|BinopAnd->"BinopAnd"|BinopOr->"BinopOr"|BinopImpl->"BinopImpl"|Unop->"Unop"|ECond->"ECond"|ESlice->"ESlice"|ECall->"ECall"|ERecord->"ERecord"|EGetBitField->"EGetBitField"|EGetBitFields->"EGetBitFields"|EConcat->"EConcat"|ETuple->"ETuple"|EUndefIdent->"EUndefIdent"|ECondSimple->"ECondSimple"|EGetArray->"EGetArray"|ESliceOrEGetArrayError->"ESliceOrEGetArrayError"|EUnknown->"EUnknown"|EPattern->"EPattern"|LEDiscard->"LEDiscard"|LELocalVar->"LELocalVar"|LEGlobalVar->"LEGlobalVar"|LEMultiAssign->"LEMultiAssign"|LESlice->"LESlice"|LESetArray->"LESetArray"|LESetField->"LESetField"|LESetFields->"LESetFields"|LEDestructuring->"LEDestructuring"|LEUndefIdentV0->"LEUndefIdentV0"|LEUndefIdentV1->"LEUndefIdentV1"|Slices->"Slices"|SliceSingle->"SliceSingle"|SliceLength->"SliceLength"|SliceRange->"SliceRange"|SliceStar->"SliceStar"|PAll->"PAll"|PAny->"PAny"|PGeq->"PGeq"|PLeq->"PLeq"|PNot->"PNot"|PRange->"PRange"|PSingle->"PSingle"|PMask->"PMask"|PTuple->"PTuple"|LDDiscard->"LDDiscard"|LDVar->"LDVar"|LDTyped->"LDTyped"|LDTuple->"LDTuple"|LDUninitialisedTyped->"LDUninitialisedTyped"|SPass->"SPass"|SAssignCall->"SAssignCall"|SAssignTuple->"SAssignTuple"|SAssign->"SAssign"|SReturnOne->"SReturnOne"|SReturnNone->"SReturnNone"|SReturnSome->"SReturnSome"|SSeq->"SThen"|SCall->"SCall"|SCond->"SCond"|SCase->"SCase"|SAssert->"SAssert"|SWhile->"SWhile"|SRepeat->"SRepeat"|SFor->"SFor"|SThrowNone->"SThrowNone"|SThrowSomeTyped->"SThrowSomeTyped"|SThrowSome->"SThrowSome"|STry->"STry"|SDeclSome->"SDeclSome"|SDeclNone->"SDeclNone"|SDebug->"SDebug"|FUndefIdent->"FUndefIdent"|FPrimitive->"FPrimitive"|FBadArity->"FBadArity"|FCall->"FCall"|Block->"Block"|Loop->"Loop"|For->"For"|Catch->"Catch"|CatchNamed->"CatchNamed"|CatchOtherwise->"CatchOtherwise"|CatchNone->"CatchNone"|CatchNoThrow->"CatchNoThrow"|TopLevel->"TopLevel"|FindCatcher->"FindCatcher"|RethrowImplicit->"RethrowImplicit"|ReadValueFrom->"ReadValueFrom"|BuildGlobalEnv->"BuildGlobalEnv"letppfr=to_stringr|>Format.pp_print_stringfletall=[Lit;Call;CTC;EExprList;EExprListM;ESideEffectFreeExpr;ELocalVar;EGlobalVar;EUndefIdent;Binop;BinopAnd;BinopOr;BinopImpl;Unop;ECondSimple;ECond;ESlice;ECall;EGetArray;ESliceOrEGetArrayError;ERecord;EGetBitField;EGetBitFields;EConcat;ETuple;EUnknown;EPattern;LEDiscard;LELocalVar;LEGlobalVar;LEMultiAssign;LEUndefIdentV0;LEUndefIdentV1;LESlice;LESetArray;LESetField;LESetFields;LEDestructuring;Slices;SliceSingle;SliceLength;SliceRange;SliceStar;PAll;PAny;PGeq;PLeq;PNot;PRange;PSingle;PMask;PTuple;LDDiscard;LDVar;LDTyped;LDTuple;LDUninitialisedTyped;SPass;SAssignCall;SAssignTuple;SAssign;SReturnOne;SReturnSome;SReturnNone;SSeq;SCall;SCond;SCase;SAssert;SWhile;SRepeat;SFor;SThrowNone;SThrowSomeTyped;SThrowSome;STry;SDeclSome;SDeclNone;SDebug;FUndefIdent;FPrimitive;FBadArity;FCall;Block;Loop;For;Catch;CatchNamed;CatchOtherwise;CatchNone;CatchNoThrow;TopLevel;FindCatcher;RethrowImplicit;ReadValueFrom;BuildGlobalEnv;]letall_nb=List.lengthallletindex=lettbl:(t,int)Hashtbl.t=Hashtbl.createall_nbinlet()=List.iteri(funir->Hashtbl.addtblri)allinHashtbl.findtblletof_string=lettbl:(string,t)Hashtbl.t=Hashtbl.createall_nbinlet()=List.iter(funr->Hashtbl.addtbl(to_stringr|>String.lowercase_ascii)r)allinfuns->Hashtbl.findtbl(String.lowercase_asciis)endtypesemantics_rule=SemanticsRule.tmoduleSemanticsCmp:Set.OrderedTypewithtypet=semantics_rule=structtypet=semantics_ruleletcompare=compareendmoduleTypingRule=structtypet=|BuiltinSingularType|BuiltinAggregateType|BuiltinSingularOrAggregate|NamedType|AnonymousType|SingularType|AggregateType|NonPrimitiveType|PrimitiveType|Structure|Canonical|Domain|Subtype|StructuralSubtypeSatisfaction|DomainSubtypeSatisfaction|SubtypeSatisfaction|TypeSatisfaction|TypeClash|LowestCommonAncestor|CheckUnop|CheckBinop|ELit|CTC|ELocalVarConstant|ELocalVar|EGlobalVarConstantVal|EGlobalVarConstantNoVal|EGlobalVar|EUndefIdent|Binop|Unop|ECondSimple|ECond|ESlice|ECall|EGetArray|ESliceOrEGetArrayError|ERecord|EStructuredMissingField|EStructuredNotStructured|EGetRecordField|EGetBitField|EGetBadField|EGetBadBitField|EGetBadRecordField|EGetBitFieldNested|EGetBitFieldTyped|EGetBitFields|EConcatEmpty|EConcat|ETuple|EUnknown|EPattern|LEDiscard|LELocalVar|LEGlobalVar|LEUndefIdentV0|LEUndefIdentV1|LEDestructuring|LESlice|LESetArray|LESetBadStructuredField|LESetStructuredField|LESetBadBitField|LESetBitField|LESetBitFieldNested|LESetBitFieldTyped|LESetBadField|LESetFields|LEConcat|SliceSingle|SliceLength|SliceRange|SliceStar|PAll|PAny|PGeq|PLeq|PNot|PRange|PSingle|PMask|PTupleBadArity|PTuple|PTupleConflict|LDDiscard|LDVar|LDTyped|LDTuple|LDUninitialisedVar|LDUninitialisedTyped|LDUninitialisedTuple|SPass|SAssignCall|SAssignTuple|SAssign|SReturnOne|SReturnSome|SReturnNone|SSeq|SCall|SCond|SCase|SAssert|SWhile|SRepeat|SFor|SThrowNone|SThrowSomeTyped|SThrowSome|STry|SDeclSome|SDeclNone|SDebug|FUndefIdent|FPrimitive|FBadArity|FCallBadArity|FCallSetter|FCallGetter|FCallMismatch|Block|Loop|For|CatcherNone|CatcherSome|Subprogram|DeclareOneFunc|DeclareGlobalStorage|DeclareTypeDecl|Specification|TString|TReal|TBool|TNamed|TInt|TBits|TTuple|TArray|TEnumDecl|TRecordExceptionDecl|TNonDecl|TBitFieldletto_string:t->string=function|BuiltinSingularType->"BuiltinSingularType"|BuiltinAggregateType->"BuiltinAggregateType"|BuiltinSingularOrAggregate->"BuiltinSingularOrAggregate"|NamedType->"NamedType"|AnonymousType->"AnonymousType"|SingularType->"SingularType"|AggregateType->"AggregateType"|NonPrimitiveType->"NonPrimitiveType"|PrimitiveType->"PrimitiveType"|Canonical->"Canonical"|Domain->"Domain"|Structure->"Structure"|Subtype->"Subtype"|StructuralSubtypeSatisfaction->"StructuralSubtypeSatisfaction"|DomainSubtypeSatisfaction->"DomainSubtypeSatisfaction"|SubtypeSatisfaction->"SubtypeSatisfaction"|TypeSatisfaction->"TypeSatisfaction"|TypeClash->"TypeClash"|CheckUnop->"CheckUnop"|CheckBinop->"CheckBinop"|LowestCommonAncestor->"LowestCommonAncestor"|ELit->"ELit"|CTC->"CTC"|ELocalVarConstant->"ELocalVarConstant"|ELocalVar->"ELocalVar"|EGlobalVarConstantVal->"EGlobalVarConstantVal"|EGlobalVarConstantNoVal->"EGlobalVarConstantNoVal"|EGlobalVar->"EGlobalVar"|Binop->"Binop"|Unop->"Unop"|ECond->"ECond"|ESlice->"ESlice"|ECall->"ECall"|ERecord->"ERecord"|EStructuredMissingField->"EStructuredMissingField"|EStructuredNotStructured->"EStructuredNotStructured"|EGetRecordField->"EGetRecordField"|EGetBitField->"EGetBitField"|EGetBadField->"EGetBadField"|EGetBadBitField->"EGetBadBitField"|EGetBadRecordField->"EGetBadRecordField"|EGetBitFieldNested->"EGetBitFieldNested"|EGetBitFieldTyped->"EGetBitFieldTyped"|EGetBitFields->"EGetBitFields"|EConcatEmpty->"EConcatEmpty"|EConcat->"EConcat"|ETuple->"ETuple"|EUndefIdent->"EUndefIdent"|ECondSimple->"ECondSimple"|EGetArray->"EGetArray"|ESliceOrEGetArrayError->"ESliceOrEGetArrayError"|EUnknown->"EUnknown"|EPattern->"EPattern"|LEDiscard->"LEDiscard"|LELocalVar->"LELocalVar"|LEGlobalVar->"LEGlobalVar"|LESlice->"LESlice"|LESetArray->"LESetArray"|LESetBadStructuredField->"LESetBadStructuredField"|LESetStructuredField->"LESetStructuredField"|LESetBadBitField->"LESetBadBitField"|LESetBitField->"LESetBitField"|LESetBitFieldNested->"LESetBitFieldNested"|LESetBitFieldTyped->"LESetBitFieldTyped"|LESetBadField->"LESetBadField"|LESetFields->"LESetFields"|LEConcat->"LEConcat"|LEDestructuring->"LEDestructuring"|LEUndefIdentV0->"LEUndefIdentV0"|LEUndefIdentV1->"LEUndefIdentV1"|SliceSingle->"SliceSingle"|SliceLength->"SliceLength"|SliceRange->"SliceRange"|SliceStar->"SliceStar"|PAll->"PAll"|PAny->"PAny"|PGeq->"PGeq"|PLeq->"PLeq"|PNot->"PNot"|PRange->"PRange"|PSingle->"PSingle"|PMask->"PMask"|PTupleBadArity->"PTupleBadArity"|PTuple->"PTuple"|PTupleConflict->"PTupleConflict"|LDDiscard->"LDDiscardNone"|LDTyped->"LDTyped"|LDVar->"LDVar"|LDUninitialisedVar->"LDUninitialisedVar"|LDUninitialisedTyped->"LDUninitialisedTyped"|LDTuple->"LDTuple"|LDUninitialisedTuple->"LDUninitialisedTuple"|SPass->"SPass"|SAssignCall->"SAssignCall"|SAssignTuple->"SAssignTuple"|SAssign->"SAssign"|SReturnOne->"SReturnOne"|SReturnNone->"SReturnNone"|SReturnSome->"SReturnSome"|SSeq->"SThen"|SCall->"SCall"|SCond->"SCond"|SCase->"SCase"|SAssert->"SAssert"|SWhile->"SWhile"|SRepeat->"SRepeat"|SFor->"SFor"|SThrowNone->"SThrowNone"|SThrowSomeTyped->"SThrowSomeTyped"|SThrowSome->"SThrowSome"|STry->"STry"|SDeclSome->"SDeclSome"|SDeclNone->"SDeclNone"|SDebug->"SDebug"|FUndefIdent->"FUndefIdent"|FPrimitive->"FPrimitive"|FBadArity->"FBadArity"|FCallBadArity->"FCallBadArity"|FCallSetter->"FCallSetter"|FCallGetter->"FCallGetter"|FCallMismatch->"FCallMismatch"|Block->"Block"|Loop->"Loop"|For->"For"|CatcherNone->"CatcherNone"|CatcherSome->"CatcherSome"|Subprogram->"Subprogram"|DeclareOneFunc->"DeclareOneFunc"|DeclareGlobalStorage->"DeclareGlobalStorage"|DeclareTypeDecl->"DeclareTypeDecl"|Specification->"Specification"|TString->"TString"|TReal->"TReal"|TBool->"TBool"|TNamed->"TNamed"|TInt->"TInt"|TBits->"TBits"|TTuple->"TTuple"|TArray->"TArray"|TEnumDecl->"TEnumDecl"|TRecordExceptionDecl->"TRecordExceptionDecl"|TNonDecl->"TNonDecl"|TBitField->"TBitField"letppfr=to_stringr|>Format.pp_print_stringfletall=[BuiltinSingularType;BuiltinAggregateType;BuiltinSingularOrAggregate;SingularType;AggregateType;NamedType;AnonymousType;NonPrimitiveType;PrimitiveType;Canonical;Domain;Structure;Subtype;DomainSubtypeSatisfaction;StructuralSubtypeSatisfaction;SubtypeSatisfaction;TypeSatisfaction;TypeClash;CheckUnop;CheckBinop;LowestCommonAncestor;ELit;CTC;ELocalVarConstant;ELocalVar;EGlobalVarConstantVal;EGlobalVarConstantNoVal;EGlobalVar;Binop;Unop;ECond;ESlice;ECall;EStructuredMissingField;EStructuredNotStructured;ERecord;EGetRecordField;EGetBadField;EGetBadBitField;EGetBadRecordField;EGetBitField;EGetBitFieldNested;EGetBitFieldTyped;EGetBitFields;EUnknown;EPattern;EGetArray;ESliceOrEGetArrayError;ECondSimple;EUndefIdent;EConcatEmpty;EConcat;ETuple;LEDiscard;LELocalVar;LEGlobalVar;LESlice;LESetArray;LESetBadStructuredField;LESetStructuredField;LESetBadBitField;LESetBitField;LESetBitFieldNested;LESetBitFieldTyped;LESetBadField;LESetFields;LESetFields;LEDestructuring;LEConcat;SliceLength;SliceSingle;SliceRange;SliceStar;SPass;SAssignCall;SAssignTuple;SAssign;SReturnOne;SReturnSome;SReturnNone;SSeq;SCall;SCond;SCase;SAssert;SWhile;SRepeat;SFor;SThrowNone;SThrowSomeTyped;SThrowSome;STry;SDeclSome;SDeclNone;SDebug;FUndefIdent;FPrimitive;FBadArity;FCallBadArity;FCallSetter;FCallGetter;FCallMismatch;Block;Loop;For;CatcherNone;CatcherSome;Subprogram;TString;TReal;TBool;TNamed;TInt;TBits;TTuple;TArray;TEnumDecl;TRecordExceptionDecl;TNonDecl;TBitField;]letall_nb=List.lengthallletindex=lettbl:(t,int)Hashtbl.t=Hashtbl.createall_nbinlet()=List.iteri(funir->Hashtbl.addtblri)allinHashtbl.findtblletof_string=lettbl:(string,t)Hashtbl.t=Hashtbl.createall_nbinlet()=List.iter(funr->Hashtbl.addtbl(to_stringr|>String.lowercase_ascii)r)allinfuns->Hashtbl.findtbl(String.lowercase_asciis)endtypetyping_rule=TypingRule.tmoduleTypingCmp:Set.OrderedTypewithtypet=typing_rule=structtypet=typing_ruleletcompare=compareendmoduleSemanticsSet=Set.Make(SemanticsCmp)moduleTypingSet=Set.Make(TypingCmp)moduleSemanticsMap=Map.Make(SemanticsCmp)moduleTypingsMap=Map.Make(TypingCmp)moduletypeSEMINSTR=sigvaluse:semantics_rule->unitvaluse_with:'a->semantics_rule->'aendmoduletypeTYPINSTR=sigvaluse:typing_rule->unitvaluse_with:'a->typing_rule->'aendmoduletypeSEMBUFFER=sigvalpush:semantics_rule->unitvalreset:unit->unitvalget:unit->semantics_rulelistendmoduletypeTYPBUFFER=sigvalpush:typing_rule->unitvalreset:unit->unitvalget:unit->typing_rulelistendmoduleSemMake(Buffer:SEMBUFFER):SEMINSTR=structletuse=Buffer.pushletuse_with(x:'a)r:'a=Buffer.pushr;xendmoduleTypMake(Buffer:TYPBUFFER):TYPINSTR=structletuse=Buffer.pushletuse_with(x:'a)r:'a=Buffer.pushr;xendmoduleSemanticsNoBuffer:SEMBUFFER=structletpush=Fun.const()letreset()=()letget()=[]endmoduleTypingNoBuffer:TYPBUFFER=structletpush=Fun.const()letreset()=()letget()=[]endmoduleSemanticsSingleBuffer:SEMBUFFER=structlet_buffer:semantics_rulelistref=ref[]letreset()=_buffer:=[]letget()=!_bufferletpushr=_buffer:=r::!_bufferendmoduleTypingSingleBuffer:TYPBUFFER=structlet_buffer:typing_rulelistref=ref[]letreset()=_buffer:=[]letget()=!_bufferletpushr=_buffer:=r::!_bufferendmoduleSemanticsSingleSetBuffer:SEMBUFFER=structlet_semantics_buffer:(semantics_rule,unit)Hashtbl.t=Hashtbl.createSemanticsRule.all_nbletpushr=Hashtbl.replace_semantics_bufferr()letreset()=Hashtbl.clear_semantics_bufferletget()=Hashtbl.to_seq_keys_semantics_buffer|>List.of_seqendmoduleTypingSingleSetBuffer:TYPBUFFER=structlet_typing_buffer:(typing_rule,unit)Hashtbl.t=Hashtbl.createTypingRule.all_nbletpushr=Hashtbl.replace_typing_bufferr()letreset()=Hashtbl.clear_typing_bufferletget()=Hashtbl.to_seq_keys_typing_buffer|>List.of_seqendmoduleSemanticsNoInstr=SemMake(SemanticsNoBuffer)moduleTypingNoInstr=TypMake(TypingNoBuffer)moduleSemanticsSingleInstr=SemMake(SemanticsSingleBuffer)moduleTypingSingleInstr=TypMake(TypingSingleBuffer)moduleSemanticsSingleSetInstr=SemMake(SemanticsSingleSetBuffer)moduleTypingSingleSetInstr=TypMake(TypingSingleSetBuffer)