Skip to content

Commit

Permalink
Merge pull request #4140 from jix/writer_aiger_sccs
Browse files Browse the repository at this point in the history
write_aiger: Detect and error out on combinational loops
  • Loading branch information
jix authored Jan 29, 2024
2 parents 2282351 + ac6fcb2 commit fd838a9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions backends/aiger/aiger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct AigerWriter

vector<pair<int, int>> aig_gates;
vector<int> aig_latchin, aig_latchinit, aig_outputs;
vector<SigBit> bit2aig_stack;
size_t next_loop_check = 1024;
int aig_m = 0, aig_i = 0, aig_l = 0, aig_o = 0, aig_a = 0;
int aig_b = 0, aig_c = 0, aig_j = 0, aig_f = 0;

Expand Down Expand Up @@ -81,6 +83,23 @@ struct AigerWriter
return it->second;
}

if (bit2aig_stack.size() == next_loop_check) {
for (size_t i = 0; i < next_loop_check; ++i)
{
SigBit report_bit = bit2aig_stack[i];
if (report_bit != bit)
continue;
for (size_t j = i; j < next_loop_check; ++j) {
report_bit = bit2aig_stack[j];
if (report_bit.is_wire() && report_bit.wire->name.isPublic())
break;
}
log_error("Found combinational logic loop while processing signal %s.\n", log_signal(report_bit));
}
next_loop_check *= 2;
}
bit2aig_stack.push_back(bit);

// NB: Cannot use iterator returned from aig_map.insert()
// since this function is called recursively

Expand All @@ -101,6 +120,8 @@ struct AigerWriter
a = initstate_ff;
}

bit2aig_stack.pop_back();

if (bit == State::Sx || bit == State::Sz)
log_error("Design contains 'x' or 'z' bits. Use 'setundef' to replace those constants.\n");

Expand Down

0 comments on commit fd838a9

Please sign in to comment.