12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* 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). *)(* *)(**************************************************************************)openCil_typesmoduleCallsite=Datatype.Pair(Kernel_function)(Cil_datatype.Kinstr)typecall_site=Callsite.tincludeDatatype.With_collections(Datatype.List(Callsite))(structletmodule_name="Dive.Callstack"end)letinitkf=[(kf,Kglobal)]letpopcs=matchcswith|[]|(_,Kglobal)::_::_|[(_,Kstmt_)]->assertfalse(* Invariant *)|[(_,Kglobal)]->None|(kf,Kstmtstmt)::t->Some(kf,stmt,t)lettop_kfcs=matchcswith|[]|(_,Kglobal)::_::_|[(_,Kstmt_)]->assertfalse(* Invariant *)|(kf,_)::_->kfletrecpop_downtotop_kf=function|[]->failwith"the callstack doesn't contain this function"|((kf,_kinstr)::tail)ascs->ifKernel_function.equalkftop_kfthencselsepop_downtotop_kftailletpush(kf,stmt)cs=matchcswith(* When the callstack is truncated, we ignore the first callsite *)|[]->[(kf,Kglobal)]|cs->(kf,Kstmtstmt)::csletrecis_prefixcs1cs2=matchcs1,cs2with|[],_->true|_,[]->false|[(kf,Kglobal)],(kf',_)::_->Kernel_function.equalkfkf'|_,[(_,Kglobal)]->false|s1::t1,s2::t2->ifCallsite.equals1s2thenis_prefixt1t2elsefalselettruncate_to_subfull_cssub_cs=letrecauxacc=function|[]->None|(s::t)ascs->ifis_prefixsub_cscsthenSome(List.rev_appendaccsub_cs)elseaux(s::acc)tinaux[]full_cs