123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228(**************************************************************************)(* This file is part of the Codex semantics library. *)(* *)(* Copyright (C) 2013-2025 *)(* 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 LICENSE). *)(* *)(**************************************************************************)moduleIn_bits=Units.In_bitsmoduleMake_Conversion(Log:Tracelog.S)(Sub:Sig.BASE)=structletar0ppretppf=functx->Log.trace(funp->p"%t"pp)~pp_ret:(ppretctx)@@fun()->fctxletar1ppappretppfctxa=Log.trace(funp->p"%t %a"pp(ppactx)a)~pp_ret:(ppretctx)@@fun()->fctxaletar2ppappbppretppfctxab=Log.trace(funp->p"%t %a %a"pp(ppactx)a(ppbctx)b)~pp_ret:(ppretctx)@@fun()->fctxabletar3ppappbppcppretppfctxabc=Log.trace(funp->p"%t %a %a %a"pp(ppactx)a(ppbctx)b(ppcctx)c)~pp_ret:(ppretctx)@@fun()->fctxabcmoduleArity=Sig.Context_Arity_Forward(Sub.Context)typeboolean=Sub.booleantypeinteger=unittypeenum=Sub.enumtypebitvector=Sub.binarytype'app=Sub.Context.t->Format.formatter->'a->unitletbool_printer=Sub.boolean_prettyletenum_printer=Sub.enum_prettyletinteger_printer_=assertfalseletbv_printer=Sub.binary_prettyletprod_printerppappbctxfmt(a,b)=Format.fprintffmt"(%a,%a)"(ppactx)a(ppbctx)bendmoduleLog_Domain(Log:Tracelog.S)(Sub:Sig.BASE):Sig.BASEwithtypeContext.t=Sub.Context.tandtypebinary=Sub.binaryandtypeboolean=Sub.booleanandmoduleContext=Sub.Context=structletname=Sub.nameletunique_id=Sub.unique_idtypebinary=Sub.binarytypeenum=Sub.enumtypeboolean=Sub.booleanmoduleBoolean=Sub.BooleanmoduleBinary=Sub.BinarymoduleEnum=Sub.EnummoduleContext=Sub.Contextletcontext_pretty=Sub.context_prettyletroot_context()=Log.trace(funp->p"root_context")~pp_ret:context_pretty@@fun()->Sub.root_context()letmu_context_openctx=Log.trace(funp->p"mu_context_open %a"context_prettyctx)~pp_ret:context_pretty@@fun()->Sub.mu_context_openctxlettyped_nondet2ctxactxbin_tup=Log.trace(funp->p"typed_nondet2"(* "%a %a" *)(* context_pretty ctxa context_pretty ctxb *))(* ~pp_ret:(fun fmt (ctx,out_tup) -> context_pretty fmt ctx) *)@@fun()->Sub.typed_nondet2ctxactxbin_tupletnondet_same_contextctxin_tup=Log.trace(funp->p"nondet_same_context"(* context_pretty ctx *))@@fun()->Sub.nondet_same_contextctxin_tuplettyped_fixpoint_step~iteration~init~arg~body=Log.trace(funp->p"typed_fixpoint_step")@@fun()->Sub.typed_fixpoint_step~iteration~init~arg~bodyletwidened_fixpoint_step~widening_id~previous~next=Log.trace(funp->p"widened_fixpoint_step")@@fun()->Sub.widened_fixpoint_step~widening_id~previous~nextletserialize_booleanctxaactxbbin_tup=Log.trace(funp->p"serialize_boolean %a %a"(Sub.boolean_prettyctxa)a(Sub.boolean_prettyctxb)b)@@fun()->Sub.serialize_booleanctxaactxbbin_tupletserialize_enumctxaactxbbin_tup=Log.trace(funp->p"serialize_enum %a %a"(Sub.enum_prettyctxa)a(Sub.enum_prettyctxb)b)@@fun()->Sub.serialize_enumctxaactxbbin_tupletserialize_binary~widens~sizectxaactxbbin_tup=Log.trace(funp->p"serialize_binary ~widens:%b ~size:%d %a %a"widens(In_bits.to_intsize)(Sub.binary_pretty~sizectxa)a(Sub.binary_pretty~sizectxb)b)@@fun()->Sub.serialize_binary~widens~sizectxaactxbbin_tup(**************** Pretty printing ****************)letbinary_pretty=Sub.binary_prettyletboolean_pretty=Sub.boolean_prettyletenum_pretty=Sub.enum_pretty(**************** Tuple fonctions ****************)letassumectxbool=Log.trace(funp->p"assume %a"(boolean_prettyctx)bool)@@fun()->Sub.assumectxbool(**************** Queries ****************)moduleQuery=structmoduleBinary_Lattice=Sub.Query.Binary_LatticemoduleEnum_Lattice=Sub.Query.Enum_Latticeletbinary=Sub.Query.binaryletenum=Sub.Query.enumendletbinary_empty~sizectx=Log.trace(funp->p"binary_empty ~size:%d"@@In_bits.to_intsize)~pp_ret:(Sub.binary_pretty~sizectx)@@fun()->Sub.binary_empty~sizectxletboolean_emptyctx=Log.trace(funp->p"boolean_empty")~pp_ret:(Sub.boolean_prettyctx)@@fun()->Sub.boolean_emptyctxletenum_emptyctx=Log.trace(funp->p"enum_empty")~pp_ret:(Sub.enum_prettyctx)@@fun()->Sub.enum_emptyctxletbinary_unknown~sizectx=Log.trace(funp->p"binary_unknown ~size:%d"@@In_bits.to_intsize)~pp_ret:(Sub.binary_pretty~sizectx)@@fun()->Sub.binary_unknown~sizectxletbinary_unknown_typed~sizectxtyp=Log.trace(funp->p"binary_unknown_typed ~size:%d typ:%a"(In_bits.to_intsize)Types.TypedC.pptyp)~pp_ret:(Sub.binary_pretty~sizectx)@@fun()->Sub.binary_unknown_typed~sizectxtypletboolean_unknownctx=Log.trace(funp->p"boolean_unknown")~pp_ret:(Sub.boolean_prettyctx)@@fun()->Sub.boolean_unknownctxletenum_unknown~enumsizectx=Log.trace(funp->p"enum_unknown ~enumsize:%d"enumsize)~pp_ret:(Sub.enum_prettyctx)@@fun()->Sub.enum_unknown~enumsizectxletsatisfiablectxbool=Log.trace(funp->p"satisfiable %a"(boolean_prettyctx)bool)@@fun()->Sub.satisfiablectxboolletunioncondctxtup=Log.trace(funp->p"union")@@fun()->Sub.unioncondctxtupletquery_boolean=Sub.query_booleanmoduleConversion=Make_Conversion(Log)(Sub)moduleBoolean_Forward=structincludeOperator.Autolog.Log_Boolean_Backward(Conversion)(Sub.Boolean_Forward)lettrue_=Sub.Boolean_Forward.true_letfalse_=Sub.Boolean_Forward.false_endmoduleBinary_Forward=Operator.Autolog.Log_Binary_Forward(Conversion)(Sub.Binary_Forward)moduleEnum_Forward=Operator.Autolog.Log_Enum_Forward(Conversion)(Sub.Enum_Forward)end(* MAYBE: Should disappear? *)moduleLog_With_Focusing(Log:Tracelog.S)(Sub:Memory_domains.With_focusing.S_with_types):Memory_domains.With_focusing.S_with_typeswithtypeContext.t=Sub.Context.tandtypebinary=Sub.binaryandtypeboolean=Sub.boolean=struct(* TODO: Also log blocks and offsets? *)includeSubincludeLog_Domain(Log)(Sub)moduleConversion=structincludeMake_Conversion(Log)(Sub)typememory=Sub.memorytypebinary=Sub.binarytypeaddress=Sub.binarytypevalue=Sub.binarytypeblock=Sub.blockletblock_printer=Sub.block_prettyletaddress_printer=(Sub.binary_pretty~size:(Codex_config.ptr_size()))letmemory_printer=Sub.memory_prettyletvalue_printer=Sub.binary_prettyendmoduleMemory_Forward=Operator.Autolog.Log_Memory_Forward(Conversion)(Sub.Memory_Forward)(* TODO: Something to fix here. *)moduleQuery=structincludeQueryletreachable=Sub.Query.reachableendend