2013-06-07 06:59:13 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-06-07 06:59:13 -05:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-06-07 06:59:13 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
// [[CITE]] Temporal Induction by Incremental SAT Solving
|
|
|
|
// Niklas Een and Niklas Sörensson (2003)
|
|
|
|
// http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.8161
|
|
|
|
|
2013-06-07 06:59:13 -05:00
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/celltypes.h"
|
2013-06-13 12:51:13 -05:00
|
|
|
#include "kernel/consteval.h"
|
2013-06-07 06:59:13 -05:00
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include "kernel/satgen.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <algorithm>
|
2014-02-17 05:06:04 -06:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2013-06-07 06:59:13 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
2013-06-13 12:51:13 -05:00
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
struct SatHelper
|
|
|
|
{
|
|
|
|
RTLIL::Design *design;
|
|
|
|
RTLIL::Module *module;
|
|
|
|
|
|
|
|
SigMap sigmap;
|
|
|
|
CellTypes ct;
|
2015-02-21 05:15:41 -06:00
|
|
|
|
|
|
|
ezSatPtr ez;
|
2013-06-09 08:49:32 -05:00
|
|
|
SatGen satgen;
|
|
|
|
|
|
|
|
// additional constraints
|
2013-12-28 04:24:36 -06:00
|
|
|
std::vector<std::pair<std::string, std::string>> sets, prove, prove_x, sets_init;
|
2013-06-09 08:49:32 -05:00
|
|
|
std::map<int, std::vector<std::pair<std::string, std::string>>> sets_at;
|
|
|
|
std::map<int, std::vector<std::string>> unsets_at;
|
2015-02-26 11:47:39 -06:00
|
|
|
bool prove_asserts, set_assumes;
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2013-11-25 14:40:00 -06:00
|
|
|
// undef constraints
|
2014-02-06 09:15:23 -06:00
|
|
|
bool enable_undef, set_init_def, set_init_undef, set_init_zero, ignore_unknown_cells;
|
2013-12-27 06:02:46 -06:00
|
|
|
std::vector<std::string> sets_def, sets_any_undef, sets_all_undef;
|
|
|
|
std::map<int, std::vector<std::string>> sets_def_at, sets_any_undef_at, sets_all_undef_at;
|
2013-11-25 14:40:00 -06:00
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
// model variables
|
|
|
|
std::vector<std::string> shows;
|
|
|
|
SigPool show_signal_pool;
|
|
|
|
SigSet<RTLIL::Cell*> show_drivers;
|
2013-06-20 05:49:10 -05:00
|
|
|
int max_timestep, timeout;
|
|
|
|
bool gotTimeout;
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
SatHelper(RTLIL::Design *design, RTLIL::Module *module, bool enable_undef) :
|
2015-02-21 05:15:41 -06:00
|
|
|
design(design), module(module), sigmap(module), ct(design), satgen(ez.get(), &sigmap)
|
2013-06-09 08:49:32 -05:00
|
|
|
{
|
2013-12-07 10:28:51 -06:00
|
|
|
this->enable_undef = enable_undef;
|
|
|
|
satgen.model_undef = enable_undef;
|
2014-02-06 09:15:23 -06:00
|
|
|
set_init_def = false;
|
2013-12-07 10:28:51 -06:00
|
|
|
set_init_undef = false;
|
2014-02-05 18:40:01 -06:00
|
|
|
set_init_zero = false;
|
2014-02-03 09:26:10 -06:00
|
|
|
ignore_unknown_cells = false;
|
2013-06-09 08:49:32 -05:00
|
|
|
max_timestep = -1;
|
2013-06-20 05:49:10 -05:00
|
|
|
timeout = 0;
|
|
|
|
gotTimeout = false;
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
void check_undef_enabled(const RTLIL::SigSpec &sig)
|
|
|
|
{
|
|
|
|
if (enable_undef)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<RTLIL::SigBit> sigbits = sig.to_sigbit_vector();
|
|
|
|
for (size_t i = 0; i < sigbits.size(); i++)
|
|
|
|
if (sigbits[i].wire == NULL && sigbits[i].data == RTLIL::State::Sx)
|
|
|
|
log_cmd_error("Bit %d of %s is undef but option -enable_undef is missing!\n", int(i), log_signal(sig));
|
|
|
|
}
|
|
|
|
|
2016-07-23 10:01:03 -05:00
|
|
|
void setup(int timestep = -1, bool initstate = false)
|
2013-06-09 08:49:32 -05:00
|
|
|
{
|
|
|
|
if (timestep > 0)
|
|
|
|
log ("\nSetting up time step %d:\n", timestep);
|
|
|
|
else
|
|
|
|
log ("\nSetting up SAT problem:\n");
|
|
|
|
|
2016-07-24 05:18:39 -05:00
|
|
|
if (initstate)
|
|
|
|
satgen.setInitState(timestep);
|
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
if (timestep > max_timestep)
|
|
|
|
max_timestep = timestep;
|
|
|
|
|
|
|
|
RTLIL::SigSpec big_lhs, big_rhs;
|
|
|
|
|
|
|
|
for (auto &s : sets)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs, rhs;
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(lhs, design, module, s.first))
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str());
|
2013-11-09 05:02:27 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second))
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Failed to parse rhs set expression `%s'.\n", s.second.c_str());
|
|
|
|
show_signal_pool.add(sigmap(lhs));
|
|
|
|
show_signal_pool.add(sigmap(rhs));
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (lhs.size() != rhs.size())
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Set expression with different lhs and rhs sizes: %s (%s, %d bits) vs. %s (%s, %d bits)\n",
|
2014-07-22 13:15:14 -05:00
|
|
|
s.first.c_str(), log_signal(lhs), lhs.size(), s.second.c_str(), log_signal(rhs), rhs.size());
|
2013-06-09 08:49:32 -05:00
|
|
|
|
|
|
|
log("Import set-constraint: %s = %s\n", log_signal(lhs), log_signal(rhs));
|
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
big_lhs.append(lhs);
|
|
|
|
big_rhs.append(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_at[timestep])
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs, rhs;
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(lhs, design, module, s.first))
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str());
|
2013-11-09 05:02:27 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second))
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Failed to parse rhs set expression `%s'.\n", s.second.c_str());
|
|
|
|
show_signal_pool.add(sigmap(lhs));
|
|
|
|
show_signal_pool.add(sigmap(rhs));
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (lhs.size() != rhs.size())
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Set expression with different lhs and rhs sizes: %s (%s, %d bits) vs. %s (%s, %d bits)\n",
|
2014-07-22 13:15:14 -05:00
|
|
|
s.first.c_str(), log_signal(lhs), lhs.size(), s.second.c_str(), log_signal(rhs), rhs.size());
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2014-03-13 07:12:49 -05:00
|
|
|
log("Import set-constraint for this timestep: %s = %s\n", log_signal(lhs), log_signal(rhs));
|
2013-06-09 08:49:32 -05:00
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
big_lhs.append(lhs);
|
|
|
|
big_rhs.append(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : unsets_at[timestep])
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs;
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(lhs, design, module, s))
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.c_str());
|
|
|
|
show_signal_pool.add(sigmap(lhs));
|
|
|
|
|
2014-03-13 07:12:49 -05:00
|
|
|
log("Import unset-constraint for this timestep: %s\n", log_signal(lhs));
|
2013-06-09 08:49:32 -05:00
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
log("Final constraint equation: %s = %s\n", log_signal(big_lhs), log_signal(big_rhs));
|
2013-12-07 10:28:51 -06:00
|
|
|
check_undef_enabled(big_lhs), check_undef_enabled(big_rhs);
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->assume(satgen.signals_eq(big_lhs, big_rhs, timestep));
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2013-12-27 06:27:21 -06:00
|
|
|
// 0 = sets_def
|
|
|
|
// 1 = sets_any_undef
|
|
|
|
// 2 = sets_all_undef
|
|
|
|
std::set<RTLIL::SigSpec> sets_def_undef[3];
|
|
|
|
|
|
|
|
for (auto &s : sets_def) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-12-27 06:27:21 -06:00
|
|
|
log_cmd_error("Failed to parse set-def expression `%s'.\n", s.c_str());
|
|
|
|
sets_def_undef[0].insert(sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_any_undef) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-12-27 06:27:21 -06:00
|
|
|
log_cmd_error("Failed to parse set-def expression `%s'.\n", s.c_str());
|
|
|
|
sets_def_undef[1].insert(sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_all_undef) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-12-27 06:27:21 -06:00
|
|
|
log_cmd_error("Failed to parse set-def expression `%s'.\n", s.c_str());
|
|
|
|
sets_def_undef[2].insert(sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_def_at[timestep]) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-12-27 06:27:21 -06:00
|
|
|
log_cmd_error("Failed to parse set-def expression `%s'.\n", s.c_str());
|
|
|
|
sets_def_undef[0].insert(sig);
|
|
|
|
sets_def_undef[1].erase(sig);
|
|
|
|
sets_def_undef[2].erase(sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_any_undef_at[timestep]) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-12-27 06:27:21 -06:00
|
|
|
log_cmd_error("Failed to parse set-def expression `%s'.\n", s.c_str());
|
|
|
|
sets_def_undef[0].erase(sig);
|
|
|
|
sets_def_undef[1].insert(sig);
|
|
|
|
sets_def_undef[2].erase(sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_all_undef_at[timestep]) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-12-27 06:27:21 -06:00
|
|
|
log_cmd_error("Failed to parse set-def expression `%s'.\n", s.c_str());
|
|
|
|
sets_def_undef[0].erase(sig);
|
|
|
|
sets_def_undef[1].erase(sig);
|
|
|
|
sets_def_undef[2].insert(sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int t = 0; t < 3; t++)
|
|
|
|
for (auto &sig : sets_def_undef[t]) {
|
2014-03-13 07:12:49 -05:00
|
|
|
log("Import %s constraint for this timestep: %s\n", t == 0 ? "def" : t == 1 ? "any_undef" : "all_undef", log_signal(sig));
|
2013-12-27 06:27:21 -06:00
|
|
|
std::vector<int> undef_sig = satgen.importUndefSigSpec(sig, timestep);
|
|
|
|
if (t == 0)
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->assume(ez->NOT(ez->expression(ezSAT::OpOr, undef_sig)));
|
2013-12-27 06:27:21 -06:00
|
|
|
if (t == 1)
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->assume(ez->expression(ezSAT::OpOr, undef_sig));
|
2013-12-27 06:27:21 -06:00
|
|
|
if (t == 2)
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->assume(ez->expression(ezSAT::OpAnd, undef_sig));
|
2013-12-27 06:27:21 -06:00
|
|
|
}
|
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
int import_cell_counter = 0;
|
2015-02-26 11:47:39 -06:00
|
|
|
for (auto cell : module->cells())
|
|
|
|
if (design->selected(module, cell)) {
|
|
|
|
// log("Import cell: %s\n", RTLIL::id2cstr(cell->name));
|
|
|
|
if (satgen.importCell(cell, timestep)) {
|
|
|
|
for (auto &p : cell->connections())
|
|
|
|
if (ct.cell_output(cell->type, p.first))
|
|
|
|
show_drivers.insert(sigmap(p.second), cell);
|
2013-06-09 08:49:32 -05:00
|
|
|
import_cell_counter++;
|
2014-02-03 09:26:10 -06:00
|
|
|
} else if (ignore_unknown_cells)
|
2015-02-26 11:47:39 -06:00
|
|
|
log_warning("Failed to import cell %s (type %s) to SAT database.\n", RTLIL::id2cstr(cell->name), RTLIL::id2cstr(cell->type));
|
2014-02-03 09:26:10 -06:00
|
|
|
else
|
2015-02-26 11:47:39 -06:00
|
|
|
log_error("Failed to import cell %s (type %s) to SAT database.\n", RTLIL::id2cstr(cell->name), RTLIL::id2cstr(cell->type));
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
log("Imported %d cells to SAT database.\n", import_cell_counter);
|
2015-02-26 11:47:39 -06:00
|
|
|
|
|
|
|
if (set_assumes) {
|
|
|
|
RTLIL::SigSpec assumes_a, assumes_en;
|
|
|
|
satgen.getAssumes(assumes_a, assumes_en, timestep);
|
|
|
|
for (int i = 0; i < GetSize(assumes_a); i++)
|
|
|
|
log("Import constraint from assume cell: %s when %s.\n", log_signal(assumes_a[i]), log_signal(assumes_en[i]));
|
|
|
|
ez->assume(satgen.importAssumes(timestep));
|
|
|
|
}
|
2016-07-23 10:01:03 -05:00
|
|
|
|
|
|
|
if (initstate)
|
2016-07-24 05:18:39 -05:00
|
|
|
{
|
|
|
|
RTLIL::SigSpec big_lhs, big_rhs;
|
|
|
|
|
|
|
|
for (auto &it : module->wires_)
|
|
|
|
{
|
|
|
|
if (it.second->attributes.count("\\init") == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
RTLIL::SigSpec lhs = sigmap(it.second);
|
|
|
|
RTLIL::SigSpec rhs = it.second->attributes.at("\\init");
|
|
|
|
log_assert(lhs.size() == rhs.size());
|
|
|
|
|
|
|
|
RTLIL::SigSpec removed_bits;
|
|
|
|
for (int i = 0; i < lhs.size(); i++) {
|
|
|
|
RTLIL::SigSpec bit = lhs.extract(i, 1);
|
2019-10-08 14:41:24 -05:00
|
|
|
if (rhs[i] == State::Sx || !satgen.initial_state.check_all(bit)) {
|
2019-12-11 13:27:10 -06:00
|
|
|
if (rhs[i] != State::Sx)
|
|
|
|
removed_bits.append(bit);
|
2016-07-24 05:18:39 -05:00
|
|
|
lhs.remove(i, 1);
|
|
|
|
rhs.remove(i, 1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removed_bits.size())
|
|
|
|
log_warning("ignoring initial value on non-register: %s\n", log_signal(removed_bits));
|
|
|
|
|
|
|
|
if (lhs.size()) {
|
|
|
|
log("Import set-constraint from init attribute: %s = %s\n", log_signal(lhs), log_signal(rhs));
|
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
big_lhs.append(lhs);
|
|
|
|
big_rhs.append(rhs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &s : sets_init)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs, rhs;
|
|
|
|
|
|
|
|
if (!RTLIL::SigSpec::parse_sel(lhs, design, module, s.first))
|
|
|
|
log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str());
|
|
|
|
if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second))
|
|
|
|
log_cmd_error("Failed to parse rhs set expression `%s'.\n", s.second.c_str());
|
|
|
|
show_signal_pool.add(sigmap(lhs));
|
|
|
|
show_signal_pool.add(sigmap(rhs));
|
|
|
|
|
|
|
|
if (lhs.size() != rhs.size())
|
|
|
|
log_cmd_error("Set expression with different lhs and rhs sizes: %s (%s, %d bits) vs. %s (%s, %d bits)\n",
|
|
|
|
s.first.c_str(), log_signal(lhs), lhs.size(), s.second.c_str(), log_signal(rhs), rhs.size());
|
|
|
|
|
|
|
|
log("Import init set-constraint: %s = %s\n", log_signal(lhs), log_signal(rhs));
|
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
big_lhs.append(lhs);
|
|
|
|
big_rhs.append(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!satgen.initial_state.check_all(big_lhs)) {
|
|
|
|
RTLIL::SigSpec rem = satgen.initial_state.remove(big_lhs);
|
|
|
|
log_cmd_error("Found -set-init bits that are not part of the initial_state: %s\n", log_signal(rem));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_init_def) {
|
|
|
|
RTLIL::SigSpec rem = satgen.initial_state.export_all();
|
|
|
|
std::vector<int> undef_rem = satgen.importUndefSigSpec(rem, 1);
|
|
|
|
ez->assume(ez->NOT(ez->expression(ezSAT::OpOr, undef_rem)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_init_undef) {
|
|
|
|
RTLIL::SigSpec rem = satgen.initial_state.export_all();
|
|
|
|
rem.remove(big_lhs);
|
|
|
|
big_lhs.append(rem);
|
|
|
|
big_rhs.append(RTLIL::SigSpec(RTLIL::State::Sx, rem.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_init_zero) {
|
|
|
|
RTLIL::SigSpec rem = satgen.initial_state.export_all();
|
|
|
|
rem.remove(big_lhs);
|
|
|
|
big_lhs.append(rem);
|
|
|
|
big_rhs.append(RTLIL::SigSpec(RTLIL::State::S0, rem.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (big_lhs.size() == 0) {
|
|
|
|
log("No constraints for initial state found.\n\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log("Final init constraint equation: %s = %s\n", log_signal(big_lhs), log_signal(big_rhs));
|
|
|
|
check_undef_enabled(big_lhs), check_undef_enabled(big_rhs);
|
|
|
|
ez->assume(satgen.signals_eq(big_lhs, big_rhs, timestep));
|
|
|
|
}
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
int setup_proof(int timestep = -1)
|
2013-06-09 09:30:37 -05:00
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(prove.size() || prove_x.size() || prove_asserts);
|
2013-06-09 09:30:37 -05:00
|
|
|
|
|
|
|
RTLIL::SigSpec big_lhs, big_rhs;
|
2013-12-28 04:24:36 -06:00
|
|
|
std::vector<int> prove_bits;
|
2013-06-09 09:30:37 -05:00
|
|
|
|
2013-12-28 04:24:36 -06:00
|
|
|
if (prove.size() > 0)
|
2013-06-09 09:30:37 -05:00
|
|
|
{
|
2013-12-28 04:24:36 -06:00
|
|
|
for (auto &s : prove)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs, rhs;
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(lhs, design, module, s.first))
|
2013-12-28 04:24:36 -06:00
|
|
|
log_cmd_error("Failed to parse lhs proof expression `%s'.\n", s.first.c_str());
|
|
|
|
if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second))
|
|
|
|
log_cmd_error("Failed to parse rhs proof expression `%s'.\n", s.second.c_str());
|
|
|
|
show_signal_pool.add(sigmap(lhs));
|
|
|
|
show_signal_pool.add(sigmap(rhs));
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (lhs.size() != rhs.size())
|
2013-12-28 04:24:36 -06:00
|
|
|
log_cmd_error("Proof expression with different lhs and rhs sizes: %s (%s, %d bits) vs. %s (%s, %d bits)\n",
|
2014-07-22 13:15:14 -05:00
|
|
|
s.first.c_str(), log_signal(lhs), lhs.size(), s.second.c_str(), log_signal(rhs), rhs.size());
|
2013-12-28 04:24:36 -06:00
|
|
|
|
|
|
|
log("Import proof-constraint: %s = %s\n", log_signal(lhs), log_signal(rhs));
|
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
big_lhs.append(lhs);
|
|
|
|
big_rhs.append(rhs);
|
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
|
2013-12-28 04:24:36 -06:00
|
|
|
log("Final proof equation: %s = %s\n", log_signal(big_lhs), log_signal(big_rhs));
|
|
|
|
check_undef_enabled(big_lhs), check_undef_enabled(big_rhs);
|
|
|
|
prove_bits.push_back(satgen.signals_eq(big_lhs, big_rhs, timestep));
|
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
|
2013-12-28 04:24:36 -06:00
|
|
|
if (prove_x.size() > 0)
|
|
|
|
{
|
|
|
|
for (auto &s : prove_x)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs, rhs;
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(lhs, design, module, s.first))
|
2013-12-28 04:24:36 -06:00
|
|
|
log_cmd_error("Failed to parse lhs proof-x expression `%s'.\n", s.first.c_str());
|
|
|
|
if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second))
|
|
|
|
log_cmd_error("Failed to parse rhs proof-x expression `%s'.\n", s.second.c_str());
|
|
|
|
show_signal_pool.add(sigmap(lhs));
|
|
|
|
show_signal_pool.add(sigmap(rhs));
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (lhs.size() != rhs.size())
|
2013-12-28 04:24:36 -06:00
|
|
|
log_cmd_error("Proof-x expression with different lhs and rhs sizes: %s (%s, %d bits) vs. %s (%s, %d bits)\n",
|
2014-07-22 13:15:14 -05:00
|
|
|
s.first.c_str(), log_signal(lhs), lhs.size(), s.second.c_str(), log_signal(rhs), rhs.size());
|
2013-12-28 04:24:36 -06:00
|
|
|
|
|
|
|
log("Import proof-x-constraint: %s = %s\n", log_signal(lhs), log_signal(rhs));
|
|
|
|
big_lhs.remove2(lhs, &big_rhs);
|
|
|
|
big_lhs.append(lhs);
|
|
|
|
big_rhs.append(rhs);
|
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
|
2013-12-28 04:24:36 -06:00
|
|
|
log("Final proof-x equation: %s = %s\n", log_signal(big_lhs), log_signal(big_rhs));
|
|
|
|
|
|
|
|
std::vector<int> value_lhs = satgen.importDefSigSpec(big_lhs, timestep);
|
|
|
|
std::vector<int> value_rhs = satgen.importDefSigSpec(big_rhs, timestep);
|
|
|
|
|
|
|
|
std::vector<int> undef_lhs = satgen.importUndefSigSpec(big_lhs, timestep);
|
|
|
|
std::vector<int> undef_rhs = satgen.importUndefSigSpec(big_rhs, timestep);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < value_lhs.size(); i++)
|
2015-02-21 05:15:41 -06:00
|
|
|
prove_bits.push_back(ez->OR(undef_lhs.at(i), ez->AND(ez->NOT(undef_rhs.at(i)), ez->NOT(ez->XOR(value_lhs.at(i), value_rhs.at(i))))));
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
|
|
|
|
2014-02-04 05:46:16 -06:00
|
|
|
if (prove_asserts) {
|
|
|
|
RTLIL::SigSpec asserts_a, asserts_en;
|
|
|
|
satgen.getAsserts(asserts_a, asserts_en, timestep);
|
2014-10-10 09:59:44 -05:00
|
|
|
for (int i = 0; i < GetSize(asserts_a); i++)
|
2014-07-23 09:09:27 -05:00
|
|
|
log("Import proof for assert: %s when %s.\n", log_signal(asserts_a[i]), log_signal(asserts_en[i]));
|
2014-01-19 08:38:23 -06:00
|
|
|
prove_bits.push_back(satgen.importAsserts(timestep));
|
2014-02-04 05:46:16 -06:00
|
|
|
}
|
2014-01-19 08:38:23 -06:00
|
|
|
|
2015-02-21 05:15:41 -06:00
|
|
|
return ez->expression(ezSAT::OpAnd, prove_bits);
|
2013-06-09 11:07:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void force_unique_state(int timestep_from, int timestep_to)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec state_signals = satgen.initial_state.export_all();
|
|
|
|
for (int i = timestep_from; i < timestep_to; i++)
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->assume(ez->NOT(satgen.signals_eq(state_signals, state_signals, i, timestep_to)));
|
2013-06-09 11:07:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool solve(const std::vector<int> &assumptions)
|
|
|
|
{
|
2013-06-20 05:49:10 -05:00
|
|
|
log_assert(gotTimeout == false);
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->setSolverTimeout(timeout);
|
|
|
|
bool success = ez->solve(modelExpressions, modelValues, assumptions);
|
|
|
|
if (ez->getSolverTimoutStatus())
|
2013-06-20 05:49:10 -05:00
|
|
|
gotTimeout = true;
|
|
|
|
return success;
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
bool solve(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0)
|
2013-06-09 08:49:32 -05:00
|
|
|
{
|
2013-06-20 05:49:10 -05:00
|
|
|
log_assert(gotTimeout == false);
|
2015-02-21 05:15:41 -06:00
|
|
|
ez->setSolverTimeout(timeout);
|
|
|
|
bool success = ez->solve(modelExpressions, modelValues, a, b, c, d, e, f);
|
|
|
|
if (ez->getSolverTimoutStatus())
|
2013-06-20 05:49:10 -05:00
|
|
|
gotTimeout = true;
|
|
|
|
return success;
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ModelBlockInfo {
|
|
|
|
int timestep, offset, width;
|
|
|
|
std::string description;
|
|
|
|
bool operator < (const ModelBlockInfo &other) const {
|
|
|
|
if (timestep != other.timestep)
|
|
|
|
return timestep < other.timestep;
|
|
|
|
if (description != other.description)
|
|
|
|
return description < other.description;
|
|
|
|
if (offset != other.offset)
|
|
|
|
return offset < other.offset;
|
|
|
|
if (width != other.width)
|
|
|
|
return width < other.width;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<int> modelExpressions;
|
|
|
|
std::vector<bool> modelValues;
|
|
|
|
std::set<ModelBlockInfo> modelInfo;
|
|
|
|
|
2013-12-07 16:58:55 -06:00
|
|
|
void maximize_undefs()
|
|
|
|
{
|
|
|
|
log_assert(enable_undef);
|
|
|
|
std::vector<bool> backupValues;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
std::vector<int> must_undef, maybe_undef;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < modelExpressions.size()/2; i++)
|
|
|
|
if (modelValues.at(modelExpressions.size()/2 + i))
|
|
|
|
must_undef.push_back(modelExpressions.at(modelExpressions.size()/2 + i));
|
|
|
|
else
|
|
|
|
maybe_undef.push_back(modelExpressions.at(modelExpressions.size()/2 + i));
|
|
|
|
|
|
|
|
backupValues.swap(modelValues);
|
2015-02-21 05:15:41 -06:00
|
|
|
if (!solve(ez->expression(ezSAT::OpAnd, must_undef), ez->expression(ezSAT::OpOr, maybe_undef)))
|
2013-12-07 16:58:55 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
backupValues.swap(modelValues);
|
|
|
|
}
|
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
void generate_model()
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec modelSig;
|
2013-06-09 11:07:05 -05:00
|
|
|
modelExpressions.clear();
|
|
|
|
modelInfo.clear();
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
// Add "show" signals or alternatively the leaves on the input cone on all set and prove signals
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
if (shows.size() == 0)
|
|
|
|
{
|
|
|
|
SigPool queued_signals, handled_signals, final_signals;
|
|
|
|
queued_signals = show_signal_pool;
|
|
|
|
while (queued_signals.size() > 0) {
|
|
|
|
RTLIL::SigSpec sig = queued_signals.export_one();
|
|
|
|
queued_signals.del(sig);
|
2013-06-09 08:49:32 -05:00
|
|
|
handled_signals.add(sig);
|
|
|
|
std::set<RTLIL::Cell*> drivers = show_drivers.find(sig);
|
|
|
|
if (drivers.size() == 0) {
|
|
|
|
final_signals.add(sig);
|
|
|
|
} else {
|
|
|
|
for (auto &d : drivers)
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &p : d->connections()) {
|
2013-06-09 11:07:05 -05:00
|
|
|
if (d->type == "$dff" && p.first == "\\CLK")
|
|
|
|
continue;
|
2019-08-07 14:20:08 -05:00
|
|
|
if (d->type.begins_with("$_DFF_") && p.first == "\\C")
|
2013-06-09 11:07:05 -05:00
|
|
|
continue;
|
2013-06-10 09:09:29 -05:00
|
|
|
queued_signals.add(handled_signals.remove(sigmap(p.second)));
|
2013-06-09 11:07:05 -05:00
|
|
|
}
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
modelSig = final_signals.export_all();
|
2013-06-09 11:07:05 -05:00
|
|
|
|
|
|
|
// additionally add all set and prove signals directly
|
|
|
|
// (it improves user confidence if we write the constraints back ;-)
|
|
|
|
modelSig.append(show_signal_pool.export_all());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-09 08:49:32 -05:00
|
|
|
for (auto &s : shows) {
|
|
|
|
RTLIL::SigSpec sig;
|
2014-02-06 12:22:46 -06:00
|
|
|
if (!RTLIL::SigSpec::parse_sel(sig, design, module, s))
|
2013-06-09 08:49:32 -05:00
|
|
|
log_cmd_error("Failed to parse show expression `%s'.\n", s.c_str());
|
|
|
|
log("Import show expression: %s\n", log_signal(sig));
|
|
|
|
modelSig.append(sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
modelSig.sort_and_unify();
|
|
|
|
// log("Model signals: %s\n", log_signal(modelSig));
|
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
std::vector<int> modelUndefExpressions;
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
for (auto &c : modelSig.chunks())
|
2013-12-07 10:28:51 -06:00
|
|
|
if (c.wire != NULL)
|
|
|
|
{
|
2013-06-09 08:49:32 -05:00
|
|
|
ModelBlockInfo info;
|
|
|
|
RTLIL::SigSpec chunksig = c;
|
2014-07-22 13:15:14 -05:00
|
|
|
info.width = chunksig.size();
|
2013-06-09 08:49:32 -05:00
|
|
|
info.description = log_signal(chunksig);
|
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
for (int timestep = -1; timestep <= max_timestep; timestep++)
|
|
|
|
{
|
2013-06-09 08:49:32 -05:00
|
|
|
if ((timestep == -1 && max_timestep > 0) || timestep == 0)
|
|
|
|
continue;
|
2013-12-07 10:28:51 -06:00
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
info.timestep = timestep;
|
|
|
|
info.offset = modelExpressions.size();
|
|
|
|
modelInfo.insert(info);
|
2013-12-07 10:28:51 -06:00
|
|
|
|
|
|
|
std::vector<int> vec = satgen.importSigSpec(chunksig, timestep);
|
|
|
|
modelExpressions.insert(modelExpressions.end(), vec.begin(), vec.end());
|
|
|
|
|
|
|
|
if (enable_undef) {
|
|
|
|
std::vector<int> undef_vec = satgen.importUndefSigSpec(chunksig, timestep);
|
|
|
|
modelUndefExpressions.insert(modelUndefExpressions.end(), undef_vec.begin(), undef_vec.end());
|
|
|
|
}
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
// Add initial state signals as collected by satgen
|
|
|
|
//
|
2013-06-09 11:07:05 -05:00
|
|
|
modelSig = satgen.initial_state.export_all();
|
2014-07-22 13:15:14 -05:00
|
|
|
for (auto &c : modelSig.chunks())
|
2013-12-07 10:28:51 -06:00
|
|
|
if (c.wire != NULL)
|
|
|
|
{
|
2013-06-09 08:49:32 -05:00
|
|
|
ModelBlockInfo info;
|
|
|
|
RTLIL::SigSpec chunksig = c;
|
2013-12-07 10:28:51 -06:00
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
info.timestep = 0;
|
|
|
|
info.offset = modelExpressions.size();
|
2014-07-22 13:15:14 -05:00
|
|
|
info.width = chunksig.size();
|
2013-06-09 08:49:32 -05:00
|
|
|
info.description = log_signal(chunksig);
|
2013-12-07 10:28:51 -06:00
|
|
|
modelInfo.insert(info);
|
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
std::vector<int> vec = satgen.importSigSpec(chunksig, 1);
|
|
|
|
modelExpressions.insert(modelExpressions.end(), vec.begin(), vec.end());
|
2013-12-07 10:28:51 -06:00
|
|
|
|
|
|
|
if (enable_undef) {
|
|
|
|
std::vector<int> undef_vec = satgen.importUndefSigSpec(chunksig, 1);
|
|
|
|
modelUndefExpressions.insert(modelUndefExpressions.end(), undef_vec.begin(), undef_vec.end());
|
|
|
|
}
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
2013-12-07 10:28:51 -06:00
|
|
|
|
|
|
|
modelExpressions.insert(modelExpressions.end(), modelUndefExpressions.begin(), modelUndefExpressions.end());
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_model()
|
|
|
|
{
|
|
|
|
int maxModelName = 10;
|
|
|
|
int maxModelWidth = 10;
|
|
|
|
|
|
|
|
for (auto &info : modelInfo) {
|
2015-10-25 13:30:49 -05:00
|
|
|
maxModelName = max(maxModelName, int(info.description.size()));
|
|
|
|
maxModelWidth = max(maxModelWidth, info.width);
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
log("\n");
|
|
|
|
|
|
|
|
int last_timestep = -2;
|
|
|
|
for (auto &info : modelInfo)
|
|
|
|
{
|
|
|
|
RTLIL::Const value;
|
2013-12-07 10:28:51 -06:00
|
|
|
bool found_undef = false;
|
|
|
|
|
2013-06-09 08:49:32 -05:00
|
|
|
for (int i = 0; i < info.width; i++) {
|
|
|
|
value.bits.push_back(modelValues.at(info.offset+i) ? RTLIL::State::S1 : RTLIL::State::S0);
|
2013-12-07 10:28:51 -06:00
|
|
|
if (enable_undef && modelValues.at(modelExpressions.size()/2 + info.offset + i))
|
|
|
|
value.bits.back() = RTLIL::State::Sx, found_undef = true;
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info.timestep != last_timestep) {
|
|
|
|
const char *hline = "---------------------------------------------------------------------------------------------------"
|
|
|
|
"---------------------------------------------------------------------------------------------------"
|
|
|
|
"---------------------------------------------------------------------------------------------------";
|
|
|
|
if (last_timestep == -2) {
|
|
|
|
log(max_timestep > 0 ? " Time " : " ");
|
2016-04-05 01:26:10 -05:00
|
|
|
log("%-*s %11s %9s %*s\n", maxModelName+5, "Signal Name", "Dec", "Hex", maxModelWidth+3, "Bin");
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
log(max_timestep > 0 ? " ---- " : " ");
|
2016-04-05 01:26:10 -05:00
|
|
|
log("%*.*s %11.11s %9.9s %*.*s\n", maxModelName+5, maxModelName+5,
|
|
|
|
hline, hline, hline, maxModelWidth+3, maxModelWidth+3, hline);
|
2013-06-09 08:49:32 -05:00
|
|
|
last_timestep = info.timestep;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_timestep > 0) {
|
|
|
|
if (info.timestep > 0)
|
|
|
|
log(" %4d ", info.timestep);
|
|
|
|
else
|
|
|
|
log(" init ");
|
|
|
|
} else
|
|
|
|
log(" ");
|
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
if (info.width <= 32 && !found_undef)
|
2016-04-05 01:26:10 -05:00
|
|
|
log("%-*s %11d %9x %*s\n", maxModelName+5, info.description.c_str(), value.as_int(), value.as_int(), maxModelWidth+3, value.as_string().c_str());
|
2013-06-09 08:49:32 -05:00
|
|
|
else
|
2016-04-05 01:26:10 -05:00
|
|
|
log("%-*s %11s %9s %*s\n", maxModelName+5, info.description.c_str(), "--", "--", maxModelWidth+3, value.as_string().c_str());
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (last_timestep == -2)
|
|
|
|
log(" no model variables selected for display.\n");
|
|
|
|
}
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
void dump_model_to_vcd(std::string vcd_file_name)
|
|
|
|
{
|
2019-06-20 12:27:59 -05:00
|
|
|
rewrite_filename(vcd_file_name);
|
2014-02-18 02:28:05 -06:00
|
|
|
FILE *f = fopen(vcd_file_name.c_str(), "w");
|
|
|
|
if (!f)
|
2014-02-17 05:06:04 -06:00
|
|
|
log_cmd_error("Can't open output file `%s' for writing: %s\n", vcd_file_name.c_str(), strerror(errno));
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
log("Dumping SAT model to VCD file %s\n", vcd_file_name.c_str());
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
time_t timestamp;
|
|
|
|
struct tm* now;
|
2014-02-18 02:28:05 -06:00
|
|
|
char stime[128] = {};
|
2014-02-17 05:06:04 -06:00
|
|
|
time(×tamp);
|
|
|
|
now = localtime(×tamp);
|
|
|
|
strftime(stime, sizeof(stime), "%c", now);
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
std::string module_fname = "unknown";
|
|
|
|
auto apos = module->attributes.find("\\src");
|
|
|
|
if(apos != module->attributes.end())
|
|
|
|
module_fname = module->attributes["\\src"].decode_string();
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
fprintf(f, "$date\n");
|
|
|
|
fprintf(f, " %s\n", stime);
|
|
|
|
fprintf(f, "$end\n");
|
|
|
|
fprintf(f, "$version\n");
|
2015-02-19 03:53:40 -06:00
|
|
|
fprintf(f, " Generated by %s\n", yosys_version_str);
|
2014-02-17 05:06:04 -06:00
|
|
|
fprintf(f, "$end\n");
|
|
|
|
fprintf(f, "$comment\n");
|
|
|
|
fprintf(f, " Generated from SAT problem in module %s (declared at %s)\n",
|
|
|
|
module->name.c_str(), module_fname.c_str());
|
|
|
|
fprintf(f, "$end\n");
|
2014-02-18 02:28:05 -06:00
|
|
|
|
|
|
|
// VCD has some limits on internal (non-display) identifier names, so make legal ones
|
2014-02-17 05:06:04 -06:00
|
|
|
std::map<std::string, std::string> vcdnames;
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
fprintf(f, "$scope module %s $end\n", module->name.c_str());
|
2014-02-18 02:28:05 -06:00
|
|
|
for (auto &info : modelInfo)
|
|
|
|
{
|
|
|
|
if (vcdnames.find(info.description) != vcdnames.end())
|
2014-02-17 05:06:04 -06:00
|
|
|
continue;
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
char namebuf[16];
|
|
|
|
snprintf(namebuf, sizeof(namebuf), "v%d", static_cast<int>(vcdnames.size()));
|
|
|
|
vcdnames[info.description] = namebuf;
|
2014-02-18 02:28:05 -06:00
|
|
|
|
|
|
|
// Even display identifiers can't use some special characters
|
2014-02-17 05:06:04 -06:00
|
|
|
std::string legal_desc = info.description.c_str();
|
|
|
|
for (auto &c : legal_desc) {
|
|
|
|
if(c == '$')
|
|
|
|
c = '_';
|
|
|
|
if(c == ':')
|
|
|
|
c = '_';
|
|
|
|
}
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
fprintf(f, "$var wire %d %s %s $end\n", info.width, namebuf, legal_desc.c_str());
|
2014-02-18 02:28:05 -06:00
|
|
|
|
|
|
|
// Need to look at first *two* cycles!
|
|
|
|
// We need to put a name on all variables but those without an initialization clause
|
|
|
|
// have no value at timestep 0
|
2014-02-17 05:06:04 -06:00
|
|
|
if(info.timestep > 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf(f, "$upscope $end\n");
|
|
|
|
fprintf(f, "$enddefinitions $end\n");
|
|
|
|
fprintf(f, "$dumpvars\n");
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
static const char bitvals[] = "01xzxx";
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
int last_timestep = -2;
|
|
|
|
for (auto &info : modelInfo)
|
|
|
|
{
|
|
|
|
RTLIL::Const value;
|
|
|
|
|
|
|
|
for (int i = 0; i < info.width; i++) {
|
|
|
|
value.bits.push_back(modelValues.at(info.offset+i) ? RTLIL::State::S1 : RTLIL::State::S0);
|
|
|
|
if (enable_undef && modelValues.at(modelExpressions.size()/2 + info.offset + i))
|
|
|
|
value.bits.back() = RTLIL::State::Sx;
|
|
|
|
}
|
2014-02-18 02:28:05 -06:00
|
|
|
|
|
|
|
if (info.timestep != last_timestep) {
|
2014-02-17 05:06:04 -06:00
|
|
|
if(last_timestep == 0)
|
|
|
|
fprintf(f, "$end\n");
|
|
|
|
else
|
|
|
|
fprintf(f, "#%d\n", info.timestep);
|
|
|
|
last_timestep = info.timestep;
|
|
|
|
}
|
2014-02-18 02:28:05 -06:00
|
|
|
|
|
|
|
if(info.width == 1) {
|
2014-02-17 05:06:04 -06:00
|
|
|
fprintf(f, "%c%s\n", bitvals[value.bits[0]], vcdnames[info.description].c_str());
|
2014-02-18 02:28:05 -06:00
|
|
|
} else {
|
2014-02-17 05:06:04 -06:00
|
|
|
fprintf(f, "b");
|
|
|
|
for(int k=info.width-1; k >= 0; k --) //need to flip bit ordering for VCD
|
|
|
|
fprintf(f, "%c", bitvals[value.bits[k]]);
|
|
|
|
fprintf(f, " %s\n", vcdnames[info.description].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_timestep == -2)
|
|
|
|
log(" no model variables selected for display.\n");
|
2014-02-18 02:28:05 -06:00
|
|
|
|
2014-02-17 05:06:04 -06:00
|
|
|
fclose(f);
|
|
|
|
}
|
2013-06-09 08:49:32 -05:00
|
|
|
|
2015-02-19 03:53:40 -06:00
|
|
|
void dump_model_to_json(std::string json_file_name)
|
|
|
|
{
|
2019-06-20 12:27:59 -05:00
|
|
|
rewrite_filename(json_file_name);
|
2015-02-19 03:53:40 -06:00
|
|
|
FILE *f = fopen(json_file_name.c_str(), "w");
|
|
|
|
if (!f)
|
|
|
|
log_cmd_error("Can't open output file `%s' for writing: %s\n", json_file_name.c_str(), strerror(errno));
|
|
|
|
|
|
|
|
log("Dumping SAT model to WaveJSON file '%s'.\n", json_file_name.c_str());
|
|
|
|
|
|
|
|
int mintime = 1, maxtime = 0, maxwidth = 0;;
|
|
|
|
dict<string, pair<int, dict<int, Const>>> wavedata;
|
|
|
|
|
|
|
|
for (auto &info : modelInfo)
|
|
|
|
{
|
|
|
|
Const value;
|
|
|
|
for (int i = 0; i < info.width; i++) {
|
|
|
|
value.bits.push_back(modelValues.at(info.offset+i) ? RTLIL::State::S1 : RTLIL::State::S0);
|
|
|
|
if (enable_undef && modelValues.at(modelExpressions.size()/2 + info.offset + i))
|
|
|
|
value.bits.back() = RTLIL::State::Sx;
|
|
|
|
}
|
|
|
|
|
|
|
|
wavedata[info.description].first = info.width;
|
|
|
|
wavedata[info.description].second[info.timestep] = value;
|
2015-10-25 13:30:49 -05:00
|
|
|
mintime = min(mintime, info.timestep);
|
|
|
|
maxtime = max(maxtime, info.timestep);
|
|
|
|
maxwidth = max(maxwidth, info.width);
|
2015-02-19 03:53:40 -06:00
|
|
|
}
|
|
|
|
|
2015-02-19 06:19:04 -06:00
|
|
|
fprintf(f, "{ \"signal\": [");
|
|
|
|
bool fist_wavedata = true;
|
|
|
|
for (auto &wd : wavedata)
|
|
|
|
{
|
|
|
|
fprintf(f, "%s", fist_wavedata ? "\n" : ",\n");
|
|
|
|
fist_wavedata = false;
|
|
|
|
|
2015-02-19 03:53:40 -06:00
|
|
|
vector<string> data;
|
|
|
|
string name = wd.first.c_str();
|
2019-08-07 14:20:08 -05:00
|
|
|
while (name.compare(0, 1, "\\") == 0)
|
2015-02-19 03:53:40 -06:00
|
|
|
name = name.substr(1);
|
2015-02-19 06:19:04 -06:00
|
|
|
|
|
|
|
fprintf(f, " { \"name\": \"%s\", \"wave\": \"", name.c_str());
|
2015-02-19 03:53:40 -06:00
|
|
|
for (int i = mintime; i <= maxtime; i++) {
|
|
|
|
if (wd.second.second.count(i)) {
|
|
|
|
string this_data = wd.second.second[i].as_string();
|
|
|
|
char ch = '=';
|
|
|
|
if (wd.second.first == 1)
|
|
|
|
ch = this_data[0];
|
|
|
|
if (!data.empty() && data.back() == this_data) {
|
|
|
|
fprintf(f, ".");
|
|
|
|
} else {
|
|
|
|
data.push_back(this_data);
|
|
|
|
fprintf(f, "%c", ch);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data.push_back("");
|
|
|
|
fprintf(f, "4");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wd.second.first != 1) {
|
2015-02-19 06:19:04 -06:00
|
|
|
fprintf(f, "\", \"data\": [");
|
2015-02-19 03:53:40 -06:00
|
|
|
for (int i = 0; i < GetSize(data); i++)
|
2015-02-19 06:19:04 -06:00
|
|
|
fprintf(f, "%s\"%s\"", i ? ", " : "", data[i].c_str());
|
|
|
|
fprintf(f, "] }");
|
2015-02-19 03:53:40 -06:00
|
|
|
} else {
|
2015-02-19 06:19:04 -06:00
|
|
|
fprintf(f, "\" }");
|
2015-02-19 03:53:40 -06:00
|
|
|
}
|
|
|
|
}
|
2015-02-19 06:19:04 -06:00
|
|
|
fprintf(f, "\n ],\n");
|
|
|
|
fprintf(f, " \"config\": {\n");
|
|
|
|
fprintf(f, " \"hscale\": %.2f\n", maxwidth / 4.0);
|
|
|
|
fprintf(f, " }\n");
|
2015-02-19 03:53:40 -06:00
|
|
|
fprintf(f, "}\n");
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2013-12-07 16:58:55 -06:00
|
|
|
void invalidate_model(bool max_undef)
|
2013-06-09 08:49:32 -05:00
|
|
|
{
|
|
|
|
std::vector<int> clause;
|
2013-12-07 10:28:51 -06:00
|
|
|
if (enable_undef) {
|
|
|
|
for (size_t i = 0; i < modelExpressions.size()/2; i++) {
|
|
|
|
int bit = modelExpressions.at(i), bit_undef = modelExpressions.at(modelExpressions.size()/2 + i);
|
|
|
|
bool val = modelValues.at(i), val_undef = modelValues.at(modelExpressions.size()/2 + i);
|
2013-12-07 16:58:55 -06:00
|
|
|
if (!max_undef || !val_undef)
|
2015-02-21 05:15:41 -06:00
|
|
|
clause.push_back(val_undef ? ez->NOT(bit_undef) : val ? ez->NOT(bit) : bit);
|
2013-12-07 10:28:51 -06:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
for (size_t i = 0; i < modelExpressions.size(); i++)
|
2015-02-21 05:15:41 -06:00
|
|
|
clause.push_back(modelValues.at(i) ? ez->NOT(modelExpressions.at(i)) : modelExpressions.at(i));
|
|
|
|
ez->assume(ez->expression(ezSAT::OpOr, clause));
|
2013-06-09 08:49:32 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void print_proof_failed()
|
2013-06-09 11:07:05 -05:00
|
|
|
{
|
|
|
|
log("\n");
|
|
|
|
log(" ______ ___ ___ _ _ _ _ \n");
|
|
|
|
log(" (_____ \\ / __) / __) (_) | | | |\n");
|
|
|
|
log(" _____) )___ ___ ___ _| |__ _| |__ _____ _| | _____ __| | |\n");
|
|
|
|
log(" | ____/ ___) _ \\ / _ (_ __) (_ __|____ | | || ___ |/ _ |_|\n");
|
|
|
|
log(" | | | | | |_| | |_| || | | | / ___ | | || ____( (_| |_ \n");
|
|
|
|
log(" |_| |_| \\___/ \\___/ |_| |_| \\_____|_|\\_)_____)\\____|_|\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void print_timeout()
|
2013-06-20 05:49:10 -05:00
|
|
|
{
|
|
|
|
log("\n");
|
|
|
|
log(" _____ _ _ _____ ____ _ _____\n");
|
|
|
|
log(" /__ __\\/ \\/ \\__/|/ __// _ \\/ \\ /\\/__ __\\\n");
|
|
|
|
log(" / \\ | || |\\/||| \\ | / \\|| | || / \\\n");
|
|
|
|
log(" | | | || | ||| /_ | \\_/|| \\_/| | |\n");
|
|
|
|
log(" \\_/ \\_/\\_/ \\|\\____\\\\____/\\____/ \\_/\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
void print_qed()
|
2013-06-09 11:07:05 -05:00
|
|
|
{
|
|
|
|
log("\n");
|
|
|
|
log(" /$$$$$$ /$$$$$$$$ /$$$$$$$ \n");
|
|
|
|
log(" /$$__ $$ | $$_____/ | $$__ $$ \n");
|
|
|
|
log(" | $$ \\ $$ | $$ | $$ \\ $$ \n");
|
|
|
|
log(" | $$ | $$ | $$$$$ | $$ | $$ \n");
|
|
|
|
log(" | $$ | $$ | $$__/ | $$ | $$ \n");
|
|
|
|
log(" | $$/$$ $$ | $$ | $$ | $$ \n");
|
|
|
|
log(" | $$$$$$/ /$$| $$$$$$$$ /$$| $$$$$$$//$$\n");
|
|
|
|
log(" \\____ $$$|__/|________/|__/|_______/|__/\n");
|
|
|
|
log(" \\__/ \n");
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
|
2013-06-09 14:55:53 -05:00
|
|
|
struct SatPass : public Pass {
|
|
|
|
SatPass() : Pass("sat", "solve a SAT problem in the circuit") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void help() YS_OVERRIDE
|
2013-06-07 06:59:13 -05:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2013-06-09 14:55:53 -05:00
|
|
|
log(" sat [options] [selection]\n");
|
2013-06-07 06:59:13 -05:00
|
|
|
log("\n");
|
|
|
|
log("This command solves a SAT problem defined over the currently selected circuit\n");
|
|
|
|
log("and additional constraints passed as parameters.\n");
|
|
|
|
log("\n");
|
2013-06-08 05:17:30 -05:00
|
|
|
log(" -all\n");
|
|
|
|
log(" show all solutions to the problem (this can grow exponentially, use\n");
|
|
|
|
log(" -max <N> instead to get <N> solutions)\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -max <N>\n");
|
|
|
|
log(" like -all, but limit number of solutions to <N>\n");
|
|
|
|
log("\n");
|
2013-11-25 14:40:00 -06:00
|
|
|
log(" -enable_undef\n");
|
|
|
|
log(" enable modeling of undef value (aka 'x-bits')\n");
|
|
|
|
log(" this option is implied by -set-def, -set-undef et. cetera\n");
|
|
|
|
log("\n");
|
2013-12-07 16:58:55 -06:00
|
|
|
log(" -max_undef\n");
|
|
|
|
log(" maximize the number of undef bits in solutions, giving a better\n");
|
|
|
|
log(" picture of which input bits are actually vital to the solution.\n");
|
|
|
|
log("\n");
|
2013-06-07 06:59:13 -05:00
|
|
|
log(" -set <signal> <value>\n");
|
|
|
|
log(" set the specified signal to the specified value.\n");
|
|
|
|
log("\n");
|
2013-11-25 14:40:00 -06:00
|
|
|
log(" -set-def <signal>\n");
|
|
|
|
log(" add a constraint that all bits of the given signal must be defined\n");
|
|
|
|
log("\n");
|
2013-12-27 06:02:46 -06:00
|
|
|
log(" -set-any-undef <signal>\n");
|
2013-11-25 14:40:00 -06:00
|
|
|
log(" add a constraint that at least one bit of the given signal is undefined\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -set-all-undef <signal>\n");
|
|
|
|
log(" add a constraint that all bits of the given signal are undefined\n");
|
|
|
|
log("\n");
|
2013-12-28 04:24:36 -06:00
|
|
|
log(" -set-def-inputs\n");
|
|
|
|
log(" add -set-def constraints for all module inputs\n");
|
|
|
|
log("\n");
|
2013-06-08 08:36:32 -05:00
|
|
|
log(" -show <signal>\n");
|
2013-06-08 02:34:36 -05:00
|
|
|
log(" show the model for the specified signal. if no -show option is\n");
|
|
|
|
log(" passed then a set of signals to be shown is automatically selected.\n");
|
2013-06-07 06:59:13 -05:00
|
|
|
log("\n");
|
2015-01-27 17:04:28 -06:00
|
|
|
log(" -show-inputs, -show-outputs, -show-ports\n");
|
|
|
|
log(" add all module (input/output) ports to the list of shown signals\n");
|
2014-02-01 15:52:44 -06:00
|
|
|
log("\n");
|
2015-08-18 10:14:30 -05:00
|
|
|
log(" -show-regs, -show-public, -show-all\n");
|
|
|
|
log(" show all registers, show signals with 'public' names, show all signals\n");
|
|
|
|
log("\n");
|
2013-08-15 04:40:01 -05:00
|
|
|
log(" -ignore_div_by_zero\n");
|
|
|
|
log(" ignore all solutions that involve a division by zero\n");
|
|
|
|
log("\n");
|
2014-02-03 09:26:10 -06:00
|
|
|
log(" -ignore_unknown_cells\n");
|
|
|
|
log(" ignore all cells that can not be matched to a SAT model\n");
|
|
|
|
log("\n");
|
2013-06-09 06:35:46 -05:00
|
|
|
log("The following options can be used to set up a sequential problem:\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -seq <N>\n");
|
|
|
|
log(" set up a sequential problem with <N> time steps. The steps will\n");
|
|
|
|
log(" be numbered from 1 to N.\n");
|
|
|
|
log("\n");
|
2015-02-21 15:03:54 -06:00
|
|
|
log(" note: for large <N> it can be significantly faster to use\n");
|
|
|
|
log(" -tempinduct-baseonly -maxsteps <N> instead of -seq <N>.\n");
|
|
|
|
log("\n");
|
2013-06-09 06:35:46 -05:00
|
|
|
log(" -set-at <N> <signal> <value>\n");
|
|
|
|
log(" -unset-at <N> <signal>\n");
|
|
|
|
log(" set or unset the specified signal to the specified value in the\n");
|
|
|
|
log(" given timestep. this has priority over a -set for the same signal.\n");
|
|
|
|
log("\n");
|
2015-02-26 11:47:39 -06:00
|
|
|
log(" -set-assumes\n");
|
|
|
|
log(" set all assumptions provided via $assume cells\n");
|
|
|
|
log("\n");
|
2013-12-27 06:02:46 -06:00
|
|
|
log(" -set-def-at <N> <signal>\n");
|
|
|
|
log(" -set-any-undef-at <N> <signal>\n");
|
|
|
|
log(" -set-all-undef-at <N> <signal>\n");
|
2014-09-06 01:47:06 -05:00
|
|
|
log(" add undef constraints in the given timestep.\n");
|
2013-11-25 14:40:00 -06:00
|
|
|
log("\n");
|
2013-12-07 10:28:51 -06:00
|
|
|
log(" -set-init <signal> <value>\n");
|
|
|
|
log(" set the initial value for the register driving the signal to the value\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -set-init-undef\n");
|
|
|
|
log(" set all initial states (not set using -set-init) to undef\n");
|
|
|
|
log("\n");
|
2014-02-06 09:15:23 -06:00
|
|
|
log(" -set-init-def\n");
|
|
|
|
log(" do not force a value for the initial state but do not allow undef\n");
|
|
|
|
log("\n");
|
2014-02-05 18:40:01 -06:00
|
|
|
log(" -set-init-zero\n");
|
|
|
|
log(" set all initial states (not set using -set-init) to zero\n");
|
|
|
|
log("\n");
|
2014-02-17 06:57:14 -06:00
|
|
|
log(" -dump_vcd <vcd-file-name>\n");
|
|
|
|
log(" dump SAT model (counter example in proof) to VCD file\n");
|
|
|
|
log("\n");
|
2015-02-19 03:53:40 -06:00
|
|
|
log(" -dump_json <json-file-name>\n");
|
|
|
|
log(" dump SAT model (counter example in proof) to a WaveJSON file.\n");
|
|
|
|
log("\n");
|
2014-02-18 02:29:08 -06:00
|
|
|
log(" -dump_cnf <cnf-file-name>\n");
|
|
|
|
log(" dump CNF of SAT problem (in DIMACS format). in temporal induction\n");
|
|
|
|
log(" proofs this is the CNF of the first induction step.\n");
|
|
|
|
log("\n");
|
2013-06-09 09:30:37 -05:00
|
|
|
log("The following additional options can be used to set up a proof. If also -seq\n");
|
|
|
|
log("is passed, a temporal induction proof is performed.\n");
|
|
|
|
log("\n");
|
2014-01-19 08:38:23 -06:00
|
|
|
log(" -tempinduct\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log(" Perform a temporal induction proof. In a temporal induction proof it is\n");
|
2014-01-19 08:38:23 -06:00
|
|
|
log(" proven that the condition holds forever after the number of time steps\n");
|
|
|
|
log(" specified using -seq.\n");
|
|
|
|
log("\n");
|
2014-02-06 09:15:23 -06:00
|
|
|
log(" -tempinduct-def\n");
|
|
|
|
log(" Perform a temporal induction proof. Assume an initial state with all\n");
|
|
|
|
log(" registers set to defined values for the induction step.\n");
|
|
|
|
log("\n");
|
2015-02-21 10:53:22 -06:00
|
|
|
log(" -tempinduct-baseonly\n");
|
|
|
|
log(" Run only the basecase half of temporal induction (requires -maxsteps)\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -tempinduct-inductonly\n");
|
|
|
|
log(" Run only the induction half of temporal induction\n");
|
|
|
|
log("\n");
|
2015-02-21 15:52:49 -06:00
|
|
|
log(" -tempinduct-skip <N>\n");
|
|
|
|
log(" Skip the first <N> steps of the induction proof.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" note: this will assume that the base case holds for <N> steps.\n");
|
|
|
|
log(" this must be proven independently with \"-tempinduct-baseonly\n");
|
|
|
|
log(" -maxsteps <N>\". Use -initsteps if you just want to set a\n");
|
|
|
|
log(" minimal induction length.\n");
|
|
|
|
log("\n");
|
2013-06-09 09:30:37 -05:00
|
|
|
log(" -prove <signal> <value>\n");
|
2014-01-19 08:38:23 -06:00
|
|
|
log(" Attempt to proof that <signal> is always <value>.\n");
|
2013-06-09 09:30:37 -05:00
|
|
|
log("\n");
|
2013-12-28 04:24:36 -06:00
|
|
|
log(" -prove-x <signal> <value>\n");
|
|
|
|
log(" Like -prove, but an undef (x) bit in the lhs matches any value on\n");
|
2015-08-14 03:56:05 -05:00
|
|
|
log(" the right hand side. Useful for equivalence checking.\n");
|
2013-12-28 04:24:36 -06:00
|
|
|
log("\n");
|
2014-01-19 08:38:23 -06:00
|
|
|
log(" -prove-asserts\n");
|
|
|
|
log(" Prove that all asserts in the design hold.\n");
|
|
|
|
log("\n");
|
2014-08-08 06:11:54 -05:00
|
|
|
log(" -prove-skip <N>\n");
|
|
|
|
log(" Do not enforce the prove-condition for the first <N> time steps.\n");
|
|
|
|
log("\n");
|
2013-06-09 11:07:05 -05:00
|
|
|
log(" -maxsteps <N>\n");
|
|
|
|
log(" Set a maximum length for the induction.\n");
|
|
|
|
log("\n");
|
2014-02-18 02:03:16 -06:00
|
|
|
log(" -initsteps <N>\n");
|
|
|
|
log(" Set initial length for the induction.\n");
|
2015-02-21 15:52:49 -06:00
|
|
|
log(" This will speed up the search of the right induction length\n");
|
|
|
|
log(" for deep induction proofs.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -stepsize <N>\n");
|
|
|
|
log(" Increase the size of the induction proof in steps of <N>.\n");
|
|
|
|
log(" This will speed up the search of the right induction length\n");
|
|
|
|
log(" for deep induction proofs.\n");
|
2014-02-18 02:03:16 -06:00
|
|
|
log("\n");
|
2013-06-20 05:49:10 -05:00
|
|
|
log(" -timeout <N>\n");
|
|
|
|
log(" Maximum number of seconds a single SAT instance may take.\n");
|
|
|
|
log("\n");
|
2013-06-09 09:30:37 -05:00
|
|
|
log(" -verify\n");
|
|
|
|
log(" Return an error and stop the synthesis script if the proof fails.\n");
|
|
|
|
log("\n");
|
2013-06-20 05:49:10 -05:00
|
|
|
log(" -verify-no-timeout\n");
|
|
|
|
log(" Like -verify but do not return an error for timeouts.\n");
|
|
|
|
log("\n");
|
2014-02-04 06:34:37 -06:00
|
|
|
log(" -falsify\n");
|
|
|
|
log(" Return an error and stop the synthesis script if the proof succeeds.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -falsify-no-timeout\n");
|
|
|
|
log(" Like -falsify but do not return an error for timeouts.\n");
|
|
|
|
log("\n");
|
2013-06-07 06:59:13 -05:00
|
|
|
}
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
2013-06-07 06:59:13 -05:00
|
|
|
{
|
2013-12-28 04:24:36 -06:00
|
|
|
std::vector<std::pair<std::string, std::string>> sets, sets_init, prove, prove_x;
|
2013-06-09 06:35:46 -05:00
|
|
|
std::map<int, std::vector<std::pair<std::string, std::string>>> sets_at;
|
2013-12-27 06:02:46 -06:00
|
|
|
std::map<int, std::vector<std::string>> unsets_at, sets_def_at, sets_any_undef_at, sets_all_undef_at;
|
|
|
|
std::vector<std::string> shows, sets_def, sets_any_undef, sets_all_undef;
|
2014-08-08 06:11:54 -05:00
|
|
|
int loopcount = 0, seq_len = 0, maxsteps = 0, initsteps = 0, timeout = 0, prove_skip = 0;
|
2013-12-28 04:24:36 -06:00
|
|
|
bool verify = false, fail_on_timeout = false, enable_undef = false, set_def_inputs = false;
|
2014-02-05 18:40:01 -06:00
|
|
|
bool ignore_div_by_zero = false, set_init_undef = false, set_init_zero = false, max_undef = false;
|
2014-02-01 15:52:44 -06:00
|
|
|
bool tempinduct = false, prove_asserts = false, show_inputs = false, show_outputs = false;
|
2015-08-18 10:14:30 -05:00
|
|
|
bool show_regs = false, show_public = false, show_all = false;
|
2014-02-06 09:15:23 -06:00
|
|
|
bool ignore_unknown_cells = false, falsify = false, tempinduct_def = false, set_init_def = false;
|
2015-02-26 11:47:39 -06:00
|
|
|
bool tempinduct_baseonly = false, tempinduct_inductonly = false, set_assumes = false;
|
2015-02-21 15:52:49 -06:00
|
|
|
int tempinduct_skip = 0, stepsize = 1;
|
2015-02-19 03:53:40 -06:00
|
|
|
std::string vcd_file_name, json_file_name, cnf_file_name;
|
2013-06-07 06:59:13 -05:00
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing SAT pass (solving SAT problems in the circuit).\n");
|
2013-06-07 06:59:13 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
2013-06-08 05:17:30 -05:00
|
|
|
if (args[argidx] == "-all") {
|
|
|
|
loopcount = -1;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
if (args[argidx] == "-verify") {
|
2013-06-20 05:49:10 -05:00
|
|
|
fail_on_timeout = true;
|
2013-06-09 09:30:37 -05:00
|
|
|
verify = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-20 05:49:10 -05:00
|
|
|
if (args[argidx] == "-verify-no-timeout") {
|
|
|
|
verify = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-04 06:34:37 -06:00
|
|
|
if (args[argidx] == "-falsify") {
|
|
|
|
fail_on_timeout = true;
|
|
|
|
falsify = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-falsify-no-timeout") {
|
|
|
|
falsify = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-20 05:49:10 -05:00
|
|
|
if (args[argidx] == "-timeout" && argidx+1 < args.size()) {
|
2019-08-07 13:11:14 -05:00
|
|
|
timeout = atoi(args[++argidx].c_str());
|
2013-06-20 05:49:10 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-08 05:17:30 -05:00
|
|
|
if (args[argidx] == "-max" && argidx+1 < args.size()) {
|
2019-08-07 13:11:14 -05:00
|
|
|
loopcount = atoi(args[++argidx].c_str());
|
2013-06-08 05:17:30 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-09 11:07:05 -05:00
|
|
|
if (args[argidx] == "-maxsteps" && argidx+1 < args.size()) {
|
2019-08-07 13:11:14 -05:00
|
|
|
maxsteps = atoi(args[++argidx].c_str());
|
2013-06-09 11:07:05 -05:00
|
|
|
continue;
|
|
|
|
}
|
2014-02-18 02:03:16 -06:00
|
|
|
if (args[argidx] == "-initsteps" && argidx+1 < args.size()) {
|
2019-08-07 13:11:14 -05:00
|
|
|
initsteps = atoi(args[++argidx].c_str());
|
2014-02-18 02:03:16 -06:00
|
|
|
continue;
|
|
|
|
}
|
2015-02-21 15:52:49 -06:00
|
|
|
if (args[argidx] == "-stepsize" && argidx+1 < args.size()) {
|
2019-08-07 13:11:14 -05:00
|
|
|
stepsize = max(1, atoi(args[++argidx].c_str()));
|
2015-02-21 15:52:49 -06:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-25 14:40:00 -06:00
|
|
|
if (args[argidx] == "-ignore_div_by_zero") {
|
2013-08-15 04:40:01 -05:00
|
|
|
ignore_div_by_zero = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-25 14:40:00 -06:00
|
|
|
if (args[argidx] == "-enable_undef") {
|
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-07 16:58:55 -06:00
|
|
|
if (args[argidx] == "-max_undef") {
|
|
|
|
enable_undef = true;
|
|
|
|
max_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-28 04:24:36 -06:00
|
|
|
if (args[argidx] == "-set-def-inputs") {
|
|
|
|
enable_undef = true;
|
|
|
|
set_def_inputs = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-07 06:59:13 -05:00
|
|
|
if (args[argidx] == "-set" && argidx+2 < args.size()) {
|
2013-11-25 14:40:00 -06:00
|
|
|
std::string lhs = args[++argidx];
|
|
|
|
std::string rhs = args[++argidx];
|
2013-06-07 06:59:13 -05:00
|
|
|
sets.push_back(std::pair<std::string, std::string>(lhs, rhs));
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-27 06:02:46 -06:00
|
|
|
if (args[argidx] == "-set-def" && argidx+1 < args.size()) {
|
2013-11-25 14:40:00 -06:00
|
|
|
sets_def.push_back(args[++argidx]);
|
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-27 06:02:46 -06:00
|
|
|
if (args[argidx] == "-set-any-undef" && argidx+1 < args.size()) {
|
|
|
|
sets_any_undef.push_back(args[++argidx]);
|
2013-11-25 14:40:00 -06:00
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-27 06:02:46 -06:00
|
|
|
if (args[argidx] == "-set-all-undef" && argidx+1 < args.size()) {
|
2013-11-25 14:40:00 -06:00
|
|
|
sets_all_undef.push_back(args[++argidx]);
|
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-26 11:47:39 -06:00
|
|
|
if (args[argidx] == "-set-assumes") {
|
|
|
|
set_assumes = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-19 08:38:23 -06:00
|
|
|
if (args[argidx] == "-tempinduct") {
|
|
|
|
tempinduct = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-06 09:15:23 -06:00
|
|
|
if (args[argidx] == "-tempinduct-def") {
|
|
|
|
tempinduct = true;
|
|
|
|
tempinduct_def = true;
|
2019-05-01 17:03:31 -05:00
|
|
|
enable_undef = true;
|
2014-02-06 09:15:23 -06:00
|
|
|
continue;
|
|
|
|
}
|
2015-02-21 10:53:22 -06:00
|
|
|
if (args[argidx] == "-tempinduct-baseonly") {
|
|
|
|
tempinduct = true;
|
|
|
|
tempinduct_baseonly = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-tempinduct-inductonly") {
|
|
|
|
tempinduct = true;
|
|
|
|
tempinduct_inductonly = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-21 15:52:49 -06:00
|
|
|
if (args[argidx] == "-tempinduct-skip" && argidx+1 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
tempinduct_skip = atoi(args[++argidx].c_str());
|
2015-02-21 15:52:49 -06:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
if (args[argidx] == "-prove" && argidx+2 < args.size()) {
|
2013-11-25 14:40:00 -06:00
|
|
|
std::string lhs = args[++argidx];
|
|
|
|
std::string rhs = args[++argidx];
|
2013-06-09 09:30:37 -05:00
|
|
|
prove.push_back(std::pair<std::string, std::string>(lhs, rhs));
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-28 04:24:36 -06:00
|
|
|
if (args[argidx] == "-prove-x" && argidx+2 < args.size()) {
|
|
|
|
std::string lhs = args[++argidx];
|
|
|
|
std::string rhs = args[++argidx];
|
|
|
|
prove_x.push_back(std::pair<std::string, std::string>(lhs, rhs));
|
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-19 08:38:23 -06:00
|
|
|
if (args[argidx] == "-prove-asserts") {
|
|
|
|
prove_asserts = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-08 06:11:54 -05:00
|
|
|
if (args[argidx] == "-prove-skip" && argidx+1 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
prove_skip = atoi(args[++argidx].c_str());
|
2014-08-08 06:11:54 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-09 06:35:46 -05:00
|
|
|
if (args[argidx] == "-seq" && argidx+1 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
seq_len = atoi(args[++argidx].c_str());
|
2013-06-09 06:35:46 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-set-at" && argidx+3 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
int timestep = atoi(args[++argidx].c_str());
|
2013-11-25 14:40:00 -06:00
|
|
|
std::string lhs = args[++argidx];
|
|
|
|
std::string rhs = args[++argidx];
|
2013-06-09 06:35:46 -05:00
|
|
|
sets_at[timestep].push_back(std::pair<std::string, std::string>(lhs, rhs));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-unset-at" && argidx+2 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
int timestep = atoi(args[++argidx].c_str());
|
2013-11-25 14:40:00 -06:00
|
|
|
unsets_at[timestep].push_back(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-set-def-at" && argidx+2 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
int timestep = atoi(args[++argidx].c_str());
|
2013-11-25 14:40:00 -06:00
|
|
|
sets_def_at[timestep].push_back(args[++argidx]);
|
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-27 06:02:46 -06:00
|
|
|
if (args[argidx] == "-set-any-undef-at" && argidx+2 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
int timestep = atoi(args[++argidx].c_str());
|
2013-12-27 06:02:46 -06:00
|
|
|
sets_any_undef_at[timestep].push_back(args[++argidx]);
|
2013-11-25 14:40:00 -06:00
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-set-all-undef-at" && argidx+2 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
int timestep = atoi(args[++argidx].c_str());
|
2013-11-25 14:40:00 -06:00
|
|
|
sets_all_undef_at[timestep].push_back(args[++argidx]);
|
|
|
|
enable_undef = true;
|
2013-06-09 06:35:46 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-12-07 10:28:51 -06:00
|
|
|
if (args[argidx] == "-set-init" && argidx+2 < args.size()) {
|
|
|
|
std::string lhs = args[++argidx];
|
|
|
|
std::string rhs = args[++argidx];
|
|
|
|
sets_init.push_back(std::pair<std::string, std::string>(lhs, rhs));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-set-init-undef") {
|
|
|
|
set_init_undef = true;
|
|
|
|
enable_undef = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-06 09:15:23 -06:00
|
|
|
if (args[argidx] == "-set-init-def") {
|
|
|
|
set_init_def = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-05 18:40:01 -06:00
|
|
|
if (args[argidx] == "-set-init-zero") {
|
|
|
|
set_init_zero = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-07 06:59:13 -05:00
|
|
|
if (args[argidx] == "-show" && argidx+1 < args.size()) {
|
|
|
|
shows.push_back(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-01 15:52:44 -06:00
|
|
|
if (args[argidx] == "-show-inputs") {
|
|
|
|
show_inputs = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-show-outputs") {
|
|
|
|
show_outputs = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-27 17:04:28 -06:00
|
|
|
if (args[argidx] == "-show-ports") {
|
|
|
|
show_inputs = true;
|
|
|
|
show_outputs = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-18 10:14:30 -05:00
|
|
|
if (args[argidx] == "-show-regs") {
|
|
|
|
show_regs = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-show-public") {
|
|
|
|
show_public = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-show-all") {
|
|
|
|
show_all = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-03 09:26:10 -06:00
|
|
|
if (args[argidx] == "-ignore_unknown_cells") {
|
|
|
|
ignore_unknown_cells = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-17 06:57:14 -06:00
|
|
|
if (args[argidx] == "-dump_vcd" && argidx+1 < args.size()) {
|
2014-02-17 05:06:04 -06:00
|
|
|
vcd_file_name = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-19 03:53:40 -06:00
|
|
|
if (args[argidx] == "-dump_json" && argidx+1 < args.size()) {
|
|
|
|
json_file_name = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-18 02:29:08 -06:00
|
|
|
if (args[argidx] == "-dump_cnf" && argidx+1 < args.size()) {
|
|
|
|
cnf_file_name = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-07 06:59:13 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
|
|
|
RTLIL::Module *module = NULL;
|
2015-04-18 02:29:03 -05:00
|
|
|
for (auto mod : design->selected_modules()) {
|
|
|
|
if (module)
|
|
|
|
log_cmd_error("Only one module must be selected for the SAT pass! (selected: %s and %s)\n", log_id(module), log_id(mod));
|
|
|
|
module = mod;
|
|
|
|
}
|
2015-02-19 03:53:40 -06:00
|
|
|
if (module == NULL)
|
2013-06-19 02:30:37 -05:00
|
|
|
log_cmd_error("Can't perform SAT on an empty selection!\n");
|
2013-06-07 06:59:13 -05:00
|
|
|
|
2014-01-19 08:38:23 -06:00
|
|
|
if (!prove.size() && !prove_x.size() && !prove_asserts && tempinduct)
|
|
|
|
log_cmd_error("Got -tempinduct but nothing to prove!\n");
|
|
|
|
|
2014-08-08 06:11:54 -05:00
|
|
|
if (prove_skip && tempinduct)
|
2015-01-27 17:46:00 -06:00
|
|
|
log_cmd_error("Options -prove-skip and -tempinduct don't work with each other. Use -seq instead of -prove-skip.\n");
|
2014-08-08 06:11:54 -05:00
|
|
|
|
|
|
|
if (prove_skip >= seq_len && prove_skip > 0)
|
|
|
|
log_cmd_error("The value of -prove-skip must be smaller than the one of -seq.\n");
|
|
|
|
|
2014-02-06 09:15:23 -06:00
|
|
|
if (set_init_undef + set_init_zero + set_init_def > 1)
|
|
|
|
log_cmd_error("The options -set-init-undef, -set-init-def, and -set-init-zero are exclusive!\n");
|
2014-02-05 18:40:01 -06:00
|
|
|
|
2013-12-28 04:24:36 -06:00
|
|
|
if (set_def_inputs) {
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_)
|
2013-12-28 04:24:36 -06:00
|
|
|
if (it.second->port_input)
|
2014-08-02 06:11:01 -05:00
|
|
|
sets_def.push_back(it.second->name.str());
|
2013-12-28 04:24:36 -06:00
|
|
|
}
|
|
|
|
|
2014-02-01 15:52:44 -06:00
|
|
|
if (show_inputs) {
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_)
|
2014-02-01 15:52:44 -06:00
|
|
|
if (it.second->port_input)
|
2014-08-02 06:11:01 -05:00
|
|
|
shows.push_back(it.second->name.str());
|
2014-02-01 15:52:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (show_outputs) {
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_)
|
2014-02-01 15:52:44 -06:00
|
|
|
if (it.second->port_output)
|
2014-08-02 06:11:01 -05:00
|
|
|
shows.push_back(it.second->name.str());
|
2014-02-01 15:52:44 -06:00
|
|
|
}
|
|
|
|
|
2015-08-18 10:14:30 -05:00
|
|
|
if (show_regs) {
|
|
|
|
pool<Wire*> reg_wires;
|
|
|
|
for (auto cell : module->cells()) {
|
2019-08-07 14:20:08 -05:00
|
|
|
if (cell->type == "$dff" || cell->type.begins_with("$_DFF_"))
|
2015-08-18 10:14:30 -05:00
|
|
|
for (auto bit : cell->getPort("\\Q"))
|
|
|
|
if (bit.wire)
|
|
|
|
reg_wires.insert(bit.wire);
|
|
|
|
}
|
|
|
|
for (auto wire : reg_wires)
|
|
|
|
shows.push_back(wire->name.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_public) {
|
|
|
|
for (auto wire : module->wires())
|
|
|
|
if (wire->name[0] == '\\')
|
|
|
|
shows.push_back(wire->name.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_all) {
|
|
|
|
for (auto wire : module->wires())
|
|
|
|
shows.push_back(wire->name.str());
|
|
|
|
}
|
|
|
|
|
2014-01-19 08:38:23 -06:00
|
|
|
if (tempinduct)
|
2013-06-09 09:30:37 -05:00
|
|
|
{
|
2013-12-07 16:58:55 -06:00
|
|
|
if (loopcount > 0 || max_undef)
|
|
|
|
log_cmd_error("The options -max, -all, and -max_undef are not supported for temporal induction proofs!\n");
|
2013-06-09 11:07:05 -05:00
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
SatHelper basecase(design, module, enable_undef);
|
|
|
|
SatHelper inductstep(design, module, enable_undef);
|
2013-06-09 11:07:05 -05:00
|
|
|
|
|
|
|
basecase.sets = sets;
|
2015-02-26 11:47:39 -06:00
|
|
|
basecase.set_assumes = set_assumes;
|
2013-06-09 11:07:05 -05:00
|
|
|
basecase.prove = prove;
|
2013-12-28 04:24:36 -06:00
|
|
|
basecase.prove_x = prove_x;
|
2014-01-19 08:38:23 -06:00
|
|
|
basecase.prove_asserts = prove_asserts;
|
2013-06-09 11:07:05 -05:00
|
|
|
basecase.sets_at = sets_at;
|
|
|
|
basecase.unsets_at = unsets_at;
|
|
|
|
basecase.shows = shows;
|
2013-06-20 05:49:10 -05:00
|
|
|
basecase.timeout = timeout;
|
2013-11-25 14:40:00 -06:00
|
|
|
basecase.sets_def = sets_def;
|
2013-12-27 06:02:46 -06:00
|
|
|
basecase.sets_any_undef = sets_any_undef;
|
2013-11-25 14:40:00 -06:00
|
|
|
basecase.sets_all_undef = sets_all_undef;
|
|
|
|
basecase.sets_def_at = sets_def_at;
|
2013-12-27 06:02:46 -06:00
|
|
|
basecase.sets_any_undef_at = sets_any_undef_at;
|
2013-11-25 14:40:00 -06:00
|
|
|
basecase.sets_all_undef_at = sets_all_undef_at;
|
2013-12-07 10:28:51 -06:00
|
|
|
basecase.sets_init = sets_init;
|
2014-02-06 09:15:23 -06:00
|
|
|
basecase.set_init_def = set_init_def;
|
2013-12-07 10:28:51 -06:00
|
|
|
basecase.set_init_undef = set_init_undef;
|
2014-02-05 18:40:01 -06:00
|
|
|
basecase.set_init_zero = set_init_zero;
|
2013-08-15 04:40:01 -05:00
|
|
|
basecase.satgen.ignore_div_by_zero = ignore_div_by_zero;
|
2014-02-03 09:26:10 -06:00
|
|
|
basecase.ignore_unknown_cells = ignore_unknown_cells;
|
2013-06-09 11:07:05 -05:00
|
|
|
|
|
|
|
for (int timestep = 1; timestep <= seq_len; timestep++)
|
2015-02-21 10:53:22 -06:00
|
|
|
if (!tempinduct_inductonly)
|
2016-07-23 10:01:03 -05:00
|
|
|
basecase.setup(timestep, timestep == 1);
|
2013-06-09 11:07:05 -05:00
|
|
|
|
|
|
|
inductstep.sets = sets;
|
2015-02-26 11:47:39 -06:00
|
|
|
inductstep.set_assumes = set_assumes;
|
2013-06-09 11:07:05 -05:00
|
|
|
inductstep.prove = prove;
|
2013-12-28 04:24:36 -06:00
|
|
|
inductstep.prove_x = prove_x;
|
2014-01-19 08:38:23 -06:00
|
|
|
inductstep.prove_asserts = prove_asserts;
|
2013-06-09 11:07:05 -05:00
|
|
|
inductstep.shows = shows;
|
2013-06-20 05:49:10 -05:00
|
|
|
inductstep.timeout = timeout;
|
2013-11-25 14:40:00 -06:00
|
|
|
inductstep.sets_def = sets_def;
|
2013-12-27 06:02:46 -06:00
|
|
|
inductstep.sets_any_undef = sets_any_undef;
|
2013-11-25 14:40:00 -06:00
|
|
|
inductstep.sets_all_undef = sets_all_undef;
|
2013-08-15 04:40:01 -05:00
|
|
|
inductstep.satgen.ignore_div_by_zero = ignore_div_by_zero;
|
2014-02-03 09:26:10 -06:00
|
|
|
inductstep.ignore_unknown_cells = ignore_unknown_cells;
|
2013-06-09 11:07:05 -05:00
|
|
|
|
2015-02-21 10:53:22 -06:00
|
|
|
if (!tempinduct_baseonly) {
|
|
|
|
inductstep.setup(1);
|
|
|
|
inductstep.ez->assume(inductstep.setup_proof(1));
|
|
|
|
}
|
2013-06-09 11:07:05 -05:00
|
|
|
|
2014-02-06 09:15:23 -06:00
|
|
|
if (tempinduct_def) {
|
|
|
|
std::vector<int> undef_state = inductstep.satgen.importUndefSigSpec(inductstep.satgen.initial_state.export_all(), 1);
|
2015-02-21 05:15:41 -06:00
|
|
|
inductstep.ez->assume(inductstep.ez->NOT(inductstep.ez->expression(ezSAT::OpOr, undef_state)));
|
2014-02-06 09:15:23 -06:00
|
|
|
}
|
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
for (int inductlen = 1; inductlen <= maxsteps || maxsteps == 0; inductlen++)
|
|
|
|
{
|
|
|
|
log("\n** Trying induction with length %d **\n", inductlen);
|
|
|
|
|
|
|
|
// phase 1: proving base case
|
|
|
|
|
2015-02-21 10:53:22 -06:00
|
|
|
if (!tempinduct_inductonly)
|
|
|
|
{
|
2016-07-23 10:01:03 -05:00
|
|
|
basecase.setup(seq_len + inductlen, seq_len + inductlen == 1);
|
2015-02-21 10:53:22 -06:00
|
|
|
int property = basecase.setup_proof(seq_len + inductlen);
|
|
|
|
basecase.generate_model();
|
2013-06-09 11:07:05 -05:00
|
|
|
|
2015-02-21 10:53:22 -06:00
|
|
|
if (inductlen > 1)
|
|
|
|
basecase.force_unique_state(seq_len + 1, seq_len + inductlen);
|
|
|
|
|
2015-02-21 15:52:49 -06:00
|
|
|
if (tempinduct_skip < inductlen)
|
|
|
|
{
|
|
|
|
log("\n[base case %d] Solving problem with %d variables and %d clauses..\n",
|
|
|
|
inductlen, basecase.ez->numCnfVariables(), basecase.ez->numCnfClauses());
|
2016-09-06 10:35:25 -05:00
|
|
|
log_flush();
|
2015-02-21 15:52:49 -06:00
|
|
|
|
|
|
|
if (basecase.solve(basecase.ez->NOT(property))) {
|
|
|
|
log("SAT temporal induction proof finished - model found for base case: FAIL!\n");
|
|
|
|
print_proof_failed();
|
|
|
|
basecase.print_model();
|
|
|
|
if(!vcd_file_name.empty())
|
|
|
|
basecase.dump_model_to_vcd(vcd_file_name);
|
|
|
|
if(!json_file_name.empty())
|
|
|
|
basecase.dump_model_to_json(json_file_name);
|
|
|
|
goto tip_failed;
|
|
|
|
}
|
2013-06-09 11:07:05 -05:00
|
|
|
|
2015-02-21 15:52:49 -06:00
|
|
|
if (basecase.gotTimeout)
|
|
|
|
goto timeout;
|
2013-06-20 05:49:10 -05:00
|
|
|
|
2015-02-21 15:52:49 -06:00
|
|
|
log("Base case for induction length %d proven.\n", inductlen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log("\n[base case %d] Skipping prove for this step (-tempinduct-skip %d).",
|
|
|
|
inductlen, tempinduct_skip);
|
|
|
|
log("\n[base case %d] Problem size so far: %d variables and %d clauses.\n",
|
|
|
|
inductlen, basecase.ez->numCnfVariables(), basecase.ez->numCnfClauses());
|
|
|
|
}
|
2015-02-21 10:53:22 -06:00
|
|
|
basecase.ez->assume(property);
|
|
|
|
}
|
2013-06-09 11:07:05 -05:00
|
|
|
|
|
|
|
// phase 2: proving induction step
|
|
|
|
|
2015-02-21 10:53:22 -06:00
|
|
|
if (!tempinduct_baseonly)
|
2014-02-18 02:03:16 -06:00
|
|
|
{
|
2015-02-21 10:53:22 -06:00
|
|
|
inductstep.setup(inductlen + 1);
|
|
|
|
int property = inductstep.setup_proof(inductlen + 1);
|
|
|
|
inductstep.generate_model();
|
2014-02-18 02:29:08 -06:00
|
|
|
|
2015-02-21 10:53:22 -06:00
|
|
|
if (inductlen > 1)
|
|
|
|
inductstep.force_unique_state(1, inductlen + 1);
|
2014-02-18 02:29:08 -06:00
|
|
|
|
2015-02-22 05:42:05 -06:00
|
|
|
if (inductlen <= tempinduct_skip || inductlen <= initsteps || inductlen % stepsize != 0)
|
2015-02-21 10:53:22 -06:00
|
|
|
{
|
2015-02-21 15:52:49 -06:00
|
|
|
if (inductlen < tempinduct_skip)
|
|
|
|
log("\n[induction step %d] Skipping prove for this step (-tempinduct-skip %d).",
|
|
|
|
inductlen, tempinduct_skip);
|
|
|
|
if (inductlen < initsteps)
|
|
|
|
log("\n[induction step %d] Skipping prove for this step (-initsteps %d).",
|
|
|
|
inductlen, tempinduct_skip);
|
|
|
|
if (inductlen % stepsize != 0)
|
|
|
|
log("\n[induction step %d] Skipping prove for this step (-stepsize %d).",
|
|
|
|
inductlen, stepsize);
|
|
|
|
log("\n[induction step %d] Problem size so far: %d variables and %d clauses.\n",
|
|
|
|
inductlen, inductstep.ez->numCnfVariables(), inductstep.ez->numCnfClauses());
|
2015-02-21 10:53:22 -06:00
|
|
|
inductstep.ez->assume(property);
|
2014-02-18 02:29:08 -06:00
|
|
|
}
|
2015-02-21 10:53:22 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!cnf_file_name.empty())
|
|
|
|
{
|
2019-06-20 12:27:59 -05:00
|
|
|
rewrite_filename(cnf_file_name);
|
2015-02-21 10:53:22 -06:00
|
|
|
FILE *f = fopen(cnf_file_name.c_str(), "w");
|
|
|
|
if (!f)
|
|
|
|
log_cmd_error("Can't open output file `%s' for writing: %s\n", cnf_file_name.c_str(), strerror(errno));
|
|
|
|
|
|
|
|
log("Dumping CNF to file `%s'.\n", cnf_file_name.c_str());
|
|
|
|
cnf_file_name.clear();
|
|
|
|
|
|
|
|
inductstep.ez->printDIMACS(f, false);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2015-02-21 15:52:49 -06:00
|
|
|
log("\n[induction step %d] Solving problem with %d variables and %d clauses..\n",
|
|
|
|
inductlen, inductstep.ez->numCnfVariables(), inductstep.ez->numCnfClauses());
|
2016-09-06 10:35:25 -05:00
|
|
|
log_flush();
|
2015-02-21 10:53:22 -06:00
|
|
|
|
|
|
|
if (!inductstep.solve(inductstep.ez->NOT(property))) {
|
|
|
|
if (inductstep.gotTimeout)
|
|
|
|
goto timeout;
|
|
|
|
log("Induction step proven: SUCCESS!\n");
|
|
|
|
print_qed();
|
|
|
|
goto tip_success;
|
|
|
|
}
|
|
|
|
|
|
|
|
log("Induction step failed. Incrementing induction length.\n");
|
|
|
|
inductstep.ez->assume(property);
|
|
|
|
inductstep.print_model();
|
2014-02-18 02:03:16 -06:00
|
|
|
}
|
|
|
|
}
|
2013-06-09 11:07:05 -05:00
|
|
|
}
|
|
|
|
|
2015-02-21 13:05:16 -06:00
|
|
|
if (tempinduct_baseonly) {
|
|
|
|
log("\nReached maximum number of time steps -> proved base case for %d steps: SUCCESS!\n", maxsteps);
|
|
|
|
goto tip_success;
|
|
|
|
}
|
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
log("\nReached maximum number of time steps -> proof failed.\n");
|
2014-08-24 06:27:40 -05:00
|
|
|
if(!vcd_file_name.empty())
|
|
|
|
inductstep.dump_model_to_vcd(vcd_file_name);
|
2015-02-19 03:53:40 -06:00
|
|
|
if(!json_file_name.empty())
|
|
|
|
inductstep.dump_model_to_json(json_file_name);
|
2013-06-09 11:07:05 -05:00
|
|
|
print_proof_failed();
|
|
|
|
|
|
|
|
tip_failed:
|
|
|
|
if (verify) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -verify and proof did fail!\n");
|
|
|
|
}
|
|
|
|
|
2014-02-04 06:34:37 -06:00
|
|
|
if (0)
|
|
|
|
tip_success:
|
|
|
|
if (falsify) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -falsify and proof did succeed!\n");
|
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
2013-06-09 08:49:32 -05:00
|
|
|
else
|
2013-06-09 09:30:37 -05:00
|
|
|
{
|
2013-06-23 06:28:30 -05:00
|
|
|
if (maxsteps > 0)
|
2013-06-09 11:07:05 -05:00
|
|
|
log_cmd_error("The options -maxsteps is only supported for temporal induction proofs!\n");
|
|
|
|
|
2013-12-07 10:28:51 -06:00
|
|
|
SatHelper sathelper(design, module, enable_undef);
|
|
|
|
|
2013-06-09 09:30:37 -05:00
|
|
|
sathelper.sets = sets;
|
2015-02-26 11:47:39 -06:00
|
|
|
sathelper.set_assumes = set_assumes;
|
2013-06-09 09:30:37 -05:00
|
|
|
sathelper.prove = prove;
|
2013-12-28 04:24:36 -06:00
|
|
|
sathelper.prove_x = prove_x;
|
2014-01-19 08:38:23 -06:00
|
|
|
sathelper.prove_asserts = prove_asserts;
|
2013-06-09 09:30:37 -05:00
|
|
|
sathelper.sets_at = sets_at;
|
|
|
|
sathelper.unsets_at = unsets_at;
|
|
|
|
sathelper.shows = shows;
|
2013-06-20 05:49:10 -05:00
|
|
|
sathelper.timeout = timeout;
|
2013-11-25 14:40:00 -06:00
|
|
|
sathelper.sets_def = sets_def;
|
2013-12-27 06:02:46 -06:00
|
|
|
sathelper.sets_any_undef = sets_any_undef;
|
2013-11-25 14:40:00 -06:00
|
|
|
sathelper.sets_all_undef = sets_all_undef;
|
|
|
|
sathelper.sets_def_at = sets_def_at;
|
2013-12-27 06:02:46 -06:00
|
|
|
sathelper.sets_any_undef_at = sets_any_undef_at;
|
2013-11-25 14:40:00 -06:00
|
|
|
sathelper.sets_all_undef_at = sets_all_undef_at;
|
2013-12-07 10:28:51 -06:00
|
|
|
sathelper.sets_init = sets_init;
|
2014-02-06 09:15:23 -06:00
|
|
|
sathelper.set_init_def = set_init_def;
|
2013-12-07 10:28:51 -06:00
|
|
|
sathelper.set_init_undef = set_init_undef;
|
2014-02-05 18:40:01 -06:00
|
|
|
sathelper.set_init_zero = set_init_zero;
|
2013-08-15 04:40:01 -05:00
|
|
|
sathelper.satgen.ignore_div_by_zero = ignore_div_by_zero;
|
2014-02-03 09:26:10 -06:00
|
|
|
sathelper.ignore_unknown_cells = ignore_unknown_cells;
|
2013-06-09 09:30:37 -05:00
|
|
|
|
|
|
|
if (seq_len == 0) {
|
|
|
|
sathelper.setup();
|
2014-01-19 08:38:23 -06:00
|
|
|
if (sathelper.prove.size() || sathelper.prove_x.size() || sathelper.prove_asserts)
|
2015-02-21 05:15:41 -06:00
|
|
|
sathelper.ez->assume(sathelper.ez->NOT(sathelper.setup_proof()));
|
2013-06-09 09:30:37 -05:00
|
|
|
} else {
|
2014-02-04 05:46:16 -06:00
|
|
|
std::vector<int> prove_bits;
|
2014-01-19 08:38:23 -06:00
|
|
|
for (int timestep = 1; timestep <= seq_len; timestep++) {
|
2016-07-23 10:01:03 -05:00
|
|
|
sathelper.setup(timestep, timestep == 1);
|
2014-01-19 08:38:23 -06:00
|
|
|
if (sathelper.prove.size() || sathelper.prove_x.size() || sathelper.prove_asserts)
|
2014-08-08 06:11:54 -05:00
|
|
|
if (timestep > prove_skip)
|
|
|
|
prove_bits.push_back(sathelper.setup_proof(timestep));
|
2014-01-19 08:38:23 -06:00
|
|
|
}
|
2014-02-04 05:46:16 -06:00
|
|
|
if (sathelper.prove.size() || sathelper.prove_x.size() || sathelper.prove_asserts)
|
2015-02-21 05:15:41 -06:00
|
|
|
sathelper.ez->assume(sathelper.ez->NOT(sathelper.ez->expression(ezSAT::OpAnd, prove_bits)));
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
|
|
|
sathelper.generate_model();
|
2013-06-08 02:34:36 -05:00
|
|
|
|
2014-02-18 02:29:08 -06:00
|
|
|
if (!cnf_file_name.empty())
|
|
|
|
{
|
2019-06-20 12:27:59 -05:00
|
|
|
rewrite_filename(cnf_file_name);
|
2014-02-18 02:29:08 -06:00
|
|
|
FILE *f = fopen(cnf_file_name.c_str(), "w");
|
|
|
|
if (!f)
|
|
|
|
log_cmd_error("Can't open output file `%s' for writing: %s\n", cnf_file_name.c_str(), strerror(errno));
|
|
|
|
|
|
|
|
log("Dumping CNF to file `%s'.\n", cnf_file_name.c_str());
|
|
|
|
cnf_file_name.clear();
|
|
|
|
|
2015-02-21 05:15:41 -06:00
|
|
|
sathelper.ez->printDIMACS(f, false);
|
2014-02-18 02:29:08 -06:00
|
|
|
fclose(f);
|
|
|
|
}
|
2013-06-09 06:35:46 -05:00
|
|
|
|
2013-12-07 16:58:55 -06:00
|
|
|
int rerun_counter = 0;
|
2013-06-10 09:09:29 -05:00
|
|
|
|
2013-06-09 11:07:05 -05:00
|
|
|
rerun_solver:
|
2013-06-09 09:30:37 -05:00
|
|
|
log("\nSolving problem with %d variables and %d clauses..\n",
|
2015-02-21 05:15:41 -06:00
|
|
|
sathelper.ez->numCnfVariables(), sathelper.ez->numCnfClauses());
|
2016-09-06 10:35:25 -05:00
|
|
|
log_flush();
|
2013-06-09 09:30:37 -05:00
|
|
|
|
|
|
|
if (sathelper.solve())
|
|
|
|
{
|
2013-12-07 16:58:55 -06:00
|
|
|
if (max_undef) {
|
|
|
|
log("SAT model found. maximizing number of undefs.\n");
|
|
|
|
sathelper.maximize_undefs();
|
|
|
|
}
|
|
|
|
|
2014-01-19 08:38:23 -06:00
|
|
|
if (!prove.size() && !prove_x.size() && !prove_asserts) {
|
2013-06-09 09:30:37 -05:00
|
|
|
log("SAT solving finished - model found:\n");
|
|
|
|
} else {
|
|
|
|
log("SAT proof finished - model found: FAIL!\n");
|
2013-06-09 11:07:05 -05:00
|
|
|
print_proof_failed();
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sathelper.print_model();
|
|
|
|
|
2014-02-17 06:57:14 -06:00
|
|
|
if(!vcd_file_name.empty())
|
|
|
|
sathelper.dump_model_to_vcd(vcd_file_name);
|
2015-02-19 03:53:40 -06:00
|
|
|
if(!json_file_name.empty())
|
|
|
|
sathelper.dump_model_to_json(json_file_name);
|
2014-02-17 06:57:14 -06:00
|
|
|
|
2013-06-09 09:30:37 -05:00
|
|
|
if (loopcount != 0) {
|
2013-12-07 16:58:55 -06:00
|
|
|
loopcount--, rerun_counter++;
|
|
|
|
sathelper.invalidate_model(max_undef);
|
2013-06-09 09:30:37 -05:00
|
|
|
goto rerun_solver;
|
|
|
|
}
|
2013-06-23 06:28:30 -05:00
|
|
|
|
2014-02-05 17:59:41 -06:00
|
|
|
if (!prove.size() && !prove_x.size() && !prove_asserts) {
|
|
|
|
if (falsify) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -falsify and found a model!\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (verify) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -verify and proof did fail!\n");
|
|
|
|
}
|
2013-06-23 06:28:30 -05:00
|
|
|
}
|
2013-06-08 05:17:30 -05:00
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
else
|
|
|
|
{
|
2013-06-20 05:49:10 -05:00
|
|
|
if (sathelper.gotTimeout)
|
|
|
|
goto timeout;
|
2013-12-07 16:58:55 -06:00
|
|
|
if (rerun_counter)
|
|
|
|
log("SAT solving finished - no more models found (after %d distinct solutions).\n", rerun_counter);
|
2014-02-05 17:59:41 -06:00
|
|
|
else if (!prove.size() && !prove_x.size() && !prove_asserts) {
|
2013-06-09 09:30:37 -05:00
|
|
|
log("SAT solving finished - no model found.\n");
|
2014-02-05 17:59:41 -06:00
|
|
|
if (verify) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -verify and found no model!\n");
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-09 09:30:37 -05:00
|
|
|
log("SAT proof finished - no model found: SUCCESS!\n");
|
2013-06-09 11:07:05 -05:00
|
|
|
print_qed();
|
2014-02-04 06:34:37 -06:00
|
|
|
if (falsify) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -falsify and proof did succeed!\n");
|
|
|
|
}
|
2013-06-09 11:07:05 -05:00
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
2013-06-23 06:28:30 -05:00
|
|
|
|
2014-02-05 17:59:41 -06:00
|
|
|
if (!prove.size() && !prove_x.size() && !prove_asserts) {
|
|
|
|
if (falsify && rerun_counter) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -falsify and found a model!\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (verify && rerun_counter) {
|
|
|
|
log("\n");
|
|
|
|
log_error("Called with -verify and proof did fail!\n");
|
|
|
|
}
|
2013-06-23 06:28:30 -05:00
|
|
|
}
|
2013-06-09 09:30:37 -05:00
|
|
|
}
|
2013-06-20 05:49:10 -05:00
|
|
|
|
|
|
|
if (0) {
|
|
|
|
timeout:
|
|
|
|
log("Interrupted SAT solver: TIMEOUT!\n");
|
|
|
|
print_timeout();
|
|
|
|
if (fail_on_timeout)
|
|
|
|
log_error("Called with -verify and proof did time out!\n");
|
|
|
|
}
|
2013-06-07 06:59:13 -05:00
|
|
|
}
|
2013-06-09 14:55:53 -05:00
|
|
|
} SatPass;
|
2015-02-19 03:53:40 -06:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|