123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(**************************************************************************)(* *)(* This file is part of the Frama-C's MetACSL plug-in. *)(* *)(* Copyright (C) 2018-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) *)(* *)(**************************************************************************)openMeta_utilsopenMeta_optionsopenMeta_parse(* Main procedure *)letgenerateflags=(* Copy current project and work on the copy *)letprj=Project.current()in(* Retrieve MPs gathered during parsing *)letmps=Meta_parse.metaproperties()inletprj_name=ifMeta_options.Separate_annots.get()then"translation-tmp"else"translation"inletnew_prj=Project.create_by_copy~last:trueprj_nameinProject.set_currentnew_prj;(* Filter only specified ones (-meta-set) *)letto_translate=matchflags.target_setwith|None->mps|Someset->List.filter(funmp->StrSet.memmp.mp_nameset)mpsinSelf.feedback"Will process %d properties"(List.lengthto_translate);(* Dispatch MPs according to their targets and context to ease annotation *)lettables,all_mp=Meta_dispatch.dispatchflagsto_translateinMeta_bindings.add_ghost_codeflags;(* Actually annotate (in a new project) *)Meta_annotate.annotateflagsall_mptables;Meta_dispatch.finalize_dependencies();File.reorder_ast();(* At this point, AST should pass integrity check. *)if(Kernel.Check.get())thenFilecheck.check_ast"MetAcsl annotations";(* Return the annotated project *)letfinal_prj=ifMeta_options.Separate_annots.get()thenbeginFile.create_rebuilt_project_from_visitor~last:true"translation"(funprj->newVisitor.frama_c_copyprj)endelsenew_prjinProject.set_currentprj;ifMeta_options.Separate_annots.get()thenProject.remove~project:new_prj();final_prjletregister()=ifEnabled.get()then(Self.feedback"Translation is enabled";Ast.compute();letflags={check_external=Check_External.get();check_callee_assigns=Check_Callee_Assigns.get();simpl=Simpl.get();number_assertions=Number_assertions.get();prefix_meta=Prefix_meta.get();static_bindings=(letr=Static_bindings.get()inifr<=0thenNoneelseSomer);keep_proof_files=Keep_proof_files.get();list_targets=List_targets.get();default_to_assert=Default_to_assert.get();target_set=ifTargets.is_empty()thenNoneelseletset=Targets.foldStrSet.addStrSet.emptyinSomeset;}inignore@@generateflags;Self.feedback"Successful translation";Enabled.setfalse)(* External API *)lettranslate?(check_external=true)?(check_callee_assigns=Kernel_function.Set.empty)?(simpl=true)?target_set?(number_assertions=false)?(prefix_meta=true)?static_bindings()=letflags={number_assertions;default_to_assert=true;static_bindings;prefix_meta;list_targets=false;check_external;check_callee_assigns;simpl;target_set;keep_proof_files=false;}ingenerateflagslet()=Boot.Main.extendregister;Meta_parse.register_parsing()