123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110(**************************************************************************)(* This file is part of BINSEC. *)(* *)(* Copyright (C) 2016-2026 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)moduletypeMonad=sigtype'amvalreturn:'a->'amvalbind:'am->('a->'bm)->'bmendmoduleMonadic_Arity(M:Monad)=structtype'am='aM.mtype'rar0='rmtype('a,'r)ar1='a->'rmtype('a,'b,'r)ar2='a->'b->'rmtype('a,'b,'c,'r)ar3='a->'b->'c->'rmtype('a,'r)variadic='alist->'rmendmoduletypeExpr_Input=sigmoduleM:MonadtypebooleantypebinarymoduleBinary:sigincludeTransfer_functions.Binary_ForwardwithmoduleArity:=Monadic_Arity(M)andtypebinary=binaryandtypeboolean=booleanendmoduleBoolean:sigincludeTransfer_functions.Boolean_ForwardwithmoduleArity:=Monadic_Arity(M)andtypeboolean=booleanendvalbin_of_bool:boolean->binaryM.mvalbool_of_bin:binary->booleanM.m(* If(cond) then a else b operation. *)valite:boolean->binary->binary->binaryM.mvalget_var:size:int->string->binaryM.mvalload:size:int->Machine.endianness->binary->binaryM.mvalassume:boolean->unitM.mendmoduleState_Monad(State:sigtypetend):Monadwithtype'am=State.t->'a*State.t=structtype'am=State.t->'a*State.tletreturnxstate=(x,state)letbindafstate1=letx,state2=astate1in(fx)state2endmoduletypeInstr_Input=sigmoduleState:sigtypetendincludeExpr_InputwithmoduleM:=State_Monad(State)valunknown:size:int->binaryState_Monad(State).mvalundef:size:int->binaryState_Monad(State).m(* Note: could return a unit State_Monad(State).m instead, but this
is more convenient. *)valstore:size:int->Machine.endianness->binary->binary->State.t->State.tvalset_var:size:int->string->binary->State.t->State.t(* Add a comment "at the current position". In LLVM for instance, it
corresponds to a metadata attached to the next instruction which
is translated. *)valadd_comment:string->State.t->State.tendtype'binjump_target=StaticofDba.idDba.jump_target|Dynamicof'bintype('bool,'bin)jump_kind=|JKIfof'bool*'binjump_target*'binjump_target|JKJumpof'binjump_target|JKStop|JKAssumeof'bool*'binjump_target