Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file dolmenexpr_to_expr.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383(* SPDX-License-Identifier: MIT *)(* Copyright (C) 2023-2024 formalsec *)(* Written by Hichem Rami Ait El Hara *)moduleDExpr=Dolmen_std.ExprmoduleDTy=DExpr.TymoduleDTerm=DExpr.TermmoduleDBuiltin=Dolmen_std.BuiltinmoduleBuiltin=struct(* additional builtins *)letstring_ty_cst:DExpr.Term.ty_const=DExpr.Id.mk~builtin:DBuiltin.Base(Dolmen_std.Path.global"StringTy")DExpr.{arity=0;alias=No_alias}letstring_ty=DTy.applystring_ty_cst[]letfloat32_ty=DTy.float824letfloat64_ty=DTy.float1153letint_to_string:DExpr.term_cst=DExpr.Id.mk~name:"IntToString"~builtin:DBuiltin.Base(Dolmen_std.Path.global"IntToString")(DTy.arrow[DTy.int]string_ty)letstring_to_int:DExpr.term_cst=DExpr.Id.mk~name:"StringToInt"~builtin:DBuiltin.Base(Dolmen_std.Path.global"StringToInt")(DTy.arrow[string_ty]DTy.int)letreal_to_string:DExpr.term_cst=DExpr.Id.mk~name:"RealToString"~builtin:DBuiltin.Base(Dolmen_std.Path.global"RealToString")(DTy.arrow[DTy.real]string_ty)letstring_to_real:DExpr.term_cst=DExpr.Id.mk~name:"StringToReal"~builtin:DBuiltin.Base(Dolmen_std.Path.global"StringToReal")(DTy.arrow[string_ty]DTy.real)letreal_to_uint32:DExpr.term_cst=DExpr.Id.mk~name:"RealToUInt32"~builtin:DBuiltin.Base(Dolmen_std.Path.global"RealToUInt32")(DTy.arrow[DTy.real]DTy.real)lettrim_string:DExpr.term_cst=DExpr.Id.mk~name:"TrimString"~builtin:DBuiltin.Base(Dolmen_std.Path.global"TrimString")(DTy.arrow[string_ty]string_ty)letf32_to_string:DExpr.term_cst=DExpr.Id.mk~name:"F32ToString"~builtin:DBuiltin.Base(Dolmen_std.Path.global"F32ToString")(DTy.arrow[float32_ty]string_ty)letstring_to_f32:DExpr.term_cst=DExpr.Id.mk~name:"StringToF32"~builtin:DBuiltin.Base(Dolmen_std.Path.global"StringToF32")(DTy.arrow[string_ty]float32_ty)letf64_to_string:DExpr.term_cst=DExpr.Id.mk~name:"F64ToString"~builtin:DBuiltin.Base(Dolmen_std.Path.global"F64ToString")(DTy.arrow[float64_ty]string_ty)letstring_to_f64:DExpr.term_cst=DExpr.Id.mk~name:"StringToF64"~builtin:DBuiltin.Base(Dolmen_std.Path.global"StringToF64")(DTy.arrow[string_ty]float64_ty)endmoduleDolmenIntf=structincludeDTermtypety=DTy.ttypeterm=DTerm.ttypefunc_decl=DTerm.Const.tlettrue_=DTerm._trueletfalse_=DTerm._falseletinti=DTerm.Int.mk(string_of_inti)letrealr=DTerm.Real.mk(string_of_floatr)letconststy=DTerm.of_cst(DTerm.Const.mk(Dolmen_std.Path.globals)ty)letnot_=DTerm.negletand_ab=DTerm._and[a;b]letor_ab=DTerm._or[a;b]letimplies=DTerm.implyletlogand=DTerm._andletlogor=DTerm._orletget_vars_from_termstl=List.map(fun(t:DTerm.t)->matcht.term_descrwith|Varv->v|_->Fmt.failwith{|Can't quantify non-variable term "%a"|}DTerm.printt)tlletforalltlt=lettvl=get_vars_from_termstlinDTerm.all([],tvl)tletexists(tl:termlist)t=lettvl=get_vars_from_termstlinDTerm.ex([],tvl)tletnary_to_binaryftl=letrecauxacc=function|[]->acc|h::t->aux(DTerm.apply_cstf[][acc;h])tinmatchtlwith|h1::h2::t->aux(DTerm.apply_cstf[][h1;h2])t|_->Fmt.failwith{|%a applied to less than two terms|}DTerm.Const.printfletint_of_term(t:DTerm.t)=matcht.term_descrwith|Cst{builtin=DBuiltin.Bitveci;_}->(* There may be a proper alternative to int_of_string somewhere,
since its hidden by prelude. *)Z.to_int(Z.of_stringi)|_->Fmt.failwith{|int_of_term: expected a term that is an integer constant, instead got: %a|}DTerm.printtmoduleTypes=structincludeDTyletregexp=DTy.string_reg_langletty=DTerm.tyletto_ety(ty:DTy.t):Ty.t=matchtywith|{ty_descr=TyApp({builtin=DBuiltin.Int;_},_);_}->Ty_int|{ty_descr=TyApp({builtin=DBuiltin.Real;_},_);_}->Ty_real|{ty_descr=TyApp({builtin=DBuiltin.Prop;_},_);_}->Ty_bool|{ty_descr=TyApp({builtin=DBuiltin.Base;path=Absolute{name="StringTy";_};_},_);_}->Ty_str|{ty_descr=TyApp({builtin=DBuiltin.Bitvn;_},_);_}->Ty_bitvn|{ty_descr=TyApp({builtin=DBuiltin.Float(8,24);_},_);_}->Ty_fp32|{ty_descr=TyApp({builtin=DBuiltin.Float(11,53);_},_);_}->Ty_fp64|_->Fmt.failwith{|Unsupported dolmen type "%a"|}DTy.printtyendmoduleInt=structincludeDTerm.Intletneg=DTerm.Int.minusendmoduleReal=structincludeDTerm.Realletneg=DTerm.Real.minusendmoduleString=structincludeDTerm.Stringletv=DTerm.String.of_ustringletto_re=DTerm.String.RegLan.of_stringletatt~pos=DTerm.String.attposletconcat=nary_to_binaryDTerm.Const.String.concatletcontainst~sub=DTerm.String.containstsubletis_prefixt~prefix=DTerm.String.is_prefixtprefixletis_suffixt~suffix=DTerm.String.is_suffixtsuffixletle=DTerm.String.leqletsubt~pos~len=DTerm.String.subtposlenletindex_oft~sub~pos=DTerm.String.index_oftsubposletreplacet~pattern~with_=DTerm.String.replacetpatternwith_letreplace_allt~pattern~with_=DTerm.String.replace_alltpatternwith_endmoduleRe=structletall()=DTerm.String.RegLan.allletallchar()=DTerm.String.RegLan.allcharletnone()=DTerm.String.RegLan.emptyletstar=DTerm.String.RegLan.starletplus=DTerm.String.RegLan.crossletopt=DTerm.String.RegLan.optionletcomp=DTerm.String.RegLan.complementletrange=DTerm.String.RegLan.rangeletinter=DTerm.String.RegLan.interletloopti1i2=DTerm.String.RegLan.loopi1i2tletunion=nary_to_binaryDTerm.Const.String.Reg_Lang.unionletconcat=nary_to_binaryDTerm.Const.String.Reg_Lang.concatendmoduleBitv=structincludeDTerm.Bitvletint_to_bitvectornbits=lettwo_pow_n=1lslbitsinletunsigned_bv=ifn<0thentwo_pow_n+nelseninletrecto_bitlistaccnbits=ifbits=0thenaccelseto_bitlist(Prelude.String.cat(string_of_int(nland1))acc)(nlsr1)(bits-1)in(* let bitlist = to_bitlist [] unsigned_bv bits in
Fmt.str "%a" (Fmt.list Fmt.int) bitlist *)to_bitlist""unsigned_bvbitsletv(i:string)(n:int)=letbv=int_to_bitvector(Z.to_int(Z.of_stringi))ninDTerm.Bitv.mkbvletlognot=DTerm.Bitv.notletdiv=DTerm.Bitv.sdivletdiv_u=DTerm.Bitv.udivletlogor=DTerm.Bitv.or_letlogand=DTerm.Bitv.and_letlogxor=DTerm.Bitv.xorletshl=DTerm.Bitv.shlletashr=DTerm.Bitv.ashrletlshr=DTerm.Bitv.lshrletrem=DTerm.Bitv.sremletrem_u=DTerm.Bitv.uremletrotate_leftt1t2=DTerm.Bitv.rotate_left(int_of_termt2)t1letrotate_rightt1t2=DTerm.Bitv.rotate_right(int_of_termt2)t1letltt1t2=DTerm.Bitv.sltt1t2letlt_ut1t2=DTerm.Bitv.ultt1t2letle=DTerm.Bitv.sleletle_u=DTerm.Bitv.uleletgtt1t2=DTerm.Bitv.sgtt1t2letgt_ut1t2=DTerm.Bitv.ugtt1t2letge=DTerm.Bitv.sgeletge_u=DTerm.Bitv.ugeletextractt~high~low=DTerm.Bitv.extracthighlowtendmoduleFloat=structincludeDTerm.FloatmoduleRounding_mode=structletrne=DTerm.Float.roundNearestTiesToEvenletrna=DTerm.Float.roundNearestTiesToAwayletrtp=DTerm.Float.roundTowardPositiveletrtn=DTerm.Float.roundTowardNegativeletrtz=DTerm.Float.roundTowardZeroendletvfes=DTerm.Float.real_to_fpesDTerm.Float.roundTowardZero(DTerm.Real.mk(Prelude.Float.to_stringf))letsqrt~rmt=DTerm.Float.sqrtrmtletis_normal=DTerm.Float.isNormalletis_subnormal=DTerm.Float.isSubnormalletis_negative=DTerm.Float.isNegativeletis_positive=DTerm.Float.isPositiveletis_infinite=DTerm.Float.isInfiniteletis_nan=DTerm.Float.isNaNletis_zero=DTerm.Float.isZeroletround_to_integral~rmt=DTerm.Float.roundToIntegralrmtletadd~rmt1t2=DTerm.Float.addrmt1t2letsub~rmt1t2=DTerm.Float.subrmt1t2letmul~rmt1t2=DTerm.Float.mulrmt1t2letdiv~rmt1t2=DTerm.Float.divrmt1t2letfma~rmabc=DTerm.Float.fmarmabcletle=DTerm.Float.leqletge=DTerm.Float.geqletto_fpes~rmfp=DTerm.Float.to_fpesrmfpletsbv_to_fpes~rmbv=DTerm.Float.sbv_to_fpesrmbvletubv_to_fpes~rmbv=DTerm.Float.ubv_to_fpesrmbvletto_ubvn~rmfp=DTerm.Float.to_ubvnrmfpletto_sbvn~rmfp=DTerm.Float.to_sbvnrmfpletof_ieee_bvebsbbv=DTerm.Float.ieee_format_to_fpebsbbvletto_ieee_bv=NoneendmoduleFunc=structletmakenametylty=DTerm.Const.mk(Dolmen_std.Path.globalname)(DTy.arrowtylty)letapplyftl=DTerm.apply_cstf[]tlendmoduleSmtlib=structletpp?name:_?logic:_?status:_=Fmt.listDTerm.printendend