mirror of
https://github.com/Z3Prover/z3
synced 2025-05-03 22:05:45 +00:00
context params
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
02e763bb6b
commit
f15de18c4a
11 changed files with 204 additions and 38 deletions
|
@ -29,6 +29,7 @@ Notes:
|
|||
#include"eval_cmd.h"
|
||||
#include"gparams.h"
|
||||
#include"model_params.hpp"
|
||||
#include"env_params.h"
|
||||
|
||||
class help_cmd : public cmd {
|
||||
svector<symbol> m_cmds;
|
||||
|
@ -305,6 +306,8 @@ class set_option_cmd : public set_get_option_cmd {
|
|||
void set_param(cmd_context & ctx, char const * value) {
|
||||
try {
|
||||
gparams::set(m_option, value);
|
||||
env_params::updt_params();
|
||||
ctx.params().updt_params();
|
||||
}
|
||||
catch (gparams::exception ex) {
|
||||
throw cmd_exception(ex.msg());
|
||||
|
|
|
@ -359,48 +359,43 @@ cmd_context::~cmd_context() {
|
|||
}
|
||||
|
||||
void cmd_context::set_produce_models(bool f) {
|
||||
// PARAM-TODO
|
||||
// params().m_model = f;
|
||||
if (m_solver)
|
||||
m_solver->set_produce_models(f);
|
||||
m_params.m_model = f;
|
||||
}
|
||||
|
||||
void cmd_context::set_produce_unsat_cores(bool f) {
|
||||
// can only be set before initialization
|
||||
SASSERT(!has_manager());
|
||||
m_produce_unsat_cores = f;
|
||||
m_params.m_unsat_core = f;
|
||||
}
|
||||
|
||||
void cmd_context::set_produce_proofs(bool f) {
|
||||
// PARAM-TODO
|
||||
// can only be set before initialization
|
||||
SASSERT(!has_manager());
|
||||
// params().m_proof_mode = f ? PGM_FINE : PGM_DISABLED;
|
||||
m_params.m_proof = f;
|
||||
}
|
||||
|
||||
bool cmd_context::produce_models() const {
|
||||
// PARAM-TODO
|
||||
// return params().m_model;
|
||||
return true;
|
||||
return m_params.m_model;
|
||||
}
|
||||
|
||||
bool cmd_context::produce_proofs() const {
|
||||
// PARAM-TODO
|
||||
// return params().m_proof_mode != PGM_DISABLED;
|
||||
return false;
|
||||
return m_params.m_proof;
|
||||
}
|
||||
|
||||
bool cmd_context::produce_unsat_cores() const {
|
||||
return m_params.m_unsat_core;
|
||||
}
|
||||
|
||||
bool cmd_context::well_sorted_check_enabled() const {
|
||||
// PARAM-TODO
|
||||
return true;
|
||||
return m_params.m_well_sorted_check;
|
||||
}
|
||||
|
||||
bool cmd_context::validate_model_enabled() const {
|
||||
// PARAM-TODO
|
||||
return false;
|
||||
return m_params.m_validate_model;
|
||||
}
|
||||
|
||||
|
||||
cmd_context::check_sat_state cmd_context::cs_state() const {
|
||||
if (m_check_sat_result.get() == 0)
|
||||
return css_clear;
|
||||
|
@ -593,10 +588,7 @@ void cmd_context::init_manager_core(bool new_manager) {
|
|||
insert(pm().mk_plist_decl());
|
||||
}
|
||||
if (m_solver) {
|
||||
m_solver->set_produce_unsat_cores(produce_unsat_cores());
|
||||
m_solver->set_produce_models(produce_models());
|
||||
m_solver->set_produce_proofs(produce_proofs());
|
||||
m_solver->init(m(), m_logic);
|
||||
init_solver_options(m_solver.get());
|
||||
}
|
||||
m_check_logic.set_logic(m(), m_logic);
|
||||
}
|
||||
|
@ -1455,14 +1447,23 @@ void cmd_context::validate_model() {
|
|||
}
|
||||
}
|
||||
|
||||
void cmd_context::init_solver_options(solver * s) {
|
||||
m_solver->set_produce_unsat_cores(produce_unsat_cores());
|
||||
m_solver->set_produce_models(produce_models());
|
||||
m_solver->set_produce_proofs(produce_proofs());
|
||||
m_solver->init(m(), m_logic);
|
||||
if (!m_params.m_auto_config) {
|
||||
params_ref p;
|
||||
p.set_bool("auto_config", false);
|
||||
m_solver->updt_params(p);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_context::set_solver(solver * s) {
|
||||
m_check_sat_result = 0;
|
||||
m_solver = s;
|
||||
if (has_manager() && s != 0) {
|
||||
m_solver->set_produce_unsat_cores(produce_unsat_cores());
|
||||
m_solver->set_produce_models(produce_models());
|
||||
m_solver->set_produce_proofs(produce_proofs());
|
||||
m_solver->init(m(), m_logic);
|
||||
init_solver_options(s);
|
||||
// assert formulas and create scopes in the new solver.
|
||||
unsigned lim = 0;
|
||||
svector<scope>::iterator it = m_scopes.begin();
|
||||
|
|
|
@ -36,6 +36,7 @@ Notes:
|
|||
#include"check_logic.h"
|
||||
#include"progress_callback.h"
|
||||
#include"scoped_ptr_vector.h"
|
||||
#include"context_params.h"
|
||||
|
||||
/**
|
||||
\brief Auxiliary function for converting SMT2 keywords into Z3 internal parameter names.
|
||||
|
@ -135,6 +136,7 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
context_params m_params;
|
||||
bool m_main_ctx;
|
||||
symbol m_logic;
|
||||
bool m_interactive_mode;
|
||||
|
@ -246,9 +248,12 @@ protected:
|
|||
void print_unsupported_msg() { regular_stream() << "unsupported" << std::endl; }
|
||||
void print_unsupported_info(symbol const& s) { if (s != symbol::null) diagnostic_stream() << "; " << s << std::endl;}
|
||||
|
||||
void init_solver_options(solver * s);
|
||||
|
||||
public:
|
||||
cmd_context(bool main_ctx = true, ast_manager * m = 0, symbol const & l = symbol::null);
|
||||
~cmd_context();
|
||||
context_params & params() { return m_params; }
|
||||
void set_logic(symbol const & s);
|
||||
bool has_logic() const { return m_logic != symbol::null; }
|
||||
symbol const & get_logic() const { return m_logic; }
|
||||
|
@ -270,7 +275,7 @@ public:
|
|||
void set_random_seed(unsigned s) { m_random_seed = s; }
|
||||
bool produce_models() const;
|
||||
bool produce_proofs() const;
|
||||
bool produce_unsat_cores() const { return m_produce_unsat_cores; }
|
||||
bool produce_unsat_cores() const;
|
||||
bool well_sorted_check_enabled() const;
|
||||
bool validate_model_enabled() const;
|
||||
void set_produce_models(bool flag);
|
||||
|
|
114
src/cmd_context/context_params.cpp
Normal file
114
src/cmd_context/context_params.cpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*++
|
||||
Copyright (c) 2011 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
context_params.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Goodies for managing context parameters in the cmd_context and
|
||||
api_context
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo (leonardo) 2012-12-01
|
||||
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
#include"context_params.h"
|
||||
#include"gparams.h"
|
||||
#include"params.h"
|
||||
|
||||
context_params::context_params() {
|
||||
updt_params();
|
||||
}
|
||||
|
||||
void context_params::set_bool(bool & opt, char const * param, char const * value) {
|
||||
if (strcmp(value, "true") == 0) {
|
||||
opt = true;
|
||||
}
|
||||
else if (strcmp(value, "false") == 0) {
|
||||
opt = false;
|
||||
}
|
||||
else {
|
||||
throw default_exception("invalid value '%s' for Boolean parameter '%s'", value, param);
|
||||
}
|
||||
}
|
||||
|
||||
void context_params::set(char const * param, char const * value) {
|
||||
std::string p = param;
|
||||
unsigned n = p.size();
|
||||
for (unsigned i = 0; i < n; i++) {
|
||||
if (p[i] >= 'A' && p[i] <= 'Z')
|
||||
p[i] = p[i] - 'A' + 'a';
|
||||
else if (p[i] == '-')
|
||||
p[i] = '_';
|
||||
}
|
||||
if (p == "timeout") {
|
||||
long val = strtol(value, 0, 10);
|
||||
m_timeout = static_cast<unsigned>(val);
|
||||
}
|
||||
else if (p == "type_check" || p == "well_sorted_check") {
|
||||
set_bool(m_well_sorted_check, param, value);
|
||||
}
|
||||
else if (p == "auto_config") {
|
||||
set_bool(m_auto_config, param, value);
|
||||
}
|
||||
else if (p == "proof") {
|
||||
set_bool(m_proof, param, value);
|
||||
}
|
||||
else if (p == "model") {
|
||||
set_bool(m_model, param, value);
|
||||
}
|
||||
else if (p == "validate_model") {
|
||||
set_bool(m_validate_model, param, value);
|
||||
}
|
||||
else if (p == "trace") {
|
||||
set_bool(m_trace, param, value);
|
||||
}
|
||||
else if (p == "trace_file_name") {
|
||||
m_trace_file_name = value;
|
||||
}
|
||||
else if (p == "unsat_core") {
|
||||
set_bool(m_unsat_core, param, value);
|
||||
}
|
||||
else if (p == "debug_ref_count") {
|
||||
set_bool(m_debug_ref_count, param, value);
|
||||
}
|
||||
else {
|
||||
throw default_exception("unknown parameter '%s'", p.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void context_params::updt_params() {
|
||||
updt_params(gparams::get());
|
||||
}
|
||||
|
||||
void context_params::updt_params(params_ref const & p) {
|
||||
m_timeout = p.get_uint("timeout", UINT_MAX);
|
||||
m_well_sorted_check = p.get_bool("type_check", p.get_bool("well_sorted_check", true));
|
||||
m_auto_config = p.get_bool("auto_config", true);
|
||||
m_proof = p.get_bool("proof", false);
|
||||
m_model = p.get_bool("model", true);
|
||||
m_validate_model = p.get_bool("validate_model", false);
|
||||
m_trace = p.get_bool("trace", false);
|
||||
m_trace_file_name = p.get_str("trace_file_name", "z3.log");
|
||||
m_unsat_core = p.get_bool("unsat_core", false);
|
||||
m_debug_ref_count = p.get_bool("debug_ref_count", false);
|
||||
}
|
||||
|
||||
void context_params::collect_param_descrs(param_descrs & d) {
|
||||
d.insert("timeout", CPK_UINT, "default timeout (in milliseconds) used for solvers", "4294967295");
|
||||
d.insert("well_sorted_check", CPK_BOOL, "type checker", "true");
|
||||
d.insert("type_check", CPK_BOOL, "type checker (alias for well_sorted_check)", "true");
|
||||
d.insert("auto_config", CPK_BOOL, "use heuristics to automatically select solver and configure it", "true");
|
||||
d.insert("proof", CPK_BOOL, "proof generation, it must be enabled when the Z3 context is created", "false");
|
||||
d.insert("model", CPK_BOOL, "model generation for solvers, this parameter can be overwritten when creating a solver", "true");
|
||||
d.insert("validate_model", CPK_BOOL, "validate models produced by solvers", "false");
|
||||
d.insert("trace", CPK_BOOL, "trace generation for VCC", "false");
|
||||
d.insert("trace_file_name", CPK_STRING, "trace out file name (see option 'trace')", "z3.log");
|
||||
d.insert("unsat_core", CPK_BOOL, "unsat-core generation for solvers, this parameter can be overwritten when creating a solver, not every solver in Z3 supports unsat core generation", "false");
|
||||
d.insert("debug_ref_count", CPK_BOOL, "debug support for AST reference counting", "false");
|
||||
}
|
52
src/cmd_context/context_params.h
Normal file
52
src/cmd_context/context_params.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*++
|
||||
Copyright (c) 2011 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
context_params.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Goodies for managing context parameters in the cmd_context and
|
||||
api_context
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo (leonardo) 2012-12-01
|
||||
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
#ifndef _CONTEXT_PARAMS_H_
|
||||
#define _CONTEXT_PARAMS_H_
|
||||
|
||||
#include"params.h"
|
||||
|
||||
class context_params {
|
||||
void set_bool(bool & opt, char const * param, char const * value);
|
||||
|
||||
public:
|
||||
bool m_auto_config;
|
||||
bool m_proof;
|
||||
bool m_debug_ref_count;
|
||||
bool m_trace;
|
||||
std::string m_trace_file_name;
|
||||
bool m_well_sorted_check;
|
||||
bool m_model;
|
||||
bool m_validate_model;
|
||||
bool m_unsat_core;
|
||||
unsigned m_timeout;
|
||||
bool m_statistics;
|
||||
|
||||
context_params();
|
||||
void set(char const * param, char const * value);
|
||||
void updt_params();
|
||||
void updt_params(params_ref const & p);
|
||||
static void collect_param_descrs(param_descrs & d);
|
||||
/*
|
||||
REG_PARAMS('context_params::collect_param_descrs')
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue