diff --git a/src/api/api_context.cpp b/src/api/api_context.cpp index 02069e06d..2d242f9b0 100644 --- a/src/api/api_context.cpp +++ b/src/api/api_context.cpp @@ -82,7 +82,7 @@ namespace api { context::context(context_params * p, bool user_ref_count): m_params(*p), m_user_ref_count(user_ref_count), - m_manager(m_params.m_proof ? PGM_FINE : PGM_DISABLED), // PARAM-TODO , _fparams.m_proof_mode, m_fparams.m_trace_stream), + m_manager(m_params.m_proof ? PGM_FINE : PGM_DISABLED, m_params.m_trace ? m_params.m_trace_file_name.c_str() : 0), m_plugins(m_manager), m_arith_util(m_manager), m_bv_util(m_manager), diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 67f07e414..ae82dcadf 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -1196,13 +1196,36 @@ decl_plugin * user_sort_plugin::mk_fresh() { // // ----------------------------------- -ast_manager::ast_manager(proof_gen_mode m, std::ostream *trace_stream, bool is_format_manager): +ast_manager::ast_manager(proof_gen_mode m, char const * trace_file, bool is_format_manager): m_alloc("ast_manager"), m_expr_array_manager(*this, m_alloc), m_expr_dependency_manager(*this, m_alloc), m_expr_dependency_array_manager(*this, m_alloc), m_proof_mode(m), - m_trace_stream(trace_stream) { + m_trace_stream(0), + m_trace_stream_owner(false) { + + if (trace_file) { + m_trace_stream = alloc(std::fstream, trace_file, std::ios_base::out); + m_trace_stream_owner = true; + } + + if (!is_format_manager) + m_format_manager = alloc(ast_manager, PGM_DISABLED, m_trace_stream, true); + else + m_format_manager = 0; + init(); +} + +ast_manager::ast_manager(proof_gen_mode m, std::fstream * trace_stream, bool is_format_manager): + m_alloc("ast_manager"), + m_expr_array_manager(*this, m_alloc), + m_expr_dependency_manager(*this, m_alloc), + m_expr_dependency_array_manager(*this, m_alloc), + m_proof_mode(m), + m_trace_stream(trace_stream), + m_trace_stream_owner(false) { + if (!is_format_manager) m_format_manager = alloc(ast_manager, PGM_DISABLED, trace_stream, true); else @@ -1216,9 +1239,10 @@ ast_manager::ast_manager(ast_manager const & src, bool disable_proofs): m_expr_dependency_manager(*this, m_alloc), m_expr_dependency_array_manager(*this, m_alloc), m_proof_mode(disable_proofs ? PGM_DISABLED : src.m_proof_mode), - m_trace_stream(src.m_trace_stream) { + m_trace_stream(src.m_trace_stream), + m_trace_stream_owner(false) { SASSERT(!src.is_format_manager()); - m_format_manager = 0; + m_format_manager = alloc(ast_manager, PGM_DISABLED, m_trace_stream, true); init(); copy_families_plugins(src); } @@ -1256,6 +1280,7 @@ void ast_manager::init() { ast_manager::~ast_manager() { SASSERT(is_format_manager() || !m_family_manager.has_family(symbol("format"))); + dec_ref(m_bool_sort); dec_ref(m_proof_sort); dec_ref(m_true); @@ -1294,6 +1319,13 @@ ast_manager::~ast_manager() { #endif if (m_format_manager != 0) dealloc(m_format_manager); + if (m_trace_stream_owner) { + std::fstream & tmp = * m_trace_stream; + tmp << "[eof]\n"; + tmp.close(); + dealloc(m_trace_stream); + m_trace_stream = 0; + } } void ast_manager::compact_memory() { @@ -1873,8 +1905,8 @@ app * ast_manager::mk_app_core(func_decl * decl, unsigned num_args, expr * const new_node = new (mem) app(decl, num_args, args); r = register_node(new_node); } -#ifndef SMTCOMP - if (m_trace_stream != NULL && r == new_node) { + + if (m_trace_stream && r == new_node) { *m_trace_stream << "[mk-app] #" << r->get_id() << " "; if (r->get_num_args() == 0 && r->get_decl()->get_name() == "int") { ast_ll_pp(*m_trace_stream, *this, r); @@ -1887,7 +1919,7 @@ app * ast_manager::mk_app_core(func_decl * decl, unsigned num_args, expr * const *m_trace_stream << "\n"; } } -#endif + return r; } @@ -2064,8 +2096,7 @@ quantifier * ast_manager::mk_quantifier(bool forall, unsigned num_decls, sort * num_no_patterns, no_patterns); quantifier * r = register_node(new_node); -#ifndef SMTCOMP - if (m_trace_stream != NULL && r == new_node) { + if (m_trace_stream && r == new_node) { *m_trace_stream << "[mk-quant] #" << r->get_id() << " " << qid; for (unsigned i = 0; i < num_patterns; ++i) { *m_trace_stream << " #" << patterns[i]->get_id(); @@ -2073,7 +2104,7 @@ quantifier * ast_manager::mk_quantifier(bool forall, unsigned num_decls, sort * *m_trace_stream << " #" << body->get_id() << "\n"; } -#endif + return r; } diff --git a/src/ast/ast.h b/src/ast/ast.h index 8453598f2..2a0872721 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -1350,7 +1350,8 @@ protected: unsigned m_fresh_id; bool m_debug_ref_count; u_map m_debug_free_indices; - std::ostream* m_trace_stream; + std::fstream* m_trace_stream; + bool m_trace_stream_owner; #ifdef Z3DEBUG bool slow_not_contains(ast const * n); #endif @@ -1361,10 +1362,14 @@ protected: bool coercion_needed(func_decl * decl, unsigned num_args, expr * const * args); public: - ast_manager(proof_gen_mode = PGM_DISABLED, std::ostream * trace_stream = NULL, bool is_format_manager = false); + ast_manager(proof_gen_mode = PGM_DISABLED, char const * trace_file = 0, bool is_format_manager = false); + ast_manager(proof_gen_mode, std::fstream * trace_stream, bool is_format_manager = false); ast_manager(ast_manager const & src, bool disable_proofs = false); ~ast_manager(); + bool has_trace_stream() const { return m_trace_stream != 0; } + std::ostream & trace_stream() { SASSERT(has_trace_stream()); return *m_trace_stream; } + void enable_int_real_coercions(bool f) { m_int_real_coercions = f; } bool int_real_coercions() const { return m_int_real_coercions; } diff --git a/src/cmd_context/cmd_context.cpp b/src/cmd_context/cmd_context.cpp index 1a018a41d..19fbdcd3c 100644 --- a/src/cmd_context/cmd_context.cpp +++ b/src/cmd_context/cmd_context.cpp @@ -597,7 +597,9 @@ void cmd_context::init_manager() { SASSERT(m_manager == 0); SASSERT(m_pmanager == 0); m_check_sat_result = 0; - m_manager = alloc(ast_manager, produce_proofs() ? PGM_FINE : PGM_DISABLED); // PARAM-TODO , params().m_trace_stream); + m_manager = alloc(ast_manager, + produce_proofs() ? PGM_FINE : PGM_DISABLED, + m_params.m_trace ? m_params.m_trace_file_name.c_str() : 0); m_pmanager = alloc(pdecl_manager, *m_manager); init_manager_core(true); // PARAM-TODO diff --git a/src/front_end_params/front_end_params.cpp b/src/front_end_params/front_end_params.cpp index f00c21d56..367c983c3 100644 --- a/src/front_end_params/front_end_params.cpp +++ b/src/front_end_params/front_end_params.cpp @@ -49,19 +49,3 @@ void front_end_params::register_params(ini_params & p) { #endif -void front_end_params::open_trace_file() { - if (m_trace) { - m_trace_stream = alloc(std::fstream, m_trace_file_name.c_str(), std::ios_base::out); - } -} - -void front_end_params::close_trace_file() { - if (m_trace_stream != NULL) { - std::fstream &tmp = *m_trace_stream; - m_trace_stream = NULL; - tmp << "[eof]\n"; - tmp.close(); - // do not delete it, this might be called from a Ctrl-C signal handler - // and there might be someone writing to it - } -} diff --git a/src/front_end_params/front_end_params.h b/src/front_end_params/front_end_params.h index 2c7dbfa2e..9bf5dd69c 100644 --- a/src/front_end_params/front_end_params.h +++ b/src/front_end_params/front_end_params.h @@ -30,9 +30,6 @@ struct front_end_params : public smt_params { bool m_auto_config; bool m_debug_ref_count; - bool m_trace; - std::string m_trace_file_name; - std::fstream* m_trace_stream; front_end_params(): m_well_sorted_check(true), @@ -40,16 +37,9 @@ struct front_end_params : public smt_params { m_memory_max_size(0), m_proof_mode(PGM_DISABLED), m_auto_config(true), - m_debug_ref_count(false), - m_trace(false), - m_trace_file_name("z3.log"), - m_trace_stream(NULL) { + m_debug_ref_count(false) { } - void open_trace_file(); - - void close_trace_file(); - bool has_auto_config(unsigned idx) { return m_auto_config; } private: diff --git a/src/parsers/smt/smtlib_solver.cpp b/src/parsers/smt/smtlib_solver.cpp index ddcdb56c8..ef28216bf 100644 --- a/src/parsers/smt/smtlib_solver.cpp +++ b/src/parsers/smt/smtlib_solver.cpp @@ -33,9 +33,9 @@ Revision History: namespace smtlib { - solver::solver(front_end_params & params): - m_ast_manager(params.m_proof_mode, params.m_trace_stream), - m_params(params), + solver::solver(): + m_ast_manager(m_params.m_proof ? PGM_FINE : PGM_DISABLED, + m_params.m_trace ? m_params.m_trace_file_name.c_str() : 0), m_ctx(0), m_error_code(0) { parser_params ps; @@ -103,7 +103,7 @@ namespace smtlib { check_sat_result * r = m_ctx->get_check_sat_result(); if (r != 0) { proof * pr = r->get_proof(); - if (pr != 0 && m_params.m_display_proof) + if (pr != 0 && m_params.m_proof) std::cout << mk_ll_pp(pr, m_ast_manager, false, false); model_ref md; if (r->status() != l_false) r->get_model(md); diff --git a/src/parsers/smt/smtlib_solver.h b/src/parsers/smt/smtlib_solver.h index a84f2c98f..4e9815d38 100644 --- a/src/parsers/smt/smtlib_solver.h +++ b/src/parsers/smt/smtlib_solver.h @@ -20,20 +20,20 @@ Revision History: #define _SMTLIB_SOLVER_H_ #include"smtparser.h" -#include"front_end_params.h" +#include"context_params.h" #include"lbool.h" class cmd_context; namespace smtlib { class solver { + context_params m_params; ast_manager m_ast_manager; - front_end_params & m_params; cmd_context * m_ctx; scoped_ptr m_parser; unsigned m_error_code; public: - solver(front_end_params & params); + solver(); ~solver(); bool solve_smt(char const * benchmark_file); bool solve_smt_string(char const * benchmark_string); diff --git a/src/shell/main.cpp b/src/shell/main.cpp index 9cef54628..ecbaf8887 100644 --- a/src/shell/main.cpp +++ b/src/shell/main.cpp @@ -122,8 +122,6 @@ void init_params() { } void del_params() { - if (g_front_end_params != NULL) - g_front_end_params->close_trace_file(); delete g_extra_params; delete g_front_end_params; g_extra_params = 0; @@ -315,7 +313,6 @@ int main(int argc, char ** argv) { parse_cmd_line_args(argc, argv); env_params::updt_params(); - g_front_end_params->open_trace_file(); if (g_input_file && g_standard_input) { error("using standard input to read formula."); } @@ -346,11 +343,11 @@ int main(int argc, char ** argv) { } switch (g_input_kind) { case IN_SMTLIB: - return_value = read_smtlib_file(g_input_file, *g_front_end_params); + return_value = read_smtlib_file(g_input_file); break; case IN_SMTLIB_2: memory::exit_when_out_of_memory(true, "(error \"out of memory\")"); - return_value = read_smtlib2_commands(g_input_file, *g_front_end_params); + return_value = read_smtlib2_commands(g_input_file); break; case IN_DIMACS: return_value = read_dimacs(g_input_file); diff --git a/src/shell/smtlib_frontend.cpp b/src/shell/smtlib_frontend.cpp index c95b90098..1551329c6 100644 --- a/src/shell/smtlib_frontend.cpp +++ b/src/shell/smtlib_frontend.cpp @@ -67,11 +67,11 @@ static void on_ctrl_c(int) { raise(SIGINT); } -unsigned read_smtlib_file(char const * benchmark_file, front_end_params & front_end_params) { +unsigned read_smtlib_file(char const * benchmark_file) { g_start_time = clock(); register_on_timeout_proc(on_timeout); signal(SIGINT, on_ctrl_c); - smtlib::solver solver(front_end_params); + smtlib::solver solver; g_solver = &solver; bool ok = true; @@ -92,7 +92,7 @@ unsigned read_smtlib_file(char const * benchmark_file, front_end_params & front_ return solver.get_error_code(); } -unsigned read_smtlib2_commands(char const* file_name, front_end_params& front_end_params) { +unsigned read_smtlib2_commands(char const * file_name) { g_start_time = clock(); register_on_timeout_proc(on_timeout); signal(SIGINT, on_ctrl_c); diff --git a/src/shell/smtlib_frontend.h b/src/shell/smtlib_frontend.h index 0db1571e4..d83944119 100644 --- a/src/shell/smtlib_frontend.h +++ b/src/shell/smtlib_frontend.h @@ -21,14 +21,8 @@ Revision History: #include"front_end_params.h" -unsigned read_smtlib_file(char const * benchmark_file, front_end_params & front_end_params); - -unsigned read_smtlib_commands(char const* command_file, front_end_params& front_end_params); -unsigned read_smtlib2_commands(char const* command_file, front_end_params& front_end_params); - -#ifdef _Z3_BUILD_PARALLEL_MPI -unsigned start_mpi_subordinate(front_end_params& front_end_params); -#endif +unsigned read_smtlib_file(char const * benchmark_file); +unsigned read_smtlib2_commands(char const * command_file); #endif /* _SMTLIB_FRONTEND_H_ */ diff --git a/src/smt/mam.cpp b/src/smt/mam.cpp index ba97d8939..24b8e2e7c 100644 --- a/src/smt/mam.cpp +++ b/src/smt/mam.cpp @@ -1824,7 +1824,6 @@ namespace smt { backtrack_stack m_backtrack_stack; unsigned m_top; const instruction * m_pc; - std::ostream* m_trace_stream; // auxiliary temporary variables unsigned m_max_generation; // the maximum generation of an app enode processed. @@ -1855,10 +1854,9 @@ namespace smt { void update_max_generation(enode * n) { m_max_generation = std::max(m_max_generation, n->get_generation()); -#ifndef SMTCOMP - if (m_trace_stream != NULL) + + if (m_ast_manager.has_trace_stream()) m_used_enodes.push_back(n); -#endif } // We have to provide the number of expected arguments because we have flat-assoc applications such as +. @@ -1965,12 +1963,11 @@ namespace smt { #define INIT_ARGS_SIZE 16 public: - interpreter(context & ctx, mam & m, bool use_filters, std::ostream *trace_stream): + interpreter(context & ctx, mam & m, bool use_filters): m_context(ctx), m_ast_manager(ctx.get_manager()), m_mam(m), - m_use_filters(use_filters), - m_trace_stream(trace_stream) { + m_use_filters(use_filters) { m_args.resize(INIT_ARGS_SIZE, 0); } @@ -2266,12 +2263,12 @@ namespace smt { m_pattern_instances.reset(); m_pattern_instances.push_back(n); m_max_generation = n->get_generation(); -#ifndef SMTCOMP - if (m_trace_stream != NULL) { + + if (m_ast_manager.has_trace_stream()) { m_used_enodes.reset(); m_used_enodes.push_back(n); } -#endif + m_pc = t->get_root(); m_registers[0] = n; m_top = 0; @@ -2638,10 +2635,10 @@ namespace smt { } backtrack_point & bp = m_backtrack_stack[m_top - 1]; m_max_generation = bp.m_old_max_generation; -#ifndef SMTCOMP - if (m_trace_stream != NULL) + + if (m_ast_manager.has_trace_stream()) m_used_enodes.shrink(bp.m_old_used_enodes_size); -#endif + TRACE("mam_int", tout << "backtrack top: " << bp.m_instr << " " << *(bp.m_instr) << "\n";); #ifdef _PROFILE_MAM if (bp.m_instr->m_opcode != CHOOSE) // CHOOSE has a different status. It is a control flow backtracking. @@ -3759,14 +3756,14 @@ namespace smt { } public: - mam_impl(context & ctx, bool use_filters, std::ostream *trace): - mam(ctx, trace), + mam_impl(context & ctx, bool use_filters): + mam(ctx), m_ast_manager(ctx.get_manager()), m_use_filters(use_filters), m_trail_stack(*this), m_ct_manager(m_lbl_hasher, m_trail_stack), m_compiler(ctx, m_ct_manager, m_lbl_hasher, use_filters), - m_interpreter(ctx, *this, use_filters, trace), + m_interpreter(ctx, *this, use_filters), m_trees(m_ast_manager, m_compiler, m_trail_stack), m_region(m_trail_stack.get_region()), m_r1(0), @@ -3980,8 +3977,8 @@ namespace smt { } }; - mam * mk_mam(context & ctx, std::ostream *trace) { - return alloc(mam_impl, ctx, true, trace); + mam * mk_mam(context & ctx) { + return alloc(mam_impl, ctx, true); } }; diff --git a/src/smt/mam.h b/src/smt/mam.h index cee6f6e2f..c9f813150 100644 --- a/src/smt/mam.h +++ b/src/smt/mam.h @@ -29,11 +29,9 @@ namespace smt { class mam { protected: context & m_context; - std::ostream * m_trace_stream; public: - mam(context & ctx, std::ostream *trace): - m_context(ctx), - m_trace_stream(trace) { + mam(context & ctx): + m_context(ctx) { } virtual ~mam() { @@ -68,7 +66,7 @@ namespace smt { #endif }; - mam * mk_mam(context & ctx, std::ostream *trace); + mam * mk_mam(context & ctx); }; #endif /* _MAM_H_ */ diff --git a/src/smt/qi_queue.cpp b/src/smt/qi_queue.cpp index a2a2cc9de..9394dae34 100644 --- a/src/smt/qi_queue.cpp +++ b/src/smt/qi_queue.cpp @@ -26,7 +26,7 @@ Revision History: namespace smt { - qi_queue::qi_queue(quantifier_manager & qm, context & ctx, qi_params & params, std::ostream *trace_stream): + qi_queue::qi_queue(quantifier_manager & qm, context & ctx, qi_params & params): m_qm(qm), m_context(ctx), m_manager(m_context.get_manager()), @@ -37,7 +37,6 @@ namespace smt { m_parser(m_manager), m_evaluator(m_manager), m_subst(m_manager), - m_trace_stream(trace_stream), m_instances(m_manager) { init_parser_vars(); m_vals.resize(15, 0.0f); @@ -173,25 +172,23 @@ namespace smt { } void qi_queue::display_instance_profile(fingerprint * f, quantifier * q, unsigned num_bindings, enode * const * bindings, unsigned proof_id, unsigned generation) { -#ifndef SMTCOMP - if (m_trace_stream != NULL) { - *m_trace_stream << "[instance] "; + if (m_manager.has_trace_stream()) { + m_manager.trace_stream() << "[instance] "; #if 1 - *m_trace_stream << static_cast(f); + m_manager.trace_stream() << static_cast(f); #else for (unsigned i = 0; i < num_bindings; i++) { // I don't want to use mk_pp because it creates expressions for pretty printing. // This nasty side-effect may change the behavior of Z3. - *m_trace_stream << " #" << bindings[i]->get_owner_id(); + m_manager.trace_stream() << " #" << bindings[i]->get_owner_id(); } #endif if (m_manager.proofs_enabled()) - *m_trace_stream << " #" << proof_id; - *m_trace_stream << " ; " << generation; - *m_trace_stream << "\n"; + m_manager.trace_stream() << " #" << proof_id; + m_manager.trace_stream() << " ; " << generation; + m_manager.trace_stream() << "\n"; } -#endif } void qi_queue::instantiate(entry & ent) { @@ -224,10 +221,10 @@ namespace smt { TRACE("qi_queue_bug", tout << "new instance after simplification:\n" << mk_pp(s_instance, m_manager) << "\n";); if (m_manager.is_true(s_instance)) { TRACE("checker", tout << "reduced to true, before:\n" << mk_ll_pp(instance, m_manager);); -#ifndef SMTCOMP - if (m_trace_stream != NULL) - *m_trace_stream << "[end-of-instance]\n"; -#endif + + if (m_manager.has_trace_stream()) + m_manager.trace_stream() << "[end-of-instance]\n"; + return; } quantifier_stat * stat = m_qm.get_stat(q); @@ -308,10 +305,10 @@ namespace smt { } } }); -#ifndef SMTCOMP - if (m_trace_stream != NULL) - *m_trace_stream << "[end-of-instance]\n"; -#endif + + if (m_manager.has_trace_stream()) + m_manager.trace_stream() << "[end-of-instance]\n"; + } void qi_queue::push_scope() { diff --git a/src/smt/qi_queue.h b/src/smt/qi_queue.h index 43d57d84f..1060f083b 100644 --- a/src/smt/qi_queue.h +++ b/src/smt/qi_queue.h @@ -53,7 +53,6 @@ namespace smt { cached_var_subst m_subst; svector m_vals; double m_eager_cost_threshold; - std::ostream * m_trace_stream; struct entry { fingerprint * m_qb; float m_cost; @@ -81,7 +80,7 @@ namespace smt { void display_instance_profile(fingerprint * f, quantifier * q, unsigned num_bindings, enode * const * bindings, unsigned proof_id, unsigned generation); public: - qi_queue(quantifier_manager & qm, context & ctx, qi_params & params, std::ostream *trace); + qi_queue(quantifier_manager & qm, context & ctx, qi_params & params); ~qi_queue(); void setup(); /** diff --git a/src/smt/smt_case_split_queue.cpp b/src/smt/smt_case_split_queue.cpp index 66d08e9fc..808284224 100644 --- a/src/smt/smt_case_split_queue.cpp +++ b/src/smt/smt_case_split_queue.cpp @@ -395,8 +395,8 @@ namespace smt { if ((is_or && val == l_true) || (is_and && val == l_false)) { expr * undef_child = 0; if (!has_child_assigned_to(m_context, to_app(curr), val, undef_child, m_params.m_rel_case_split_order)) { - if (m_params.m_trace_stream != NULL) { - *m_params.m_trace_stream << "[decide-and-or] #" << curr->get_id() << " #" << undef_child->get_id() << "\n"; + if (m_manager.has_trace_stream()) { + m_manager.trace_stream() << "[decide-and-or] #" << curr->get_id() << " #" << undef_child->get_id() << "\n"; } TRACE("case_split", tout << "found AND/OR candidate: #" << curr->get_id() << " #" << undef_child->get_id() << "\n";); literal l = m_context.get_literal(undef_child); @@ -851,8 +851,8 @@ namespace smt { if ((is_or && val == l_true) || (is_and && val == l_false)) { expr * undef_child = 0; if (!has_child_assigned_to(m_context, to_app(curr), val, undef_child, m_params.m_rel_case_split_order)) { - if (m_params.m_trace_stream != NULL) { - *m_params.m_trace_stream << "[decide-and-or] #" << curr->get_id() << " #" << undef_child->get_id() << "\n"; + if (m_manager.has_trace_stream()) { + m_manager.trace_stream() << "[decide-and-or] #" << curr->get_id() << " #" << undef_child->get_id() << "\n"; } TRACE("case_split", tout << "found AND/OR candidate: #" << curr->get_id() << " #" << undef_child->get_id() << "\n";); literal l = m_context.get_literal(undef_child); @@ -900,11 +900,6 @@ namespace smt { // does the push after calling us m_priority_queue2.insert(idx); e.m_last_decided = -1; - /* - if (m_params.m_trace_stream != NULL) { - *m_params.m_trace_stream << "[generation] #" << e.m_expr->get_id() << " " << e.m_generation << "\n"; - } - */ return; } } diff --git a/src/smt/smt_conflict_resolution.cpp b/src/smt/smt_conflict_resolution.cpp index 2bc32e217..071275dd4 100644 --- a/src/smt/smt_conflict_resolution.cpp +++ b/src/smt/smt_conflict_resolution.cpp @@ -304,13 +304,13 @@ namespace smt { if (th) th->conflict_resolution_eh(to_app(n), var); } -#ifndef SMTCOMP - if (m_params.m_trace_stream != NULL) { - *m_params.m_trace_stream << "[resolve-lit] " << m_conflict_lvl - lvl << " "; - m_ctx.display_literal(*m_params.m_trace_stream, ~antecedent); - *m_params.m_trace_stream << "\n"; + + if (get_manager().has_trace_stream()) { + get_manager().trace_stream() << "[resolve-lit] " << m_conflict_lvl - lvl << " "; + m_ctx.display_literal(get_manager().trace_stream(), ~antecedent); + get_manager().trace_stream() << "\n"; } -#endif + if (lvl == m_conflict_lvl) { num_marks++; } @@ -478,13 +478,12 @@ namespace smt { } do { -#ifndef SMTCOMP - if (m_params.m_trace_stream != NULL) { - *m_params.m_trace_stream << "[resolve-process] "; - m_ctx.display_literal(*m_params.m_trace_stream, ~consequent); - *m_params.m_trace_stream << "\n"; + + if (get_manager().has_trace_stream()) { + get_manager().trace_stream() << "[resolve-process] "; + m_ctx.display_literal(get_manager().trace_stream(), ~consequent); + get_manager().trace_stream() << "\n"; } -#endif TRACE("conflict", tout << "processing consequent: "; m_ctx.display_literal(tout, consequent); tout << "\n"; tout << "num_marks: " << num_marks << ", js kind: " << js.get_kind() << "\n";); diff --git a/src/smt/smt_context.cpp b/src/smt/smt_context.cpp index 1aae1c62a..3fb8398b4 100644 --- a/src/smt/smt_context.cpp +++ b/src/smt/smt_context.cpp @@ -190,11 +190,10 @@ namespace smt { TRACE("phase_selection", tout << "saving phase, is_pos: " << d.m_phase << " l: " << l << "\n";); if (d.is_atom() && (m_fparams.m_relevancy_lvl == 0 || (m_fparams.m_relevancy_lvl == 1 && !d.is_quantifier()) || is_relevant_core(bool_var2expr(l.var())))) m_atom_propagation_queue.push_back(l); -#ifndef SMTCOMP - if (m_fparams.m_trace_stream != NULL) + + if (m_manager.has_trace_stream()) trace_assign(l, j, decision); m_case_split_queue->assign_lit_eh(l); -#endif } bool context::bcp() { @@ -1789,10 +1788,10 @@ namespace smt { \brief Create an internal backtracking point */ void context::push_scope() { -#ifndef SMTCOMP - if (m_fparams.m_trace_stream != NULL) - *m_fparams.m_trace_stream << "[push] " << m_scope_lvl << "\n"; -#endif + + if (m_manager.has_trace_stream()) + m_manager.trace_stream() << "[push] " << m_scope_lvl << "\n"; + m_scope_lvl++; m_region.push_scope(); m_scopes.push_back(scope()); @@ -2237,10 +2236,10 @@ namespace smt { \warning This method will not invoke reset_cache_generation. */ unsigned context::pop_scope_core(unsigned num_scopes) { -#ifndef SMTCOMP - if (m_fparams.m_trace_stream != NULL) - *m_fparams.m_trace_stream << "[pop] " << num_scopes << " " << m_scope_lvl << "\n"; -#endif + + if (m_manager.has_trace_stream()) + m_manager.trace_stream() << "[pop] " << num_scopes << " " << m_scope_lvl << "\n"; + TRACE("context", tout << "backtracking: " << num_scopes << "\n";); TRACE("pop_scope_detail", display(tout);); SASSERT(num_scopes > 0); @@ -2927,10 +2926,8 @@ namespace smt { Return true if succeeded. */ bool context::check_preamble(bool reset_cancel) { -#ifndef SMTCOMP - if (m_fparams.m_trace_stream != NULL) - *m_fparams.m_trace_stream << "[begin-check] " << m_scope_lvl << "\n"; -#endif + if (m_manager.has_trace_stream()) + m_manager.trace_stream() << "[begin-check] " << m_scope_lvl << "\n"; if (reset_cancel) { m_cancel_flag = false; @@ -3534,13 +3531,13 @@ namespace smt { tout << ", ilvl: " << get_intern_level(l.var()) << "\n" << mk_pp(bool_var2expr(l.var()), m_manager) << "\n"; }); -#ifndef SMTCOMP - if (m_fparams.m_trace_stream != NULL) { - *m_fparams.m_trace_stream << "[conflict] "; - display_literals(*m_fparams.m_trace_stream, num_lits, lits); - *m_fparams.m_trace_stream << "\n"; + + if (m_manager.has_trace_stream()) { + m_manager.trace_stream() << "[conflict] "; + display_literals(m_manager.trace_stream(), num_lits, lits); + m_manager.trace_stream() << "\n"; } -#endif + #ifdef Z3DEBUG expr_ref_vector expr_lits(m_manager); svector expr_signs; diff --git a/src/smt/smt_context_pp.cpp b/src/smt/smt_context_pp.cpp index 4bc5dfd74..9ce684440 100644 --- a/src/smt/smt_context_pp.cpp +++ b/src/smt/smt_context_pp.cpp @@ -583,7 +583,8 @@ namespace smt { } void context::trace_assign(literal l, b_justification j, bool decision) const { - std::ostream & out = *m_fparams.m_trace_stream; + SASSERT(m_manager.has_trace_stream()); + std::ostream & out = m_manager.trace_stream(); out << "[assign] "; display_literal(out, l); if (decision) diff --git a/src/smt/smt_internalizer.cpp b/src/smt/smt_internalizer.cpp index 0cfe5b1de..556222c33 100644 --- a/src/smt/smt_internalizer.cpp +++ b/src/smt/smt_internalizer.cpp @@ -952,10 +952,10 @@ namespace smt { tout << "is_true_eq: " << e->is_true_eq() << " in cg_table: " << m_cg_table.contains_ptr(e) << " is_cgr: " << e->is_cgr() << "\n"; }); -#ifndef SMTCOMP - if (m_fparams.m_trace_stream != NULL) - *m_fparams.m_trace_stream << "[attach-enode] #" << n->get_id() << " " << m_generation << "\n"; -#endif + + if (m_manager.has_trace_stream()) + m_manager.trace_stream() << "[attach-enode] #" << n->get_id() << " " << m_generation << "\n"; + return e; } diff --git a/src/smt/smt_quantifier.cpp b/src/smt/smt_quantifier.cpp index e6d81d3d2..14e63b982 100644 --- a/src/smt/smt_quantifier.cpp +++ b/src/smt/smt_quantifier.cpp @@ -45,13 +45,16 @@ namespace smt { m_wrapper(wrapper), m_context(ctx), m_params(p), - m_qi_queue(m_wrapper, ctx, p, p.m_trace_stream), + m_qi_queue(m_wrapper, ctx, p), m_qstat_gen(ctx.get_manager(), ctx.get_region()), m_plugin(plugin) { m_num_instances = 0; m_qi_queue.setup(); } + bool has_trace_stream() const { return m_context.get_manager().has_trace_stream(); } + std::ostream & trace_stream() { return m_context.get_manager().trace_stream(); } + quantifier_stat * get_stat(quantifier * q) const { return m_quantifier_stat.find(q); } @@ -112,8 +115,8 @@ namespace smt { get_stat(q)->update_max_generation(max_generation); fingerprint * f = m_context.add_fingerprint(q, q->get_id(), num_bindings, bindings); if (f) { - if (m_params.m_trace_stream != NULL) { - std::ostream & out = *m_params.m_trace_stream; + if (has_trace_stream()) { + std::ostream & out = trace_stream(); out << "[new-match] " << static_cast(f) << " #" << q->get_id(); for (unsigned i = 0; i < num_bindings; i++) { // I don't want to use mk_pp because it creates expressions for pretty printing. @@ -418,8 +421,8 @@ namespace smt { m_fparams = &(m_context->get_fparams()); ast_manager & m = m_context->get_manager(); - m_mam = mk_mam(*m_context, m_fparams->m_trace_stream); - m_lazy_mam = mk_mam(*m_context, m_fparams->m_trace_stream); + m_mam = mk_mam(*m_context); + m_lazy_mam = mk_mam(*m_context); m_model_finder = alloc(model_finder, m, m_context->get_simplifier()); m_model_checker = alloc(model_checker, m, *m_fparams, *(m_model_finder.get()));