|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: SMT2 solver |
| 4 | +
|
| 5 | +Author: Romain Brenguier, [email protected] |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// SMT2 commands |
| 11 | + |
| 12 | +#ifndef CPROVER_SOLVERS_SMT2_SMT2_COMMAND_H |
| 13 | +#define CPROVER_SOLVERS_SMT2_SMT2_COMMAND_H |
| 14 | + |
| 15 | +#include "smt2_ast.h" |
| 16 | + |
| 17 | +class smt2_command_or_commentt |
| 18 | +{ |
| 19 | +public: |
| 20 | + virtual void print(std::ostream &stream) const = 0; |
| 21 | + virtual ~smt2_command_or_commentt() = default; |
| 22 | +}; |
| 23 | + |
| 24 | +inline std::ostream & |
| 25 | +operator<<(std::ostream &stream, const smt2_command_or_commentt &command) |
| 26 | +{ |
| 27 | + command.print(stream); |
| 28 | + return stream; |
| 29 | +} |
| 30 | + |
| 31 | +/// See the SMT-LIB standard for explanations about the meaning of the commands: |
| 32 | +/// http://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.0-r10.12.21.pdf |
| 33 | +class smt2_commandt final : public smt2_command_or_commentt |
| 34 | +{ |
| 35 | +public: |
| 36 | + void print(std::ostream &stream) const override; |
| 37 | + |
| 38 | + static smt2_commandt set_logic(smt2_symbolt symbol) |
| 39 | + { |
| 40 | + return smt2_commandt{"set-logic", {std::move(symbol)}}; |
| 41 | + } |
| 42 | + |
| 43 | + static smt2_commandt declare_fun( |
| 44 | + smt2_symbolt symbol, |
| 45 | + smt2_listt<smt2_sortt> arguments, |
| 46 | + smt2_sortt result) |
| 47 | + { |
| 48 | + return smt2_commandt{ |
| 49 | + "declare-fun", |
| 50 | + {std::move(symbol), std::move(arguments), std::move(result)}}; |
| 51 | + } |
| 52 | + |
| 53 | + static smt2_commandt define_fun( |
| 54 | + smt2_symbolt symbol, |
| 55 | + smt2_listt<smt2_pairt<smt2_symbolt, smt2_sortt>> arguments, |
| 56 | + smt2_sortt result_sort, |
| 57 | + smt2_astt result_expr) |
| 58 | + { |
| 59 | + return smt2_commandt{"define-fun", |
| 60 | + {std::move(symbol), |
| 61 | + std::move(arguments), |
| 62 | + std::move(result_sort), |
| 63 | + std::move(result_expr)}}; |
| 64 | + } |
| 65 | + |
| 66 | + static smt2_commandt declare_sort(smt2_symbolt symbol, smt2_constantt numeral) |
| 67 | + { |
| 68 | + return smt2_commandt{"declare-sort", |
| 69 | + {std::move(symbol), std::move(numeral)}}; |
| 70 | + } |
| 71 | + |
| 72 | + static smt2_commandt define_sort( |
| 73 | + smt2_symbolt symbol, |
| 74 | + smt2_listt<smt2_symbolt> arguments, |
| 75 | + smt2_astt expr) |
| 76 | + { |
| 77 | + return smt2_commandt{ |
| 78 | + "define-sort", |
| 79 | + {std::move(symbol), std::move(arguments), std::move(expr)}}; |
| 80 | + } |
| 81 | + |
| 82 | + static smt2_commandt _assert(smt2_astt expr) |
| 83 | + { |
| 84 | + return smt2_commandt{"assert", {std::move(expr)}}; |
| 85 | + } |
| 86 | + |
| 87 | + static smt2_commandt get_assertions() |
| 88 | + { |
| 89 | + return smt2_commandt{"get-assertions", {}}; |
| 90 | + } |
| 91 | + |
| 92 | + static smt2_commandt check_sat() |
| 93 | + { |
| 94 | + return smt2_commandt{"check-sat", {}}; |
| 95 | + } |
| 96 | + |
| 97 | + static smt2_commandt get_proof() |
| 98 | + { |
| 99 | + return smt2_commandt{"get-proof", {}}; |
| 100 | + } |
| 101 | + |
| 102 | + static smt2_commandt get_unsat_core() |
| 103 | + { |
| 104 | + return smt2_commandt{"get-unsat-core", {}}; |
| 105 | + } |
| 106 | + |
| 107 | + static smt2_commandt get_value(smt2_listt<smt2_astt> terms) |
| 108 | + { |
| 109 | + return smt2_commandt{"get-value", {std::move(terms)}}; |
| 110 | + } |
| 111 | + |
| 112 | + static smt2_commandt get_assignment() |
| 113 | + { |
| 114 | + return smt2_commandt{"get-assignment", {}}; |
| 115 | + } |
| 116 | + |
| 117 | + static smt2_commandt push(smt2_constantt numeral) |
| 118 | + { |
| 119 | + return smt2_commandt{"push", {std::move(numeral)}}; |
| 120 | + } |
| 121 | + |
| 122 | + static smt2_commandt pop(smt2_constantt numeral) |
| 123 | + { |
| 124 | + return smt2_commandt{"pop", {std::move(numeral)}}; |
| 125 | + } |
| 126 | + |
| 127 | + static smt2_commandt get_option(smt2_symbolt keyword) |
| 128 | + { |
| 129 | + return smt2_commandt{"get-option", {std::move(keyword)}}; |
| 130 | + } |
| 131 | + |
| 132 | + static smt2_commandt set_option(smt2_symbolt keyword, smt2_astt value) |
| 133 | + { |
| 134 | + return smt2_commandt{"set-option", {std::move(keyword), std::move(value)}}; |
| 135 | + } |
| 136 | + |
| 137 | + static smt2_commandt get_info(smt2_symbolt keyword) |
| 138 | + { |
| 139 | + return smt2_commandt{"get-info", {std::move(keyword)}}; |
| 140 | + } |
| 141 | + |
| 142 | + static smt2_commandt set_info(smt2_symbolt keyword, smt2_astt value) |
| 143 | + { |
| 144 | + return smt2_commandt{"set-info", {std::move(keyword), std::move(value)}}; |
| 145 | + } |
| 146 | + |
| 147 | + static smt2_commandt exit() |
| 148 | + { |
| 149 | + return smt2_commandt{"exit", {}}; |
| 150 | + } |
| 151 | + |
| 152 | + static smt2_commandt declare_datatypes( |
| 153 | + smt2_listt<smt2_sort_declarationt> sort_decs, |
| 154 | + smt2_listt<smt2_datatype_declarationt> datatype_decs) |
| 155 | + { |
| 156 | + return smt2_commandt{"declare-datatypes", |
| 157 | + {std::move(sort_decs), std::move(datatype_decs)}}; |
| 158 | + } |
| 159 | + |
| 160 | + static smt2_commandt |
| 161 | + declare_datatypes(smt2_listt<smt2_datatype_declarationt> datatype_decs) |
| 162 | + { |
| 163 | + return declare_datatypes( |
| 164 | + smt2_listt<smt2_sort_declarationt>{{}}, std::move(datatype_decs)); |
| 165 | + } |
| 166 | + |
| 167 | +private: |
| 168 | + irep_idt name; |
| 169 | + std::vector<smt2_astt> arguments; |
| 170 | + |
| 171 | + smt2_commandt(irep_idt name, std::vector<smt2_astt> arguments) |
| 172 | + : name(std::move(name)), arguments(std::move(arguments)) |
| 173 | + { |
| 174 | + } |
| 175 | +}; |
| 176 | + |
| 177 | +void smt2_commandt::print(std::ostream &stream) const |
| 178 | +{ |
| 179 | + stream << '(' << name; |
| 180 | + for(const auto &arg : arguments) |
| 181 | + stream << ' ' << arg; |
| 182 | + stream << ")\n"; |
| 183 | +} |
| 184 | + |
| 185 | +class smt2_commentt final : public smt2_command_or_commentt |
| 186 | +{ |
| 187 | +public: |
| 188 | + void print(std::ostream &stream) const override |
| 189 | + { |
| 190 | + stream << "; " << content << '\n'; |
| 191 | + } |
| 192 | + |
| 193 | + explicit smt2_commentt(std::string content) : content(std::move(content)) |
| 194 | + { |
| 195 | + } |
| 196 | + |
| 197 | +private: |
| 198 | + std::string content; |
| 199 | +}; |
| 200 | + |
| 201 | +#endif // CPROVER_SOLVERS_SMT2_SMT2_COMMAND_H |
0 commit comments