1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(**************************************************************************)(* 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). *)(* *)(**************************************************************************)(** Unique identifier for [malloc] sites, which eventually includes all
allocations in a C program. We also give string as a convenient
name for these allocations. *)moduleMalloc_id:sigtypet=privateint*stringvalfresh:string->tvalhash:t->intvalto_string:t->stringvalto_int:t->intvalcompare:t->t->intvalequal:t->t->boolend=structtypet=int*stringletcount=ref0letfreshstring=incrcount;!count,stringletto_int(x,_)=xlethash=to_intletto_string(_i,s)=s(* ^ "#" ^ (string_of_int i) *)letcompareab=Int.compare(to_inta)(to_intb)letequalab=(to_inta)==(to_intb)end(** Generative functor to create unique ids. *)module[@inlinealways]MakeId():sigtypet=privateintvalfresh:unit->tend=structtypet=intletcount=ref0letfresh()=incrcount;!countend(** We want a choose operation on sets (which normally selects an
arbitrary elements in a set) but we want to tell whether two
distinct choose(S) operations selected the same element or not.
For this we parameterized the choice function by a choice
identifier: Two calls with the same identifier on the same set
return the same value. This makes the choice function
deterministic (but parameterized by an unknown value).
We also represent sets by decision trees: A union B is really
"if(cond) A else B", where cond is a fresh condition variable
(that we never use). Thus, a choice can viewed as a valuation of
different condition variables. We can thus express that
choise_c(S) is equal to one element in the set (we just don't know
which one). *)moduleCondition:sigtypet=privateintvalfresh:unit->tend=MakeId()moduleChoice:sigtypet=privateintvalfresh:unit->tend=MakeId()