12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2024 *)(* 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_typesletcategory=File.register_code_transformation_category"variadic"(* Variadic will create prototype and specifications for some variadic
functions. Since only prototypes are created, the resulting source code isn't
compilable. This printer will print the original functions, with the replaced
prototypes in comments beside the instruction. *)letchange_printer=letfirst=reftrueinfun()->if!firstthenbeginfirst:=false;letmodulePrinter_class(X:Printer.PrinterClass)=structclassprinter=objectinheritX.printerassupermethod!instrfmti=matchiwith(* If the instruction calls a function that have been replaced,
then build an instruction with the old function. *)|Call(res,({enode=Lval(Varvi,o)}asfct),args,loc)whenReplacements.memvi->letold_vi=Replacements.findviinletold_vi={viwithvname=old_vi.vname}inletold_instr=Call(res,{fctwithenode=Lval(Varold_vi,o)},args,loc)inFormat.fprintffmt"%a /* %s */"super#instrold_instrvi.vname(* Otherwise keep the instruction. *)|_->super#instrfmtiendendinPrinter.update_printer(modulePrinter_class:Printer.PrinterExtension)endlet()=Cmdline.run_after_extended_stagebeginfun()->State_dependency_graph.add_dependencies~from:Options.Enabled.self[Ast.self]end;Cmdline.run_after_configuring_stagebeginfun()->lettranslatefile=ifOptions.Enabled.get()thenbeginchange_printer();Translate.translate_variadicsfileendinFile.add_code_transformation_before_cleanupcategorytranslateend