3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 19:05:51 +00:00

reorganizing the code

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-10-23 22:14:35 -07:00
parent 9e299b88c4
commit 0a4446ae26
255 changed files with 17 additions and 17 deletions

1812
src/tactic/aig/aig.cpp Normal file

File diff suppressed because it is too large Load diff

85
src/tactic/aig/aig.h Normal file
View file

@ -0,0 +1,85 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
aig.h
Abstract:
And-inverted graphs
Author:
Leonardo (leonardo) 2011-05-13
Notes:
--*/
#ifndef _AIG_H_
#define _AIG_H_
#include"ast.h"
#include"tactic_exception.h"
class assertion_set;
class goal;
class aig_lit;
class aig_manager;
class aig_exception : public tactic_exception {
public:
aig_exception(char const * msg):tactic_exception(msg) {}
};
class aig_ref {
friend class aig_lit;
friend class aig_manager;
aig_manager * m_manager;
void * m_ref;
aig_ref(aig_manager & m, aig_lit const & l);
public:
aig_ref();
~aig_ref();
aig_ref & operator=(aig_ref const & r);
bool operator==(aig_ref const & r) const { return m_ref == r.m_ref; }
bool operator!=(aig_ref const & r) const { return m_ref != r.m_ref; }
};
class aig_manager {
struct imp;
imp * m_imp;
friend class aig_ref;
public:
// If default_gate_encoding == true, then
// ite(a, b, c) is encoded as (NOT a OR b) AND (a OR c)
// iff(a, b) is encoded as (NOT a OR b) AND (a OR NOT b)
//
// If default_gate_encoding == false, then
// ite(a, b, c) is encoded as (a AND b) OR (NOT a AND c)
// iff(a, b) is encoded as (a AND b) OR (NOT a AND NOT b)
aig_manager(ast_manager & m, unsigned long long max_memory = UINT64_MAX, bool default_gate_encoding = true);
~aig_manager();
void set_max_memory(unsigned long long max);
aig_ref mk_aig(expr * n);
aig_ref mk_aig(assertion_set const & s); // TODO delete
aig_ref mk_aig(goal const & g);
aig_ref mk_not(aig_ref const & r);
aig_ref mk_and(aig_ref const & r1, aig_ref const & r2);
aig_ref mk_or(aig_ref const & r1, aig_ref const & r2);
aig_ref mk_iff(aig_ref const & r1, aig_ref const & r2);
aig_ref mk_ite(aig_ref const & r1, aig_ref const & r2, aig_ref const & r3);
void max_sharing(aig_ref & r);
void to_formula(aig_ref const & r, assertion_set & s); // TODO delete
void to_formula(aig_ref const & r, expr_ref & result);
void to_formula(aig_ref const & r, goal & result);
void to_cnf(aig_ref const & r, goal & result);
void display(std::ostream & out, aig_ref const & r) const;
void display_smt2(std::ostream & out, aig_ref const & r) const;
unsigned get_num_aigs() const;
void cancel() { set_cancel(true); }
void reset_cancel() { set_cancel(false); }
void set_cancel(bool f);
};
#endif

View file

@ -0,0 +1,126 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
aig_tactic.cpp
Abstract:
Tactic for minimizing circuits using AIGs.
Author:
Leonardo (leonardo) 2011-10-24
Notes:
--*/
#include"tactical.h"
#include"aig.h"
class aig_manager;
class aig_tactic : public tactic {
unsigned long long m_max_memory;
bool m_aig_gate_encoding;
bool m_aig_per_assertion;
aig_manager * m_aig_manager;
struct mk_aig_manager {
aig_tactic & m_owner;
mk_aig_manager(aig_tactic & o, ast_manager & m):m_owner(o) {
aig_manager * mng = alloc(aig_manager, m, o.m_max_memory, o.m_aig_gate_encoding);
#pragma omp critical (aig_tactic)
{
m_owner.m_aig_manager = mng;
}
}
~mk_aig_manager() {
aig_manager * mng = m_owner.m_aig_manager;
#pragma omp critical (aig_tactic)
{
m_owner.m_aig_manager = 0;
}
dealloc(mng);
}
};
public:
aig_tactic(params_ref const & p = params_ref()):m_aig_manager(0) {
updt_params(p);
}
virtual tactic * translate(ast_manager & m) {
aig_tactic * t = alloc(aig_tactic);
t->m_max_memory = m_max_memory;
t->m_aig_gate_encoding = m_aig_gate_encoding;
t->m_aig_per_assertion = m_aig_per_assertion;
return t;
}
virtual void updt_params(params_ref const & p) {
m_max_memory = megabytes_to_bytes(p.get_uint(":max-memory", UINT_MAX));
m_aig_gate_encoding = p.get_bool(":aig-default-gate-encoding", true);
m_aig_per_assertion = p.get_bool(":aig-per-assertion", true);
}
virtual void collect_param_descrs(param_descrs & r) {
insert_max_memory(r);
r.insert(":aig-per-assertion", CPK_BOOL, "(default: true) process one assertion at a time.");
}
void operator()(goal_ref const & g) {
SASSERT(g->is_well_sorted());
tactic_report report("aig", *g);
mk_aig_manager mk(*this, g->m());
if (m_aig_per_assertion) {
unsigned size = g->size();
for (unsigned i = 0; i < size; i++) {
aig_ref r = m_aig_manager->mk_aig(g->form(i));
m_aig_manager->max_sharing(r);
expr_ref new_f(g->m());
m_aig_manager->to_formula(r, new_f);
g->update(i, new_f, 0, g->dep(i));
}
}
else {
fail_if_unsat_core_generation("aig", g);
aig_ref r = m_aig_manager->mk_aig(*(g.get()));
g->reset(); // save memory
m_aig_manager->max_sharing(r);
m_aig_manager->to_formula(r, *(g.get()));
}
SASSERT(g->is_well_sorted());
}
virtual void operator()(goal_ref const & g,
goal_ref_buffer & result,
model_converter_ref & mc,
proof_converter_ref & pc,
expr_dependency_ref & core) {
fail_if_proof_generation("aig", g);
mc = 0; pc = 0; core = 0;
operator()(g);
g->inc_depth();
result.push_back(g.get());
}
virtual void cleanup() {}
protected:
virtual void set_cancel(bool f) {
#pragma omp critical (aig_tactic)
{
if (m_aig_manager)
m_aig_manager->set_cancel(f);
}
}
};
tactic * mk_aig_tactic(params_ref const & p) {
return clean(alloc(aig_tactic, p));
}

View file

@ -0,0 +1,27 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
aig_tactic.h
Abstract:
Tactic for minimizing circuits using AIGs.
Author:
Leonardo (leonardo) 2011-10-24
Notes:
--*/
#ifndef _AIG_TACTIC_H_
#define _AIG_TACTIC_H_
#include"params.h"
class tactic;
tactic * mk_aig_tactic(params_ref const & p = params_ref());
#endif