253 bool arst_polarity =
true;
255 std::set<sig2driver_entry_t> cellport_list;
257 for (
auto &cellport : cellport_list) {
259 if ((cell->
type !=
"$dff" && cell->
type !=
"$adff") || cellport.second !=
"\\Q")
265 clk_polarity = cell->
parameters[
"\\CLK_POLARITY"].as_bool();
266 if (cell->
type ==
"$adff") {
267 arst = cell->
getPort(
"\\ARST");
268 arst_polarity = cell->
parameters[
"\\ARST_POLARITY"].as_bool();
269 reset_state = cell->
parameters[
"\\ARST_VALUE"];
271 sig_q.replace(dff_out, sig_d, &dff_in);
275 log(
" root of input selection tree: %s\n",
log_signal(dff_in));
276 if (dff_in.has_marked_bits()) {
277 log(
" fsm extraction failed: incomplete input selection tree root.\n");
284 std::map<RTLIL::Const, int>
states;
286 log(
" found reset state: %s (from async reset)\n",
log_signal(reset_state));
287 states[reset_state] = -1;
289 if (!
find_states(dff_in, dff_out, ctrl_in, states, &reset_state)) {
290 log(
" fsm extraction failed: state selection tree is not closed.\n");
294 log(
" fsm extraction failed: at least two states are required.\n");
303 cellport_list.clear();
305 for (
auto &cellport : cellport_list) {
310 if (cellport.second ==
"\\A" && !sig_b.is_fully_const())
332 for (
auto &it : states) {
343 for (
int state_idx = 0; state_idx < int(fsm_data.
state_table.size()); state_idx++) {
344 ce.push(), ce_nostop.push();
346 ce_nostop.set(dff_out, fsm_data.
state_table[state_idx]);
348 ce.pop(), ce_nostop.pop();
354 fsm_cell->
setPort(
"\\CLK", clk);
355 fsm_cell->
setPort(
"\\ARST", arst);
358 fsm_cell->
setPort(
"\\CTRL_IN", ctrl_in);
359 fsm_cell->
setPort(
"\\CTRL_OUT", ctrl_out);
361 fsm_cell->attributes = wire->attributes;
367 wire->attributes.erase(
"\\fsm_encoding");
373 cellport_list.clear();
375 for (
auto &cellport : cellport_list) {
const char * c_str() const
bool is_fully_def() const
std::string stringf(const char *fmt,...)
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
void copy_to_cell(RTLIL::Cell *cell)
std::map< RTLIL::IdString, RTLIL::Const > parameters
void remove(const RTLIL::SigSpec &pattern)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
int GetSize(RTLIL::Wire *wire)
bool is_fully_const() const
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with)
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
std::vector< RTLIL::Const > state_table
void log(const char *format,...)
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
void append(const RTLIL::SigSpec &signal)
std::map< RTLIL::IdString, RTLIL::SigSpec > connections_
YOSYS_NAMESPACE_BEGIN int autoidx