Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ All notable changes to this project will be documented in this file.
* added `to_string` and `write_txt` to the state transition graph, printing the full conditions of all transitions together with a legend that maps the state bits, the outputs, and every net variable of a Boolean function back to the netlist
* added tests
* removed the debug output that `solve_fsm` printed to stdout on every run
* fixed `solve_fsm` crashing on a nullptr in the state register, which is now rejected with an error naming its index, as is a nullptr in the transition logic
* fixed `solve_fsm` interpreting a user-provided initial state with the wrong bit order
* netlist preprocessing
* added an optional gate scope to the preprocessing functions, restricting which gates may be modified or deleted and defaulting to the entire netlist
Expand Down
16 changes: 16 additions & 0 deletions plugins/solve_fsm/src/solve_fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,22 @@ namespace hal
return ERR("failed to solve FSM: no transition logic configured.");
}

for (u32 i = 0; i < config.state_register.size(); i++)
{
if (config.state_register.at(i) == nullptr)
{
return ERR("failed to solve FSM: the flip-flop at index " + std::to_string(i) + " of the state register is a nullptr.");
}
}

for (u32 i = 0; i < config.transition_logic.size(); i++)
{
if (config.transition_logic.at(i) == nullptr)
{
return ERR("failed to solve FSM: the gate at index " + std::to_string(i) + " of the transition logic is a nullptr.");
}
}

const u32 state_size = config.state_register.size();
if (state_size > 64)
{
Expand Down
11 changes: 11 additions & 0 deletions plugins/solve_fsm/test/solve_fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@ namespace hal
EXPECT_TRUE(solve_fsm::solve_fsm(solve_fsm::Configuration(nl.get()).with_transition_logic(transition_logic)).is_error());
EXPECT_TRUE(solve_fsm::solve_fsm(solve_fsm::Configuration(nl.get()).with_state_register(sr.gates())).is_error());

// a nullptr in the state register or the transition logic is rejected instead of dereferenced, and the error names where it is
const auto expect_nullptr_error = [&](const std::vector<Gate*>& state_register, const std::vector<Gate*>& logic, const std::string& expected) {
const auto res = solve_fsm::solve_fsm(solve_fsm::Configuration(nl.get()).with_state_register(state_register).with_transition_logic(logic));
ASSERT_TRUE(res.is_error());
EXPECT_NE(res.get_error().get().find(expected), std::string::npos) << res.get_error().get();
};
expect_nullptr_error({nullptr, sr.ff0, sr.ff1}, transition_logic, "flip-flop at index 0 of the state register is a nullptr");
expect_nullptr_error({sr.ff0, sr.ff1, nullptr}, transition_logic, "flip-flop at index 2 of the state register is a nullptr");
expect_nullptr_error(sr.gates(), {nullptr, transition_logic.at(0), transition_logic.at(1)}, "gate at index 0 of the transition logic is a nullptr");
expect_nullptr_error(sr.gates(), {transition_logic.at(0), transition_logic.at(1), nullptr}, "gate at index 2 of the transition logic is a nullptr");

// an initial state that does not cover the whole state register is rejected as well
const auto incomplete = solve_fsm::Configuration(nl.get())
.with_state_register(sr.gates())
Expand Down
Loading