123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163(**************************************************************************)(* This file is part of BINSEC. *)(* *)(* Copyright (C) 2016-2026 *)(* 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). *)(* *)(**************************************************************************)includeCli.Options_from_logger(Smtlib.Logger)(structletshortname="smt"letname="Satisfiability Modulo Theories"end)typesolver=|Auto(* try to use the best SMT solver available; in order *)|Bitwuzla_builtin(* bitwuzla native ocaml binding (cxx) *)|Bitwuzla_legacy(* bitwuzla native ocaml binding (c) *)|Bitwuzla_smtlib(* bitwuzla external process *)|Boolector_smtlib(* boolector external process *)|Z3_builtin(* z3 native ocaml binding *)|Z3_smtlib(* z3 external process *)|CVC4_smtlib(* cvc4 external process *)|Yices_smtlib(* yices external process *)lettext_backend:Smtlib.Solver.t->Smtlib.Solver.backend=funsolver->ifSmtlib.Solver.pingsolverthen(Logger.debug"Found %a in the path."Smtlib.Solver.ppsolver;Text{session=(moduleSmtlib.Solver.Session.Spawn);arg=solver})elseLogger.fatal"%a is required but not available in path."Smtlib.Solver.ppsolverletbackend:solver->Smtlib.Solver.backend=function|Auto->Smtlib.Solver.default_backend()|Bitwuzla_builtinwhenOption.is_someSmtlib.Bindings.bitwuzla_cxx->Logger.debug"Use native Bitwuzla binding (cxx).";Binding{factory=Option.getSmtlib.Bindings.bitwuzla_cxx;complete_fold_ax_values=true;}|(Bitwuzla_builtin|Bitwuzla_legacy)whenOption.is_someSmtlib.Bindings.bitwuzla_c->Logger.debug"Use native Bitwuzla binding (c).";Binding{factory=Option.getSmtlib.Bindings.bitwuzla_c;complete_fold_ax_values=true;}|Z3_builtinwhenOption.is_someSmtlib.Bindings.z3->Logger.debug"Use native z3 binding.";Binding{factory=Option.getSmtlib.Bindings.z3;complete_fold_ax_values=false;}|Bitwuzla_builtin|Bitwuzla_legacy->Logger.fatal"Native bitwuzla binding is required but not available."|Z3_builtin->Logger.fatal"Native z3 binding is required but not available."|Bitwuzla_smtlib->text_backendBitwuzla|Boolector_smtlib->text_backendBoolector|Z3_smtlib->text_backendZ3|CVC4_smtlib->text_backendCVC4|Yices_smtlib->text_backendYicesmoduleSolver=Builder.Variant_choice_assoc(structtypet=solverletassoc_map=[("auto",Auto);("bitwuzla",Bitwuzla_smtlib);("bitwuzla:native",Bitwuzla_legacy);("bitwuzla:legacy",Bitwuzla_legacy);("bitwuzla:builtin",Bitwuzla_builtin);("bitwuzla:smtlib",Bitwuzla_smtlib);("boolector",Boolector_smtlib);("boolector:smtlib",Boolector_smtlib);("z3",Z3_smtlib);("z3:builtin",Z3_builtin);("z3:smtlib",Z3_smtlib);("cvc4",CVC4_smtlib);("cvc4:smtlib",CVC4_smtlib);("yices",Yices_smtlib);("yices:smtlib",Yices_smtlib);]letdefault=Autoletname="solver"letdoc="Manually set the SMT solver to use."end)moduleTimeout=Builder.Float_option(structletname="timeout"letdoc="set the per query timeout"end)moduleMultichecks=Builder.False(structletname="multi-checks"letdoc="enable forward incremental solving"end)moduleDumpDir=Builder.String_option(structletname="dir"letdoc="set directory to cache smt scripts"end)moduleTheory=Builder.String(structletname="theory"letdoc="Select the formula theory"letdefault="QF_ABV"end)moduleUtils=structletsse_dirname="binsec_sse"letmk_file~dir=letn=ref0infun()->incrn;lettemp_dir=dir()inifnot(Sys.file_existstemp_dir)then(Logger.debug~level:6"Creating directory %s"temp_dir;Unix.mkdirtemp_dir0o700);letfilename=Filename.concattemp_dir@@Printf.sprintf"sse_%d.smt2"!ninLogger.debug~level:5"Creating temporary %s"filename;filenamelettemp_file=letdir()=lettmpdir=DumpDir.get()inFilename.concattmpdirsse_dirnameinmk_file~direndletfresh_file()=ifDumpDir.is_set()then(letfilename=Utils.temp_file()inLogger.debug~level:3"@[<h>Using SMT script file %s@]"filename;Somefilename)elseNone