mirror of
https://github.com/Z3Prover/z3
synced 2025-05-04 22:35:45 +00:00
saved params work
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
c3055207ed
commit
cf28cbab0a
130 changed files with 1469 additions and 948 deletions
|
@ -28,6 +28,7 @@ Notes:
|
|||
#include"simplify_cmd.h"
|
||||
#include"eval_cmd.h"
|
||||
#include"front_end_params.h"
|
||||
#include"gparams.h"
|
||||
|
||||
class help_cmd : public cmd {
|
||||
svector<symbol> m_cmds;
|
||||
|
@ -219,25 +220,6 @@ UNARY_CMD(pp_cmd, "display", "<term>", "display the given term.", CPK_EXPR, expr
|
|||
|
||||
UNARY_CMD(echo_cmd, "echo", "<string>", "display the given string", CPK_STRING, char const *, ctx.regular_stream() << arg << std::endl;);
|
||||
|
||||
/**
|
||||
\brief Convert a keyword into an internal Z3 option name
|
||||
*/
|
||||
std::string smt_keyword2opt_name(symbol const & opt) {
|
||||
std::string r;
|
||||
SASSERT(opt.bare_str()[0] == ':');
|
||||
r = opt.bare_str() + 1;
|
||||
unsigned sz = static_cast<unsigned>(r.size());
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
char curr = r[i];
|
||||
if ('a' <= curr && curr <= 'z')
|
||||
r[i] = 'A' + (curr - 'a');
|
||||
else if (curr == '-')
|
||||
r[i] = '_';
|
||||
}
|
||||
TRACE("smt2_opt_name", tout << opt << " -> '" << r << "'\n";);
|
||||
return r;
|
||||
}
|
||||
|
||||
class set_get_option_cmd : public cmd {
|
||||
protected:
|
||||
symbol m_true;
|
||||
|
@ -259,7 +241,6 @@ protected:
|
|||
symbol m_numeral_as_real;
|
||||
symbol m_error_behavior;
|
||||
symbol m_int_real_coercions;
|
||||
ini_params m_ini;
|
||||
|
||||
bool is_builtin_option(symbol const & s) const {
|
||||
return
|
||||
|
@ -289,10 +270,7 @@ public:
|
|||
m_global_decls(":global-decls"),
|
||||
m_numeral_as_real(":numeral-as-real"),
|
||||
m_error_behavior(":error-behavior"),
|
||||
m_int_real_coercions(":int-real-coercions"),
|
||||
m_ini(false) {
|
||||
params.register_params(m_ini);
|
||||
register_pp_params(m_ini);
|
||||
m_int_real_coercions(":int-real-coercions") {
|
||||
}
|
||||
virtual ~set_get_option_cmd() {}
|
||||
|
||||
|
@ -324,22 +302,11 @@ class set_option_cmd : public set_get_option_cmd {
|
|||
}
|
||||
|
||||
void set_param(cmd_context & ctx, char const * value) {
|
||||
m_ini.freeze(ctx.has_manager());
|
||||
std::string internal_opt = smt_keyword2opt_name(m_option);
|
||||
try {
|
||||
std::string old_value;
|
||||
if (!m_ini.get_param_value(internal_opt.c_str(), old_value)) {
|
||||
m_unsupported = true;
|
||||
return;
|
||||
}
|
||||
m_ini.set_param_value(internal_opt.c_str(), value);
|
||||
gparams::set(m_option, value);
|
||||
}
|
||||
catch (set_get_param_exception ex) {
|
||||
std::string msg = "error setting '";
|
||||
msg += m_option.str();
|
||||
msg += "', ";
|
||||
msg += ex.get_msg();
|
||||
throw cmd_exception(msg);
|
||||
catch (gparams::exception ex) {
|
||||
throw cmd_exception(ex.msg());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -545,12 +512,10 @@ public:
|
|||
print_bool(ctx, ctx.m().int_real_coercions());
|
||||
}
|
||||
else {
|
||||
std::string iopt = smt_keyword2opt_name(opt);
|
||||
std::string r;
|
||||
if (m_ini.get_param_value(iopt.c_str(), r)) {
|
||||
ctx.regular_stream() << r << std::endl;
|
||||
try {
|
||||
std::string val = gparams::get_value(opt);
|
||||
}
|
||||
else {
|
||||
catch (gparams::exception ex) {
|
||||
ctx.print_unsupported(opt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,22 @@ Notes:
|
|||
#include"model_evaluator.h"
|
||||
#include"for_each_expr.h"
|
||||
|
||||
std::string smt2_keyword_to_param(symbol const & opt) {
|
||||
std::string r;
|
||||
SASSERT(opt.bare_str()[0] == ':');
|
||||
r = opt.bare_str() + 1;
|
||||
unsigned sz = static_cast<unsigned>(r.size());
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
char curr = r[i];
|
||||
if ('A' <= curr && curr <= 'Z')
|
||||
r[i] = curr - 'A' + 'a';
|
||||
else if (curr == '-')
|
||||
r[i] = '_';
|
||||
}
|
||||
TRACE("smt2_keyword_to_param", tout << opt << " -> '" << r << "'\n";);
|
||||
return r;
|
||||
}
|
||||
|
||||
func_decls::func_decls(ast_manager & m, func_decl * f):
|
||||
m_decls(TAG(func_decl*, f, 0)) {
|
||||
m.inc_ref(f);
|
||||
|
@ -1400,9 +1416,9 @@ void cmd_context::validate_model() {
|
|||
get_check_sat_result()->get_model(md);
|
||||
SASSERT(md.get() != 0);
|
||||
params_ref p;
|
||||
p.set_uint(":max-degree", UINT_MAX); // evaluate algebraic numbers of any degree.
|
||||
p.set_uint(":sort-store", true);
|
||||
p.set_bool(":model-completion", true);
|
||||
p.set_uint("max_degree", UINT_MAX); // evaluate algebraic numbers of any degree.
|
||||
p.set_uint("sort_store", true);
|
||||
p.set_bool("model_completion", true);
|
||||
model_evaluator evaluator(*(md.get()), p);
|
||||
contains_array_op_proc contains_array(m());
|
||||
{
|
||||
|
|
|
@ -37,6 +37,11 @@ Notes:
|
|||
#include"progress_callback.h"
|
||||
#include"scoped_ptr_vector.h"
|
||||
|
||||
/**
|
||||
\brief Auxiliary function for converting SMT2 keywords into Z3 internal parameter names.
|
||||
*/
|
||||
std::string smt2_keyword_to_param(symbol const & k);
|
||||
|
||||
struct front_end_params;
|
||||
|
||||
class func_decls {
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
SASSERT(last_result);
|
||||
last_result->get_model(md);
|
||||
expr_ref r(ctx.m());
|
||||
unsigned timeout = m_params.get_uint(":timeout", UINT_MAX);
|
||||
unsigned timeout = m_params.get_uint("timeout", UINT_MAX);
|
||||
model_evaluator ev(*(md.get()), m_params);
|
||||
cancel_eh<model_evaluator> eh(ev);
|
||||
{
|
||||
|
|
|
@ -141,8 +141,8 @@ public:
|
|||
UNARY_CMD(bool_rewriter_cmd, "dbg-bool-rewriter", "<term>", "apply the Boolean rewriter to the given term", CPK_EXPR, expr *, {
|
||||
expr_ref t(ctx.m());
|
||||
params_ref p;
|
||||
p.set_bool(":flat", false);
|
||||
SASSERT(p.get_bool(":flat", true) == false);
|
||||
p.set_bool("flat", false);
|
||||
SASSERT(p.get_bool("flat", true) == false);
|
||||
bool_rewriter_star r(ctx.m(), p);
|
||||
r(arg, t);
|
||||
ctx.display(ctx.regular_stream(), t);
|
||||
|
@ -153,7 +153,7 @@ UNARY_CMD(bool_frewriter_cmd, "dbg-bool-flat-rewriter", "<term>", "apply the Boo
|
|||
expr_ref t(ctx.m());
|
||||
{
|
||||
params_ref p;
|
||||
p.set_bool(":flat", true);
|
||||
p.set_bool("flat", true);
|
||||
bool_rewriter_star r(ctx.m(), p);
|
||||
r(arg, t);
|
||||
}
|
||||
|
@ -165,8 +165,8 @@ UNARY_CMD(elim_and_cmd, "dbg-elim-and", "<term>", "apply the Boolean rewriter (e
|
|||
expr_ref t(ctx.m());
|
||||
{
|
||||
params_ref p;
|
||||
p.set_bool(":flat", true);
|
||||
p.set_bool(":elim-and", true);
|
||||
p.set_bool("flat", true);
|
||||
p.set_bool("elim_and", true);
|
||||
bool_rewriter_star r(ctx.m(), p);
|
||||
r(arg, t);
|
||||
}
|
||||
|
@ -208,15 +208,15 @@ UNARY_CMD(some_value_cmd, "dbg-some-value", "<sort>", "retrieve some value of th
|
|||
void tst_params(cmd_context & ctx) {
|
||||
params_ref p1;
|
||||
params_ref p2;
|
||||
p1.set_uint(":val", 100);
|
||||
p1.set_uint("val", 100);
|
||||
p2 = p1;
|
||||
SASSERT(p2.get_uint(":val", 0) == 100);
|
||||
p2.set_uint(":val", 200);
|
||||
SASSERT(p2.get_uint(":val", 0) == 200);
|
||||
SASSERT(p1.get_uint(":val", 0) == 100);
|
||||
SASSERT(p2.get_uint("val", 0) == 100);
|
||||
p2.set_uint("val", 200);
|
||||
SASSERT(p2.get_uint("val", 0) == 200);
|
||||
SASSERT(p1.get_uint("val", 0) == 100);
|
||||
p2 = p1;
|
||||
SASSERT(p2.get_uint(":val", 0) == 100);
|
||||
SASSERT(p1.get_uint(":val", 0) == 100);
|
||||
SASSERT(p2.get_uint("val", 0) == 100);
|
||||
SASSERT(p1.get_uint("val", 0) == 100);
|
||||
ctx.regular_stream() << "worked" << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ static void to_subpaving(cmd_context & ctx, expr * t) {
|
|||
expr2var e2v(m);
|
||||
expr2subpaving e2s(m, *s, &e2v);
|
||||
params_ref p;
|
||||
p.set_bool(":mul-to-power", true);
|
||||
p.set_bool("mul_to_power", true);
|
||||
th_rewriter simp(m, p);
|
||||
expr_ref t_s(m);
|
||||
simp(t, t_s);
|
||||
|
|
|
@ -16,6 +16,7 @@ Notes:
|
|||
|
||||
--*/
|
||||
#include<sstream>
|
||||
#include"cmd_context.h"
|
||||
#include"parametric_cmd.h"
|
||||
|
||||
char const * parametric_cmd::get_descr(cmd_context & ctx) const {
|
||||
|
@ -37,13 +38,15 @@ cmd_arg_kind parametric_cmd::next_arg_kind(cmd_context & ctx) const {
|
|||
|
||||
void parametric_cmd::set_next_arg(cmd_context & ctx, symbol const & s) {
|
||||
if (m_last == symbol::null) {
|
||||
m_last = s;
|
||||
m_last = symbol(smt2_keyword_to_param(s).c_str());
|
||||
if (pdescrs(ctx).get_kind(m_last.bare_str()) == CPK_INVALID)
|
||||
throw cmd_exception("invalid keyword argument");
|
||||
return;
|
||||
}
|
||||
m_params.set_sym(m_last.bare_str(), s);
|
||||
m_last = symbol::null;
|
||||
else {
|
||||
m_params.set_sym(m_last.bare_str(), s);
|
||||
m_last = symbol::null;
|
||||
}
|
||||
}
|
||||
|
||||
param_descrs const & parametric_cmd::pdescrs(cmd_context & ctx) const {
|
||||
|
|
|
@ -40,9 +40,9 @@ public:
|
|||
virtual void init_pdescrs(cmd_context & ctx, param_descrs & p) {
|
||||
th_rewriter::get_param_descrs(p);
|
||||
insert_timeout(p);
|
||||
p.insert(":print", CPK_BOOL, "(default: true) print the simplified term.");
|
||||
p.insert(":print-proofs", CPK_BOOL, "(default: false) print a proof showing the original term is equal to the resultant one.");
|
||||
p.insert(":print-statistics", CPK_BOOL, "(default: false) print statistics.");
|
||||
p.insert("print", CPK_BOOL, "(default: true) print the simplified term.");
|
||||
p.insert("print_proofs", CPK_BOOL, "(default: false) print a proof showing the original term is equal to the resultant one.");
|
||||
p.insert("print_statistics", CPK_BOOL, "(default: false) print statistics.");
|
||||
}
|
||||
|
||||
virtual ~simplify_cmd() {
|
||||
|
@ -67,12 +67,12 @@ public:
|
|||
throw cmd_exception("invalid simplify command, argument expected");
|
||||
expr_ref r(ctx.m());
|
||||
proof_ref pr(ctx.m());
|
||||
if (m_params.get_bool(":som", false))
|
||||
m_params.set_bool(":flat", true);
|
||||
if (m_params.get_bool("som", false))
|
||||
m_params.set_bool("flat", true);
|
||||
th_rewriter s(ctx.m(), m_params);
|
||||
unsigned cache_sz;
|
||||
unsigned num_steps = 0;
|
||||
unsigned timeout = m_params.get_uint(":timeout", UINT_MAX);
|
||||
unsigned timeout = m_params.get_uint("timeout", UINT_MAX);
|
||||
bool failed = false;
|
||||
cancel_eh<th_rewriter> eh(s);
|
||||
{
|
||||
|
@ -94,17 +94,17 @@ public:
|
|||
num_steps = s.get_num_steps();
|
||||
s.cleanup();
|
||||
}
|
||||
if (m_params.get_bool(":print", true)) {
|
||||
if (m_params.get_bool("print", true)) {
|
||||
ctx.display(ctx.regular_stream(), r);
|
||||
ctx.regular_stream() << std::endl;
|
||||
}
|
||||
if (!failed && m_params.get_bool(":print-proofs", false)) {
|
||||
if (!failed && m_params.get_bool("print_proofs", false)) {
|
||||
ast_smt_pp pp(ctx.m());
|
||||
pp.set_logic(ctx.get_logic().str().c_str());
|
||||
pp.display_expr_smt2(ctx.regular_stream(), pr.get());
|
||||
ctx.regular_stream() << std::endl;
|
||||
}
|
||||
if (m_params.get_bool(":print-statistics", false)) {
|
||||
if (m_params.get_bool("print_statistics", false)) {
|
||||
shared_occs s1(ctx.m());
|
||||
if (!failed)
|
||||
s1(r);
|
||||
|
|
|
@ -153,7 +153,7 @@ public:
|
|||
virtual void init_pdescrs(cmd_context & ctx, param_descrs & p) {
|
||||
insert_timeout(p);
|
||||
insert_max_memory(p);
|
||||
p.insert(":print-statistics", CPK_BOOL, "(default: false) print statistics.");
|
||||
p.insert("print_statistics", CPK_BOOL, "(default: false) print statistics.");
|
||||
}
|
||||
|
||||
void display_statistics(cmd_context & ctx, tactic * t) {
|
||||
|
@ -180,9 +180,9 @@ public:
|
|||
|
||||
virtual void init_pdescrs(cmd_context & ctx, param_descrs & p) {
|
||||
exec_given_tactic_cmd::init_pdescrs(ctx, p);
|
||||
p.insert(":print-unsat-core", CPK_BOOL, "(default: false) print unsatisfiable core.");
|
||||
p.insert(":print-proof", CPK_BOOL, "(default: false) print proof.");
|
||||
p.insert(":print-model", CPK_BOOL, "(default: false) print model.");
|
||||
p.insert("print_unsat_core", CPK_BOOL, "(default: false) print unsatisfiable core.");
|
||||
p.insert("print_proof", CPK_BOOL, "(default: false) print proof.");
|
||||
p.insert("print_model", CPK_BOOL, "(default: false) print model.");
|
||||
}
|
||||
|
||||
virtual void execute(cmd_context & ctx) {
|
||||
|
@ -192,7 +192,7 @@ public:
|
|||
tref->set_front_end_params(ctx.params());
|
||||
tref->set_logic(ctx.get_logic());
|
||||
ast_manager & m = ctx.m();
|
||||
unsigned timeout = p.get_uint(":timeout", UINT_MAX);
|
||||
unsigned timeout = p.get_uint("timeout", UINT_MAX);
|
||||
goal_ref g = alloc(goal, m, ctx.produce_proofs(), ctx.produce_models(), ctx.produce_unsat_cores());
|
||||
assert_exprs_from(ctx, *g);
|
||||
TRACE("check_sat_using", g->display(tout););
|
||||
|
@ -241,7 +241,7 @@ public:
|
|||
ptr_vector<expr> core_elems;
|
||||
m.linearize(core, core_elems);
|
||||
result->m_core.append(core_elems.size(), core_elems.c_ptr());
|
||||
if (p.get_bool(":print-unsat-core", false)) {
|
||||
if (p.get_bool("print_unsat_core", false)) {
|
||||
ctx.regular_stream() << "(unsat-core";
|
||||
ptr_vector<expr>::const_iterator it = core_elems.begin();
|
||||
ptr_vector<expr>::const_iterator end = core_elems.end();
|
||||
|
@ -255,7 +255,7 @@ public:
|
|||
|
||||
if (ctx.produce_models() && md) {
|
||||
result->m_model = md;
|
||||
if (p.get_bool(":print-model", false)) {
|
||||
if (p.get_bool("print_model", false)) {
|
||||
ctx.regular_stream() << "(model " << std::endl;
|
||||
model_smt2_pp(ctx.regular_stream(), ctx, *md, 2);
|
||||
ctx.regular_stream() << ")" << std::endl;
|
||||
|
@ -266,12 +266,12 @@ public:
|
|||
|
||||
if (ctx.produce_proofs() && pr) {
|
||||
result->m_proof = pr;
|
||||
if (p.get_bool(":print-proof", false)) {
|
||||
if (p.get_bool("print_proof", false)) {
|
||||
ctx.regular_stream() << mk_ismt2_pp(pr, m) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (p.get_bool(":print-statistics", false))
|
||||
if (p.get_bool("print_statistics", false))
|
||||
display_statistics(ctx, tref.get());
|
||||
}
|
||||
};
|
||||
|
@ -285,14 +285,14 @@ public:
|
|||
virtual char const * get_main_descr() const { return "apply the given tactic to the current context, and print the resultant set of goals."; }
|
||||
|
||||
virtual void init_pdescrs(cmd_context & ctx, param_descrs & p) {
|
||||
p.insert(":print", CPK_BOOL, "(default: true) print resultant goals.");
|
||||
p.insert("print", CPK_BOOL, "(default: true) print resultant goals.");
|
||||
#ifndef _EXTERNAL_RELEASE
|
||||
p.insert(":print-proof", CPK_BOOL, "(default: false) print proof associated with each assertion.");
|
||||
p.insert("print_proof", CPK_BOOL, "(default: false) print proof associated with each assertion.");
|
||||
#endif
|
||||
p.insert(":print-model-converter", CPK_BOOL, "(default: false) print model converter.");
|
||||
p.insert(":print-benchmark", CPK_BOOL, "(default: false) display resultant goals as a SMT2 benchmark.");
|
||||
p.insert("print_model_converter", CPK_BOOL, "(default: false) print model converter.");
|
||||
p.insert("print_benchmark", CPK_BOOL, "(default: false) display resultant goals as a SMT2 benchmark.");
|
||||
#ifndef _EXTERNAL_RELEASE
|
||||
p.insert(":print-dependencies", CPK_BOOL, "(default: false) print dependencies when displaying the resultant set of goals.");
|
||||
p.insert("print_dependencies", CPK_BOOL, "(default: false) print dependencies when displaying the resultant set of goals.");
|
||||
#endif
|
||||
exec_given_tactic_cmd::init_pdescrs(ctx, p);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ public:
|
|||
goal_ref g = alloc(goal, m, ctx.produce_proofs(), ctx.produce_models(), ctx.produce_unsat_cores());
|
||||
assert_exprs_from(ctx, *g);
|
||||
|
||||
unsigned timeout = p.get_uint(":timeout", UINT_MAX);
|
||||
unsigned timeout = p.get_uint("timeout", UINT_MAX);
|
||||
|
||||
goal_ref_buffer result_goals;
|
||||
model_converter_ref mc;
|
||||
|
@ -330,8 +330,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (!failed && p.get_bool(":print", true)) {
|
||||
bool print_dependencies = p.get_bool(":print-dependencies", false);
|
||||
if (!failed && p.get_bool("print", true)) {
|
||||
bool print_dependencies = p.get_bool("print_dependencies", false);
|
||||
ctx.regular_stream() << "(goals\n";
|
||||
unsigned sz = result_goals.size();
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
|
@ -344,12 +344,12 @@ public:
|
|||
}
|
||||
|
||||
#ifndef _EXTERNAL_RELEASE
|
||||
if (!failed && ctx.produce_proofs() && p.get_bool(":print-proof", false)) {
|
||||
if (!failed && ctx.produce_proofs() && p.get_bool("print_proof", false)) {
|
||||
// TODO
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!failed && p.get_bool(":print-benchmark", false)) {
|
||||
if (!failed && p.get_bool("print_benchmark", false)) {
|
||||
unsigned num_goals = result_goals.size();
|
||||
SASSERT(num_goals > 0);
|
||||
if (num_goals == 1) {
|
||||
|
@ -381,10 +381,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (!failed && mc && p.get_bool(":print-model-converter", false))
|
||||
if (!failed && mc && p.get_bool("print_model_converter", false))
|
||||
mc->display(ctx.regular_stream());
|
||||
|
||||
if (p.get_bool(":print-statistics", false))
|
||||
if (p.get_bool("print_statistics", false))
|
||||
display_statistics(ctx, tref.get());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue