123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(**************************************************************************)(* 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). *)(* *)(**************************************************************************)letoutc_trace=refNoneletmarshal_flags=[]letcounter=ref(-1)letrejected=ref0typetrace_line=|Node:{loc:'aSyntax_tree.Location_identifier.toption;category:string;content:string}->trace_line|Single:{severity:int;category:string;content:string}->trace_line|ResultofstringoptionmoduletypeS=sigvalinit:unit->unitvalclose:unit->unitvaladd_trace_to_file:string->trace_line->unitvalread_all_items:?file:string->unit->trace_linelistendmoduleTo_file:S=structletfilename="bin_trace.codex"letinit()=outc_trace:=Some(open_out_binfilename)letclose()=print_endline("rejected "^string_of_int!rejected^"/"^string_of_int!counter);match!outc_tracewith|None->assertfalse|Someoutc->close_outoutcletwrite_trace_elt(elt:trace_line)=match!outc_tracewith|None->()(* using frama_c_codex doesn't init the out_channel *)|Someoutc->Marshal.to_channeloutceltmarshal_flags;flushoutcletread_itemic=(Marshal.from_channelic:trace_line)letadd_trace_to_filecategorytrace_line=incrcounter;if(category<>"Terms.Builder")thenbeginwrite_trace_elttrace_lineendelseincrrejectedletread_all_items?(file=filename)()=letic=open_in_binfileinletitems=ref[]intrywhiletruedoitems:=read_itemic::!itemsdone;[](* never reached *)with|End_of_file->close_inic;List.rev!items|e->close_inic;raiseeend(* Test: in-memory logging is already much faster than marshalling. *)moduleIn_Memory:S=structletinit()=()letclose()=()letin_memory:trace_linelistref=ref[]letadd_trace_to_filecategory(trace_line:trace_line)=in_memory:=trace_line::!in_memoryletread_all_items?file()=List.rev!in_memoryendincludeIn_Memory