123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121(* Copyright 2018-present Cornell University
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*)openAstmoduleF=Formatletconvert_dollar_to_brackets(s:string):string=Str.global_replace(Str.regexp"\\$\\([0-9]+\\)")"[\\1]"sletpp_print_optionppfmt=function|None->()|Somex->F.fprintffmt" %a"ppxletprint_intfmti=F.fprintffmt"%d"iletprint_stringfmts=F.fprintffmt"%s"sletprint_quoted_stringfmts=F.fprintffmt"\"%s\""sletprint_namefmtname=print_quoted_stringfmtnameletprint_idfmtid=print_quoted_stringfmtidletprint_numberfmtnumber=print_stringfmtnumberletprint_sessionfmtsession=print_stringfmtsessionletprint_portfmtport=print_stringfmtportletprint_exactfmtexact=ifexactthenF.fprintffmt"$"else()letprint_packetfmtpacket=print_stringfmtpacketletprint_expectfmtexpect=print_stringfmtexpectletprint_argfmtarg=letid,number=arginF.fprintffmt"%a:%a"print_ididprint_numbernumberletprint_actionfmtaction=letname,args=actioninF.fprintffmt"%a(%a)"print_namename(F.pp_print_list~pp_sep:(funfmt()->F.fprintffmt",")print_arg)argsletprint_mtchkindfmt=function|Numnumber->print_numberfmtnumber|Slash(number_l,number_r)->F.fprintffmt"%a/%a"print_numbernumber_lprint_numbernumber_rletprint_mtchfmtmtch=letname,mtchkind=mtchinF.fprintffmt"%a:%a"print_namenameprint_mtchkindmtchkindletprint_id_or_indexfmt=function|Idid->print_stringfmtid|Indexnumber->print_numberfmtnumberletprint_condfmt=function|Eq->print_stringfmt"=="|Ne->print_stringfmt"!="|Le->print_stringfmt"<="|Lt->print_stringfmt"<"|Ge->print_stringfmt">="|Gt->print_stringfmt">"letprint_ctrfmt=function|Bytes->print_stringfmt"bytes"|Packets->print_stringfmt"packets"letprint_stmtfmt=function|Wait->print_stringfmt"wait"|RemoveAll->print_stringfmt"remove_all"|Expect(port,Someexpect,exact)->F.fprintffmt"expect %a %a%a"print_portportprint_expectexpectprint_exactexact|Expect(port,None,exact)->F.fprintffmt"expect %a %a"print_portportprint_exactexact|Packet(port,packet)->F.fprintffmt"packet %a %a"print_portportprint_packetpacket|NoPacket->print_stringfmt"no_packet"|Add(name,int_opt,mtchs,action,id_opt)->F.fprintffmt"add %a%a %a %a%a"print_namename(pp_print_optionprint_int)int_opt(F.pp_print_list~pp_sep:(funfmt()->F.fprintffmt" ")print_mtch)mtchsprint_actionaction(pp_print_optionprint_id)id_opt|SetDefault(name,action)->F.fprintffmt"setdefault %a %a"print_namenameprint_actionaction|CheckCounter(id,id_or_index,(ctr,cond,number))->F.fprintffmt"check_counter %a(%a)%a %a %a"print_ididprint_id_or_indexid_or_index(pp_print_optionprint_ctr)ctrprint_condcondprint_numbernumber|MirroringAdd(session,port)->F.fprintffmt"mirroring_add %a %a"print_sessionsessionprint_portport|MirroringAddMc(session,id)->F.fprintffmt"mirroring_add_mc %a %a"print_sessionsessionprint_idid|MirroringGetsession->F.fprintffmt"mirroring_get %a"print_sessionsession|McGroupCreateid->F.fprintffmt"mc_mgrp_create %a"print_numberid|McNodeCreate(id,port)->F.fprintffmt"mc_node_create %a %a"print_numberid(F.pp_print_list~pp_sep:(funfmt()->F.fprintffmt" ")print_number)port|McNodeAssociate(id,handle)->F.fprintffmt"mc_mgrp_associate %a %a"print_numberidprint_numberhandle|RegisterRead(name,index)->F.fprintffmt"register_read %a %a"print_namenameprint_numberindex|RegisterWrite(name,index,number)->F.fprintffmt"register_write %a %a %a"print_namenameprint_numberindexprint_numbernumber|RegisterResetname->F.fprintffmt"register_reset %a"print_namenameletprint_stmtsfmtstmts=F.pp_print_list~pp_sep:(funfmt()->F.fprintffmt"@.")print_stmtfmtstmts