Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions frontends/btor2_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "utils/logger.h"

#include <iostream>
#include "assert.h"

using namespace smt;
using namespace std;
Expand Down Expand Up @@ -317,6 +318,7 @@ void BTOR2Encoder::parse(const std::string filename)
symbol_ = "output" + to_string(l_->id);
}
ts_.name_term(symbol_, termargs_[0]);
terms_[l_->id] = termargs_[0];
} else if (l_->tag == BTOR2_TAG_sort) {
switch (l_->sort.tag) {
case BTOR2_TAG_SORT_bitvec: {
Expand All @@ -337,7 +339,9 @@ void BTOR2Encoder::parse(const std::string filename)
throw CosaException("Unknown sort tag");
}
} else if (l_->tag == BTOR2_TAG_constraint) {
ts_.add_constraint(bv_to_bool(termargs_[0]));
Term constraint = bv_to_bool(termargs_[0]);
ts_.add_constraint(constraint);
terms_[l_->id] = constraint;
} else if (l_->tag == BTOR2_TAG_init) {
if (termargs_.size() != 2) {
throw CosaException("Expecting two term arguments to init");
Expand All @@ -346,22 +350,25 @@ void BTOR2Encoder::parse(const std::string filename)
"Expecting to init sort to match first argument's sort");
}

Term init_eq;

if (linesort_->get_sort_kind() == BV) {
ts_.constrain_init(solver_->make_term(Equal, termargs_));
init_eq = solver_->make_term(Equal, termargs_);
} else if (linesort_->get_sort_kind() == ARRAY) {
if (termargs_[1]->get_sort()->get_sort_kind() == BV) {
ts_.constrain_init(
solver_->make_term(Equal,
termargs_[0],
solver_->make_term(termargs_[1], linesort_)));
init_eq = solver_->make_term(
Equal, termargs_[0], solver_->make_term(termargs_[1], linesort_));
} else {
ts_.constrain_init(
solver_->make_term(Equal, termargs_[0], termargs_[1]));
init_eq = solver_->make_term(Equal, termargs_[0], termargs_[1]);
}
} else {
throw CosaException("Unhandled sort: "
+ termargs_[0]->get_sort()->to_string());
}

ts_.constrain_init(init_eq);
terms_[l_->id] = init_eq;

} else if (l_->tag == BTOR2_TAG_next) {
if (termargs_.size() != 2) {
throw CosaException("Expecting two arguments to next");
Expand All @@ -376,10 +383,12 @@ void BTOR2Encoder::parse(const std::string filename)

if (s0 == s1) {
ts_.assign_next(t0, t1);
terms_[l_->id] = t1;
} else if (((sk0 == BV) && (sk1 == BOOL))
|| ((sk0 == BOOL) && (sk1 == BV))) {
// need to cast
ts_.assign_next(bool_to_bv(t0), bool_to_bv(t1));
terms_[l_->id] = bool_to_bv(t1);
} else {
throw CosaException("Got two different sorts in next update.");
}
Expand Down Expand Up @@ -413,9 +422,11 @@ void BTOR2Encoder::parse(const std::string filename)
} else if (l_->tag == BTOR2_TAG_justice) {
std::cout << "Warning: ignoring justice term" << std::endl;
justicevec_.push_back(termargs_[0]);
terms_[l_->id] = termargs_[0];
} else if (l_->tag == BTOR2_TAG_fair) {
std::cout << "Warning: ignoring fair term" << std::endl;
fairvec_.push_back(termargs_[0]);
terms_[l_->id] = termargs_[0];
} else if (l_->constant) {
terms_[l_->id] =
solver_->make_term(l_->constant, linesort_, basemap.at(l_->tag));
Expand Down Expand Up @@ -712,6 +723,9 @@ void BTOR2Encoder::parse(const std::string filename)
logger.log(1, "BTOR2Encoder Warning: {}", e.what());
}
}

// sort tag should be the only one that doesn't populate terms_
assert(l_->tag == BTOR2_TAG_sort || terms_.find(l_->id) != terms_.end());
}

fclose(input_file);
Expand Down