3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 00:55:31 +00:00

other components

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-10-02 11:48:48 -07:00
parent e9eab22e5c
commit 68269c43a6
250 changed files with 70871 additions and 0 deletions

278
shell/datalog_frontend.cpp Normal file
View file

@ -0,0 +1,278 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
datalog_frontend.cpp
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2010-05-18.
Revision History:
--*/
#include<iostream>
#include<time.h>
#include<signal.h>
#include"stopwatch.h"
#include"front_end_params.h"
#include"datalog_parser.h"
#include"arith_decl_plugin.h"
#include"dl_compiler.h"
#include"dl_context.h"
#include"dl_mk_filter_rules.h"
#include"dl_finite_product_relation.h"
#include"datalog_frontend.h"
#include"timeout.h"
static stopwatch g_overall_time;
static stopwatch g_piece_timer;
static unsigned t_parsing = 0;
static datalog::context * g_ctx = 0;
static datalog::rule_set * g_orig_rules;
static datalog::instruction_block * g_code;
static datalog::execution_context * g_ectx;
static front_end_params * g_params;
datalog_params::datalog_params():
m_default_table("sparse")
{}
void datalog_params::register_params(ini_params& p) {
p.register_symbol_param("DEFAULT_TABLE", m_default_table, "Datalog engine: default table (sparse)");
}
static void display_statistics(
std::ostream& out,
datalog::context& ctx,
datalog::rule_set& orig_rules,
datalog::instruction_block& code,
datalog::execution_context& ex_ctx,
front_end_params& params,
bool verbose
)
{
g_piece_timer.stop();
unsigned t_other = static_cast<int>(g_piece_timer.get_seconds()*1000);
g_overall_time.stop();
code.process_all_costs();
{
params_ref p(ctx.get_params());
p.set_bool(":output-profile", true);
p.set_uint(":profile-milliseconds-threshold", 100);
ctx.updt_params(p);
out << "--------------\n";
out << "original rules\n";
orig_rules.display(out);
out << "---------------\n";
out << "generated rules\n";
ctx.display_rules(out);
out << "--------------\n";
out << "instructions \n";
code.display(ctx, out);
out << "--------------\n";
out << "big relations \n";
ex_ctx.report_big_relations(1000, out);
}
out << "--------------\n";
out << "relation sizes\n";
ctx.get_rmanager().display_relation_sizes(out);
if (verbose) {
out << "--------------\n";
out << "rules\n";
ctx.display_rules(out);
}
out << "Time: " << static_cast<int>(g_overall_time.get_seconds()*1000) << "ms\n";
out << "Parsing: " << t_parsing << "ms, other: " << t_other << "ms\n";
}
static void display_statistics() {
if (g_ctx) {
display_statistics(std::cout, *g_ctx, *g_orig_rules, *g_code, *g_ectx, *g_params, true);
}
}
static void on_timeout() {
display_statistics();
exit(0);
}
static void on_ctrl_c(int) {
signal (SIGINT, SIG_DFL);
display_statistics();
raise(SIGINT);
}
unsigned read_datalog(char const * file, datalog_params const& dl_params, front_end_params & front_end_params) {
IF_VERBOSE(1, verbose_stream() << "Z3 Datalog Engine\n";);
ast_manager m;
g_overall_time.start();
register_on_timeout_proc(on_timeout);
signal(SIGINT, on_ctrl_c);
params_ref params;
params.set_sym(":engine", symbol("datalog"));
params.set_sym(":default-table", dl_params.m_default_table);
datalog::context ctx(m, front_end_params, params);
size_t watermark = front_end_params.m_memory_high_watermark;
if (watermark == 0) {
memory::set_high_watermark(static_cast<size_t>(UINT_MAX));
}
datalog::relation_manager & rmgr = ctx.get_rmanager();
datalog::relation_plugin & inner_plg = *rmgr.get_relation_plugin(symbol("tr_hashtable"));
SASSERT(&inner_plg);
rmgr.register_plugin(alloc(datalog::finite_product_relation_plugin, inner_plg, rmgr));
g_piece_timer.reset();
g_piece_timer.start();
bool wpa_benchmark = datalog::is_directory(std::string(file));
if (wpa_benchmark) {
scoped_ptr<datalog::wpa_parser> parser = datalog::wpa_parser::create(ctx, m);
if (!parser->parse_directory(file)) {
std::cerr << "ERROR: failed to parse file\n";
return 1;
}
}
else {
scoped_ptr<datalog::parser> parser = datalog::parser::create(ctx, m);
if (!parser->parse_file(file)) {
std::cerr << "ERROR: failed to parse file\n";
return 1;
}
}
g_piece_timer.stop();
t_parsing = static_cast<int>(g_piece_timer.get_seconds()*1000);
IF_VERBOSE(1, verbose_stream() << "parsing finished\n";);
IF_VERBOSE(1, verbose_stream() << "running saturation...\n";);
g_piece_timer.reset();
g_piece_timer.start();
//all rules were added
ctx.close();
TRACE("dl_compiler", ctx.display(tout););
datalog::rule_set original_rules(ctx.get_rules());
datalog::decl_set original_predicates;
ctx.collect_predicates(original_predicates);
datalog::instruction_block rules_code;
datalog::instruction_block termination_code;
datalog::execution_context ex_ctx(ctx);
IF_VERBOSE(10, original_rules.display_deps(verbose_stream()););
g_ctx = &ctx;
g_orig_rules = &original_rules;
g_code = &rules_code;
g_ectx = &ex_ctx;
g_params = &front_end_params;
try {
g_piece_timer.reset();
g_piece_timer.start();
bool early_termination;
unsigned timeout = ctx.initial_restart_timeout();
if(timeout == 0) {
timeout = UINT_MAX;
}
do {
model_converter_ref mc; // ignored
proof_converter_ref pc; // ignored
ctx.transform_rules(mc, pc);
datalog::compiler::compile(ctx, ctx.get_rules(), rules_code, termination_code);
TRACE("dl_compiler", rules_code.display(ctx, tout););
rules_code.make_annotations(ex_ctx);
ex_ctx.set_timelimit(timeout);
SASSERT(!ex_ctx.should_terminate());
early_termination = !rules_code.perform(ex_ctx);
if(early_termination) {
IF_VERBOSE(10, ex_ctx.report_big_relations(1000, verbose_stream()););
if (memory::above_high_watermark()) {
throw out_of_memory_error();
}
}
ex_ctx.reset_timelimit();
TRUSTME( termination_code.perform(ex_ctx) );
ctx.saturation_was_run();
if (early_termination) {
IF_VERBOSE(1, verbose_stream() << "restarting saturation\n";);
uint64 new_timeout = static_cast<uint64>(timeout)*ctx.initial_restart_timeout();
if(new_timeout>UINT_MAX) {
timeout=UINT_MAX;
}
else {
timeout=static_cast<unsigned>(new_timeout);
}
rules_code.process_all_costs();
rules_code.reset();
termination_code.reset();
ex_ctx.reset();
ctx.reopen();
ctx.restrict_predicates(original_predicates);
ctx.replace_rules(original_rules);
ctx.close();
}
} while (early_termination);
TRACE("dl_compiler", ctx.display(tout);
rules_code.display(ctx, tout););
if (ctx.get_params().get_bool(":output-tuples", true)) {
ctx.display_output_facts(std::cout);
}
display_statistics(
std::cout,
ctx,
original_rules,
rules_code,
ex_ctx,
front_end_params,
false);
}
catch (out_of_memory_error) {
std::cout << "\n\nOUT OF MEMORY!\n\n";
display_statistics(
std::cout,
ctx,
original_rules,
rules_code,
ex_ctx,
front_end_params,
true);
return ERR_MEMOUT;
}
register_on_timeout_proc(0);
return 0;
}

32
shell/datalog_frontend.h Normal file
View file

@ -0,0 +1,32 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
datalog_frontend.h
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2010-05-18.
Revision History:
--*/
#ifndef _DATALOG_FRONTEND_H_
#define _DATALOG_FRONTEND_H_
struct datalog_params {
symbol m_default_table;
datalog_params();
virtual void register_params(ini_params& p);
};
unsigned read_datalog(char const * file, datalog_params const& dl_params, front_end_params & front_end_params);
#endif /* _DATALOG_FRONTEND_H_ */

106
shell/dimacs_frontend.cpp Normal file
View file

@ -0,0 +1,106 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
dimacs_frontend.cpp
Abstract:
Frontend for reading dimacs input files
Author:
Leonardo de Moura (leonardo) 2011-07-26.
Revision History:
--*/
#include<iostream>
#include<time.h>
#include<signal.h>
#include"timeout.h"
#include"dimacs.h"
#include"sat_solver.h"
#include"front_end_params.h"
extern bool g_display_statistics;
static sat::solver * g_solver = 0;
static clock_t g_start_time;
static void display_statistics() {
clock_t end_time = clock();
if (g_solver && g_display_statistics) {
std::cout.flush();
std::cerr.flush();
statistics st;
g_solver->collect_statistics(st);
st.update("total time", ((static_cast<double>(end_time) - static_cast<double>(g_start_time)) / CLOCKS_PER_SEC));
st.display_smt2(std::cout);
}
}
static void on_timeout() {
display_statistics();
exit(0);
}
static void on_ctrl_c(int) {
signal (SIGINT, SIG_DFL);
display_statistics();
raise(SIGINT);
}
static void display_model(sat::solver const & s) {
sat::model const & m = s.get_model();
for (unsigned i = 1; i < m.size(); i++) {
switch (m[i]) {
case l_false: std::cout << "-" << i << " "; break;
case l_undef: break;
case l_true: std::cout << i << " "; break;
}
}
std::cout << "\n";
}
unsigned read_dimacs(char const * file_name, front_end_params & front_end_params) {
g_start_time = clock();
register_on_timeout_proc(on_timeout);
signal(SIGINT, on_ctrl_c);
params_ref p;
p.set_bool(":produce-models", front_end_params.m_model);
sat::solver solver(p, 0);
g_solver = &solver;
if (file_name) {
std::ifstream in(file_name);
if (in.bad() || in.fail()) {
std::cerr << "(error \"failed to open file '" << file_name << "'\")" << std::endl;
exit(ERR_OPEN_FILE);
}
parse_dimacs(in, solver);
}
else {
parse_dimacs(std::cin, solver);
}
IF_VERBOSE(20, solver.display_status(verbose_stream()););
lbool r = solver.check();
switch (r) {
case l_true:
std::cout << "sat\n";
if (front_end_params.m_model)
display_model(solver);
break;
case l_undef:
std::cout << "unknown\n";
break;
case l_false:
std::cout << "unsat\n";
break;
}
if (g_display_statistics)
display_statistics();
return 0;
}

25
shell/dimacs_frontend.h Normal file
View file

@ -0,0 +1,25 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
dimacs_frontend.h
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2011-07-26.
Revision History:
--*/
#ifndef _DIMACS_FRONTEND_H_
#define _DIMACS_FRONTEND_H_
unsigned read_dimacs(char const * benchmark_file, front_end_params & front_end_params);
#endif /* _DATALOG_FRONTEND_H_ */

459
shell/main.cpp Normal file
View file

@ -0,0 +1,459 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
main.cpp
Abstract:
Z3 command line tool.
Author:
Leonardo de Moura (leonardo) 2006-10-10.
Nikolaj Bjorner (nbjorner)
Revision History:
--*/
#include<iostream>
#include"memory_manager.h"
#include"trace.h"
#include"debug.h"
#include"util.h"
#include"pp.h"
#include"smtlib_frontend.h"
#include"z3_log_frontend.h"
#include"warning.h"
#include"version.h"
#include"datalog_frontend.h"
#include"dimacs_frontend.h"
#include"timeout.h"
#include"z3_exception.h"
#include"error_codes.h"
typedef enum { IN_UNSPECIFIED, IN_SMTLIB, IN_SMTLIB_2, IN_DATALOG, IN_DIMACS, IN_Z3_LOG } input_kind;
std::string g_aux_input_file;
char const * g_input_file = 0;
bool g_standard_input = false;
input_kind g_input_kind = IN_UNSPECIFIED;
front_end_params * g_front_end_params = 0;
bool g_display_statistics = false;
bool g_display_istatistics = false;
#ifdef _WINDOWS
#define OPT "/"
#else
#define OPT "-"
#endif
void error(const char * msg) {
std::cerr << "Error: " << msg << "\n";
std::cerr << "For usage information: z3 " << OPT << "h\n";
exit(ERR_CMD_LINE);
}
void display_usage() {
std::cout << "Z3 [version " << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "]. (C) Copyright 2006 Microsoft Corp.\n";
std::cout << "Usage: z3 [options] [" << OPT << "file:]file\n";
std::cout << "\nInput format:\n";
std::cout << " " << OPT << "smt use parser for SMT input format.\n";
std::cout << " " << OPT << "smt2 use parser for SMT 2 input format.\n";
std::cout << " " << OPT << "dl use parser for Datalog input format.\n";
std::cout << " " << OPT << "dimacs use parser for DIMACS input format.\n";
std::cout << " " << OPT << "log use parser for Z3 log input format.\n";
std::cout << " " << OPT << "in read formula from standard input.\n";
std::cout << "\nMiscellaneous:\n";
std::cout << " " << OPT << "h, " << OPT << "? prints this message.\n";
std::cout << " " << OPT << "version prints version number of Z3.\n";
std::cout << " " << OPT << "v:level be verbose, where <level> is the verbosity level.\n";
std::cout << " " << OPT << "nw disable warning messages.\n";
std::cout << " " << OPT << "ini:file configuration file.\n";
std::cout << " " << OPT << "ini? display all available INI file parameters.\n";
std::cout << " --" << " all remaining arguments are assumed to be part of the input file name. This option allows Z3 to read files with strange names such as: -foo.smt2.\n";
std::cout << "\nResources:\n";
// timeout and memout are now available on Linux and OSX too.
std::cout << " " << OPT << "T:timeout set the timeout (in seconds).\n";
std::cout << " " << OPT << "t:timeout set the soft timeout (in seconds). It only kills the current query.\n";
std::cout << " " << OPT << "memory:Megabytes set a limit for virtual memory consumption.\n";
//
std::cout << "\nOutput:\n";
std::cout << " " << OPT << "st display statistics.\n";
std::cout << "\nSearch heuristics:\n";
std::cout << " " << OPT << "rs:num random seed.\n";
#if defined(Z3DEBUG) || defined(_TRACE)
std::cout << "\nDebugging support:\n";
#endif
#ifdef _TRACE
std::cout << " " << OPT << "tr:tag enable trace messages tagged with <tag>.\n";
#endif
#ifdef Z3DEBUG
std::cout << " " << OPT << "dbg:tag enable assertions tagged with <tag>.\n";
#endif
}
class extra_params : public datalog_params {
bool & m_statistics;
public:
extra_params():
m_statistics(g_display_statistics) {
}
virtual void register_params(ini_params & p) {
datalog_params::register_params(p);
p.register_bool_param("STATISTICS", m_statistics, "display statistics");
}
};
ini_params* g_params = 0;
extra_params* g_extra_params = 0;
bool g_params_initialized = false;
void init_params() {
if (!g_params_initialized) {
z3_bound_num_procs();
g_front_end_params = new front_end_params();
g_params = new ini_params();
g_extra_params = new extra_params();
register_verbosity_level(*g_params);
register_warning(*g_params);
register_pp_params(*g_params);
g_front_end_params->register_params(*g_params);
g_extra_params->register_params(*g_params);
g_params_initialized = true;
}
}
void del_params() {
if (g_front_end_params != NULL)
g_front_end_params->close_trace_file();
delete g_extra_params;
delete g_params;
delete g_front_end_params;
g_extra_params = 0;
g_params = 0;
g_front_end_params = 0;
}
void read_ini_file(const char * file_name) {
std::ifstream in(file_name);
if (in.bad() || in.fail()) {
std::cerr << "Error: failed to open init file \"" << file_name << "\".\n";
exit(ERR_INI_FILE);
}
g_params->read_ini_file(in);
}
void display_ini_help() {
g_params->display_params(std::cout);
}
void display_config() {
if (g_front_end_params->m_display_config) {
display_ini_help();
}
}
void display_ini_doc() {
g_params->display_params_documentation(std::cout);
}
void parse_cmd_line_args(int argc, char ** argv) {
int i = 1;
char * eq_pos = 0;
while (i < argc) {
char * arg = argv[i];
if (arg[0] == '-' && arg[1] == '-' && arg[2] == 0) {
// Little hack used to read files with strange names such as -foo.smt2
// z3 -- -foo.smt2
i++;
g_aux_input_file = "";
for (; i < argc; i++) {
g_aux_input_file += argv[i];
if (i < argc - 1)
g_aux_input_file += " ";
}
if (g_front_end_params->m_interactive) {
warning_msg("ignoring input file in interactive mode.");
}
else if (g_input_file) {
warning_msg("input file was already specified.");
}
else {
g_input_file = g_aux_input_file.c_str();
}
break;
}
if (arg[0] == '-'
#ifdef _WINDOWS
|| arg[0] == '/'
#endif
) {
char * opt_name = arg + 1;
char * opt_arg = 0;
char * colon = strchr(arg, ':');
if (colon) {
opt_arg = colon + 1;
*colon = 0;
}
if (strcmp(opt_name, "h") == 0 || strcmp(opt_name, "?") == 0 || strcmp(opt_name, "help") == 0) {
display_usage();
exit(0);
}
if (strcmp(opt_name, "version") == 0) {
#ifdef _EXTERNAL_RELEASE
std::cout << "Z3 version " << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "\n";
#else
std::cout
<< "Z3 version (major minor build revision): "
<< Z3_MAJOR_VERSION << " "
<< Z3_MINOR_VERSION << " "
<< Z3_BUILD_NUMBER << " "
<< Z3_REVISION_NUMBER << "\n";
#endif
exit(0);
}
else if (strcmp(opt_name, "smt") == 0) {
g_input_kind = IN_SMTLIB;
}
else if (strcmp(opt_name, "smt2") == 0) {
g_input_kind = IN_SMTLIB_2;
}
else if (strcmp(opt_name, "in") == 0) {
g_standard_input = true;
}
else if (strcmp(opt_name, "dimacs") == 0) {
g_input_kind = IN_DIMACS;
}
else if (strcmp(opt_name, "log") == 0) {
g_input_kind = IN_Z3_LOG;
}
else if (strcmp(opt_name, "st") == 0) {
g_display_statistics = true;
}
else if (strcmp(opt_name, "ist") == 0) {
g_display_istatistics = true;
}
else if (strcmp(opt_name, "v") == 0) {
if (!opt_arg)
error("option argument (/v:level) is missing.");
long lvl = strtol(opt_arg, 0, 10);
set_verbosity_level(lvl);
}
else if (strcmp(opt_name, "vldt") == 0) {
g_front_end_params->m_model_validate = true;
}
else if (strcmp(opt_name, "file") == 0) {
g_input_file = opt_arg;
}
else if (strcmp(opt_name, "r") == 0) {
if (!opt_arg) {
error("optional argument (/r:level) is missing.");
}
g_front_end_params->m_relevancy_lvl = strtol(opt_arg, 0, 10);
}
else if (strcmp(opt_name, "rd") == 0) {
if (!opt_arg) {
error("optional argument (/rd:num) is missing.");
}
g_front_end_params->m_random_var_freq = static_cast<double>(strtol(opt_arg, 0, 10)) / 100.0;
}
else if (strcmp(opt_name, "rs") == 0) {
if (!opt_arg) {
error("optional argument (/rs:num) is missing.");
}
long seed = strtol(opt_arg, 0, 10);
g_front_end_params->m_random_seed = seed;
g_front_end_params->m_arith_random_seed = seed;
}
else if (strcmp(opt_name, "T") == 0) {
if (!opt_arg)
error("option argument (/T:timeout) is missing.");
long tm = strtol(opt_arg, 0, 10);
set_timeout(tm * 1000);
}
else if (strcmp(opt_name, "t") == 0) {
if (!opt_arg)
error("option argument (/t:timeout) is missing.");
long tm = strtol(opt_arg, 0, 10);
g_front_end_params->m_soft_timeout = tm*1000;
}
else if (strcmp(opt_name, "nw") == 0) {
enable_warning_messages(false);
}
else if (strcmp(opt_name, "ini") == 0) {
if (!opt_arg)
error("option argument (/ini:file) is missing.");
read_ini_file(opt_arg);
}
else if (strcmp(opt_name, "ini?") == 0) {
display_ini_help();
exit(0);
}
else if (strcmp(opt_name, "geninidoc") == 0) {
display_ini_doc();
exit(0);
}
#ifdef _TRACE
else if (strcmp(opt_name, "tr") == 0) {
if (!opt_arg)
error("option argument (/tr:tag) is missing.");
enable_trace(opt_arg);
}
#endif
#ifdef Z3DEBUG
else if (strcmp(opt_name, "dbg") == 0) {
if (!opt_arg)
error("option argument (/dbg:tag) is missing.");
enable_debug(opt_arg);
}
#endif
else if (strcmp(opt_name, "memory") == 0) {
if (!opt_arg)
error("option argument (/memory:val) is missing.");
g_front_end_params->m_memory_high_watermark = strtoul(opt_arg, 0, 10);
}
else {
std::cerr << "Error: invalid command line option: " << arg << "\n";
std::cerr << "For usage information: z3 " << OPT << "h\n";
exit(ERR_CMD_LINE);
}
}
else if (argv[i][0] != '"' && (eq_pos = strchr(argv[i], '='))) {
char * key = argv[i];
*eq_pos = 0;
char * value = eq_pos+1;
g_params->set_param_value(key, value);
}
else {
if (g_front_end_params->m_interactive) {
warning_msg("ignoring input file in interactive mode.");
}
else if (g_input_file) {
warning_msg("input file was already specified.");
}
else {
g_input_file = arg;
}
}
i++;
}
}
char const * get_extension(char const * file_name) {
if (file_name == 0)
return 0;
char const * last_dot = 0;
for (;;) {
char const * tmp = strchr(file_name, '.');
if (tmp == 0) {
return last_dot;
}
last_dot = tmp + 1;
file_name = last_dot;
}
}
class global_state_initialiser {
public:
global_state_initialiser() {
memory::initialize(0);
#if defined(_WINDOWS) && defined(_Z3_BUILD_PARALLEL_SMT)
memory::mem->set_threaded_mode(true);
#endif
init_params();
}
void reset() {
del_params();
memory::finalize();
}
~global_state_initialiser() {
reset();
}
};
int main(int argc, char ** argv) {
try{
unsigned return_value = 0;
global_state_initialiser global_state;
memory::exit_when_out_of_memory(true, "ERROR: out of memory");
parse_cmd_line_args(argc, argv);
memory::set_high_watermark(static_cast<size_t>(g_front_end_params->m_memory_high_watermark) * 1024 * 1024);
memory::set_max_size(static_cast<size_t>(g_front_end_params->m_memory_max_size) * 1024 * 1024);
g_front_end_params->open_trace_file();
DEBUG_CODE(
if (g_front_end_params->m_copy_params != -1) {
g_front_end_params->copy_params(g_front_end_params->m_copy_params);
TRACE("copy_params", g_params->display_params(tout););
});
if (g_input_file && g_standard_input) {
error("using standard input to read formula.");
}
if (!g_input_file && !g_front_end_params->m_interactive && !g_standard_input) {
error("input file was not specified.");
}
if (g_input_kind == IN_UNSPECIFIED) {
g_input_kind = IN_SMTLIB;
char const * ext = get_extension(g_input_file);
if (ext) {
if (strcmp(ext, "datalog") == 0 || strcmp(ext, "dl") == 0) {
g_input_kind = IN_DATALOG;
}
else if (strcmp(ext, "dimacs") == 0 || strcmp(ext, "cnf") == 0) {
g_input_kind = IN_DIMACS;
}
else if (strcmp(ext, "log") == 0) {
g_input_kind = IN_Z3_LOG;
}
else if (strcmp(ext, "smt2") == 0) {
g_input_kind = IN_SMTLIB_2;
}
else if (strcmp(ext, "smt") == 0) {
g_input_kind = IN_SMTLIB;
}
}
}
switch (g_input_kind) {
case IN_SMTLIB:
return_value = read_smtlib_file(g_input_file, *g_front_end_params);
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);
break;
case IN_DIMACS:
return_value = read_dimacs(g_input_file, *g_front_end_params);
break;
case IN_DATALOG:
read_datalog(g_input_file, *g_extra_params, *g_front_end_params);
break;
case IN_Z3_LOG:
replay_z3_log(g_input_file);
break;
default:
UNREACHABLE();
}
global_state.reset();
#ifdef _WINDOWS
_CrtDumpMemoryLeaks();
#endif
return return_value;
}
catch (z3_exception & ex) {
// unhandled exception
std::cerr << "ERROR: " << ex.msg() << "\n";
if (ex.has_error_code())
return ex.error_code();
else
return ERR_INTERNAL_FATAL;
}
}

67
shell/options.h Normal file
View file

@ -0,0 +1,67 @@
/**
\page cmdline Command line options
\section informat Input format
Z3 understands a set of default file extensions, and will invoke a parser based on the extension.
- \ext{smt2} - <a href="http://www.smtlib.org">SMT-LIB 2</a> format, this is the preferred input format.
- \ext{dimacs}, \ext{cnf} - DIMACS format used by regular SAT solvers.
- \ext{dl} - Datalog input format.
- \ext{smt} - (deprecated) <a href="http://www.smtlib.org">SMT-LIB 1</a> format.
You can tell Z3 explicitly which grammar the input belongs to by using the following options:
\cmdopt{smt2} use parser for SMT-LIB 2.0 input format.
\cmdopt{dimacs} use dimacs parser to read the input file.
\section cmdlinemis Miscellaneous
\cmdopt{h\, ?} prints the help message.
\cmdopt{version} prints version number of Z3.
\cmdopt{v:level} be verbose, where <level> is the verbosity level.
\cmdopt{nw} disable warning messages.
\cmdopt{ini:file} configuration file.
Several parameters are available besides the ones listed by \ty{/h}.
These parameters can be loaded from an initialization file by using
this option.
\cmdopt{ini?} display all available INI file parameters.
The available \ref config can also be supplied on the command
line as a pair parameter-name=parameter-value.
\section cmdlineres Resources
\cmdopt{T:timeout} set the timeout (in seconds).
Setting this option causes the entire process to exit.
It is a reliable way to kill Z3.
\cmdopt{t:timeout} set the soft timeout (in seconds).
It only kills the current query.
\cmdopt{memory:Megabytes} set a limit for virtual memory consumption.
This limit for virtual memory consumption is approximate, but in
general a good guideline for controlling the memory consumption of Z3. If the
memory consumption exceeds the specified number of Megabytes, Z3 exits with a warning
message.
\section cmdlineout Output
\cmdopt{st} display statistics.
This option can be used to dump various statistics about the search,
such as number of splits, conflict clauses, and quantifier instantiations.
\section cmdlinesearch Search heuristics
\cmdopt{rs:num} random seed.
*/

14
shell/resource.h Normal file
View file

@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by shell.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

102
shell/shell.rc Normal file
View file

@ -0,0 +1,102 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,2,0,0
PRODUCTVERSION 4,2,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Microsoft"
VALUE "FileDescription", "Z3 shell"
VALUE "FileVersion" "4,2,0,0"
VALUE "InternalName", "Z3 shell"
VALUE "LegalCopyright", "(c) Microsoft Corporation. All rights reserved."
VALUE "OriginalFilename", "z3.exe"
VALUE "ProductName", "Z3"
VALUE "ProductVersion", "4,2,0,0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

1630
shell/shell.vcxproj Normal file

File diff suppressed because it is too large Load diff

3
shell/shell.vcxproj.user Normal file
View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

118
shell/simple_sat.cpp Normal file
View file

@ -0,0 +1,118 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
simple_sat.cpp
Abstract:
<abstract>
Author:
Leonardo de Moura (leonardo) 2006-10-10.
Revision History:
--*/
#include<fstream>
#include<time.h>
#include"front_end_params.h"
#include"sat_def.h"
#include"dimacs_parser.h"
#include"timeit.h"
#include"mem_stat.h"
class simple_sat_solver : public no_extension {
const front_end_params & m_params;
sat_solver<simple_sat_solver> * m_sat;
unsigned m_num_vars;
svector<lbool> m_model;
public:
simple_sat_solver(const front_end_params & p):
m_params(p),
m_sat(new sat_solver<simple_sat_solver>(*this, p)),
m_num_vars(0) {
}
~simple_sat_solver() {
delete m_sat;
}
static bool enable_ref_counters() {
return false;
}
void mk_var() {
m_sat->mk_var();
m_num_vars++;
}
void mk_clause(const literal_vector & lits) {
m_sat->mk_main_clause(lits);
}
unsigned get_num_vars() const {
return m_num_vars;
}
lbool check() {
return m_sat->check();
}
void mk_model() {
if (m_params.m_build_model) {
m_sat->save_assignment(m_model);
}
}
void display_model(std::ostream & out) const {
int sz = m_model.size();
for (int i = 1; i < sz; i++) {
if (m_model[i] == l_true) {
out << i << " ";
}
else if (m_model[i] == l_false) {
out << -i << " ";
}
}
out << "\n";
}
void display_statistics(std::ostream & out) const {
m_sat->display_statistics(out);
}
};
extern bool g_display_statistics;
extern front_end_params g_front_end_params;
void solve_cnf(const char * file) {
clock_t start_time = clock();
simple_sat_solver solver(g_front_end_params);
std::ifstream in(file);
parse_dimacs(in, solver);
lbool r = solver.check();
clock_t end_time = clock();
switch(r) {
case l_false:
std::cout << "unsat\n";
break;
case l_undef:
std::cout << "unknown\n";
break;
case l_true:
std::cout << "sat\n";
if (g_front_end_params.m_build_model) {
solver.display_model(std::cout);
}
break;
}
if (g_display_statistics) {
solver.display_statistics(std::cerr);
memory::display_max_usage(std::cerr);
std::cerr << "time: " << ((static_cast<double>(end_time) - static_cast<double>(start_time)) / CLOCKS_PER_SEC) << "\n";
}
}

26
shell/simple_sat.h Normal file
View file

@ -0,0 +1,26 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
simple_sat.h
Abstract:
Simple SAT solver using the Z3 SAT template.
Author:
Leonardo de Moura (leonardo) 2006-10-10.
Revision History:
--*/
#ifndef _SIMPLE_SAT_H_
#define _SIMPLE_SAT_H_
void solve_cnf(const char * file);
#endif /* _SIMPLE_SAT_H_ */

138
shell/smtlib_frontend.cpp Normal file
View file

@ -0,0 +1,138 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
smtlib_frontend.cpp
Abstract:
Frontend for reading Smtlib input files
Author:
Nikolaj Bjorner (nbjorner) 2006-11-3.
Revision History:
Leonardo de Moura: new SMT 2.0 front-end, removed support for .smtc files and smtcmd_solver object.
--*/
#include<iostream>
#include<time.h>
#include<signal.h>
#include"smtlib_solver.h"
#include"timeout.h"
#include"smt2parser.h"
#include"dl_cmds.h"
#include"dbg_cmds.h"
#include"polynomial_cmds.h"
#include"subpaving_cmds.h"
#include"smt_strategic_solver.h"
#include"tactic2solver.h"
#include"qfnra_nlsat_tactic.h"
extern bool g_display_statistics;
extern void display_config();
static clock_t g_start_time;
static smtlib::solver* g_solver = 0;
static cmd_context * g_cmd_context = 0;
static void display_statistics() {
display_config();
clock_t end_time = clock();
if ((g_solver || g_cmd_context) && g_display_statistics) {
std::cout.flush();
std::cerr.flush();
if (g_solver) {
g_solver->display_statistics();
memory::display_max_usage(std::cout);
std::cout << "time: " << ((static_cast<double>(end_time) - static_cast<double>(g_start_time)) / CLOCKS_PER_SEC) << " secs\n";
}
else if (g_cmd_context) {
g_cmd_context->set_regular_stream("stdout");
g_cmd_context->display_statistics(true, ((static_cast<double>(end_time) - static_cast<double>(g_start_time)) / CLOCKS_PER_SEC));
}
}
}
static void on_timeout() {
display_statistics();
exit(0);
}
static void on_ctrl_c(int) {
signal (SIGINT, SIG_DFL);
display_statistics();
raise(SIGINT);
}
unsigned read_smtlib_file(char const * benchmark_file, front_end_params & front_end_params) {
g_start_time = clock();
register_on_timeout_proc(on_timeout);
signal(SIGINT, on_ctrl_c);
smtlib::solver solver(front_end_params);
g_solver = &solver;
bool ok = true;
ok = solver.solve_smt(benchmark_file);
if (!ok) {
if (benchmark_file) {
std::cerr << "ERROR: solving '" << benchmark_file << "'.\n";
}
else {
std::cerr << "ERROR: solving input stream.\n";
}
}
display_statistics();
register_on_timeout_proc(0);
g_solver = 0;
return solver.get_error_code();
}
unsigned read_smtlib2_commands(char const* file_name, front_end_params& front_end_params) {
g_start_time = clock();
register_on_timeout_proc(on_timeout);
signal(SIGINT, on_ctrl_c);
cmd_context ctx(front_end_params);
// temporary hack until strategic_solver is ported to new tactic framework
if (front_end_params.m_nlsat) {
tactic2solver_cmd * s = alloc(tactic2solver_cmd);
s->set_tactic(alloc(qfnra_nlsat_fct));
ctx.set_solver(s);
}
else {
solver * s = mk_smt_strategic_solver(ctx);
ctx.set_solver(s);
}
install_dl_cmds(ctx);
install_dbg_cmds(ctx);
install_polynomial_cmds(ctx);
install_subpaving_cmds(ctx);
g_cmd_context = &ctx;
register_on_timeout_proc(on_timeout);
signal(SIGINT, on_ctrl_c);
bool result = true;
if (file_name) {
std::ifstream in(file_name);
if (in.bad() || in.fail()) {
std::cerr << "(error \"failed to open file '" << file_name << "'\")" << std::endl;
exit(ERR_OPEN_FILE);
}
result = parse_smt2_commands(ctx, in);
}
else {
result = parse_smt2_commands(ctx, std::cin, true);
}
display_statistics();
g_cmd_context = 0;
return result ? 0 : 1;
}

35
shell/smtlib_frontend.h Normal file
View file

@ -0,0 +1,35 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
smtlib_frontend.h
Abstract:
Smtlib frontend.
Author:
Leonardo de Moura (leonardo) 2006-11-2.
Revision History:
--*/
#ifndef _SMTLIB_FRONTEND_H_
#define _SMTLIB_FRONTEND_H_
#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
#endif /* _SMTLIB_FRONTEND_H_ */

56
shell/z3_log_frontend.cpp Normal file
View file

@ -0,0 +1,56 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
z3_log_frontend.cpp
Abstract:
Z3 log frontend.
Replay a log generated by Z3
Author:
Leonardo de Moura (leonardo) 2011-09-26.
Revision History:
--*/
#include<iostream>
#include<fstream>
#include<time.h>
#include"util.h"
#include"error_codes.h"
#include"z3_replayer.h"
static void solve(char const * stream_name, std::istream & in) {
clock_t start_time = clock();
z3_replayer r(in);
try {
r.parse();
}
catch (z3_exception & ex) {
std::cerr << "Error at line " << r.get_line() << ": " << ex.msg() << std::endl;
}
clock_t end_time = clock();
memory::display_max_usage(std::cout);
std::cout << "time: " << ((static_cast<double>(end_time) - static_cast<double>(start_time)) / CLOCKS_PER_SEC) << "\n";
}
void replay_z3_log(char const * file_name) {
if (!file_name) {
solve(file_name, std::cin);
}
else {
std::ifstream in(file_name);
if (in.bad() || in.fail()) {
std::cerr << "Error: failed to open file \"" << file_name << "\".\n";
exit(ERR_OPEN_FILE);
}
solve(file_name, in);
}
exit(0);
}

27
shell/z3_log_frontend.h Normal file
View file

@ -0,0 +1,27 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
z3_log_frontend.h
Abstract:
Z3 log frontend.
Replay a log generated by Z3
Author:
Leonardo de Moura (leonardo) 2011-09-26.
Revision History:
--*/
#ifndef _Z3_LOG_FRONTEND_H_
#define _Z3_LOG_FRONTEND_H_
void replay_z3_log(char const * benchmark_file);
#endif /* _Z3_FRONTEND_H_ */