123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: 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, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program 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. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Switch combiner *)openCore.AllopenSig.Combiner.DomainopenCommonopenMopsa_utilsmoduleMake(D1:DOMAIN_COMBINER)(D2:DOMAIN_COMBINER):DOMAIN_COMBINERwithtypet=D1.t*D2.t=struct(**************************************************************************)(** {2 Domain header} *)(**************************************************************************)typet=D1.t*D2.tletid=C_pair(Sequence,D1.id,D2.id)letname=D1.name^" ; "^D2.nameletdomains=DomainSet.unionD1.domainsD2.domainsletsemantics=SemanticSet.unionD1.semanticsD2.semanticsletrouting_table=lett=join_routing_tableD1.routing_tableD2.routing_tableinDomainSet.fold(fund1acc->add_routes(Belowd1)D2.domainsacc)D1.domainstletchecks=D1.checks@D2.checks|>List.sort_uniqcompareletbottom=D1.bottom,D2.bottomlettop=D1.top,D2.topletis_bottom(a1,a2)=D1.is_bottoma1||D2.is_bottoma2(**************************************************************************)(** {2 Lattice operators} *)(**************************************************************************)letsubsetmanctx((a1,a2),s)((a1',a2'),s')=D1.subset(fst_pair_manman)ctx(a1,s)(a1',s')&&D2.subset(snd_pair_manman)ctx(a2,s)(a2',s')letjoinmanctx((a1,a2),s)((a1',a2'),s')=letaa1=D1.join(fst_pair_manman)ctx(a1,s)(a1',s')inletaa2=D2.join(snd_pair_manman)ctx(a2,s)(a2',s')in(aa1,aa2)letmeetmanctx((a1,a2),s)((a1',a2'),s')=letaa1=D1.meet(fst_pair_manman)ctx(a1,s)(a1',s')inletaa2=D2.meet(snd_pair_manman)ctx(a2,s)(a2',s')in(aa1,aa2)letwidenmanctx((a1,a2),s)((a1',a2'),s')=letaa1=D1.widen(fst_pair_manman)ctx(a1,s)(a1',s')inletaa2=D2.widen(snd_pair_manman)ctx(a2,s)(a2',s')in(aa1,aa2)letmergepath(pre1,pre2)((a1,a2),te)((a1',a2'),te')=D1.merge(Ax_pair_left::path)pre1(a1,te)(a1',te'),D2.merge(Ax_pair_right::path)pre2(a2,te)(a2',te')(**************************************************************************)(** {2 Transfer functions} *)(**************************************************************************)(** Initialization procedure *)letinitprogmanflow=broadcast_initD1.initD2.initprogmanflow(** Execution of statements *)letexectargets=cascade_calltargetsD1.execD1.domainsD2.execD2.domains(** Evaluation of expressions *)letevaltargets=cascade_calltargetsD1.evalD1.domainsD2.evalD2.domains(** Query handler *)letasktargets=broadcast_calltargetsD1.askD1.domainsD2.askD2.domains(** Pretty printer of states *)letprint_statetargets=matchsat_targets~targets~domains:D1.domains,sat_targets~targets~domains:D2.domainswith|false,false->raiseNot_found|true,false->letf=D1.print_statetargetsin(funprinter(a1,_)->fprintera1)|false,true->letf=D2.print_statetargetsin(funprinter(_,a2)->fprintera2)|true,true->letf1=D1.print_statetargetsinletf2=D2.print_statetargetsin(funprinter(a1,a2)->f1printera1;f2printera2)(** Pretty printer of expressions *)letprint_exprtargets=matchsat_targets~targets~domains:D1.domains,sat_targets~targets~domains:D2.domainswith|false,false->raiseNot_found|true,false->letf=D1.print_exprtargetsin(funmanflowprintere->f(fst_pair_manman)flowprintere)|false,true->letf=D2.print_exprtargetsin(funmanflowprintere->f(snd_pair_manman)flowprintere)|true,true->letf1=D1.print_exprtargetsinletf2=D2.print_exprtargetsin(funmanflowprintere->f1(fst_pair_manman)flowprintere;f2(snd_pair_manman)flowprintere)endletrecmake(domains:(moduleDOMAIN_COMBINER)list):(moduleDOMAIN_COMBINER)=matchdomainswith|[]->assertfalse|[d]->d|l->leta,b=ListExt.splitlinletaa,bb=makea,makebin(moduleMake(valaa:DOMAIN_COMBINER)(valbb:DOMAIN_COMBINER))