mirror of https://github.com/YosysHQ/yosys.git
clk2fflogic: nice names for autogenerated signals
This commit is contained in:
parent
375af199ef
commit
90b40aa51f
|
@ -616,6 +616,23 @@ RTLIL::IdString new_id(std::string file, int line, std::string func)
|
||||||
return stringf("$auto$%s:%d:%s$%d", file.c_str(), line, func.c_str(), autoidx++);
|
return stringf("$auto$%s:%d:%s$%d", file.c_str(), line, func.c_str(), autoidx++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
size_t pos = file.find_last_of("/\\");
|
||||||
|
#else
|
||||||
|
size_t pos = file.find_last_of('/');
|
||||||
|
#endif
|
||||||
|
if (pos != std::string::npos)
|
||||||
|
file = file.substr(pos+1);
|
||||||
|
|
||||||
|
pos = func.find_last_of(':');
|
||||||
|
if (pos != std::string::npos)
|
||||||
|
func = func.substr(pos+1);
|
||||||
|
|
||||||
|
return stringf("$auto$%s:%d:%s$%s$%d", file.c_str(), line, func.c_str(), suffix.c_str(), autoidx++);
|
||||||
|
}
|
||||||
|
|
||||||
RTLIL::Design *yosys_get_design()
|
RTLIL::Design *yosys_get_design()
|
||||||
{
|
{
|
||||||
return yosys_design;
|
return yosys_design;
|
||||||
|
|
|
@ -321,9 +321,12 @@ Tcl_Interp *yosys_get_tcl_interp();
|
||||||
extern RTLIL::Design *yosys_design;
|
extern RTLIL::Design *yosys_design;
|
||||||
|
|
||||||
RTLIL::IdString new_id(std::string file, int line, std::string func);
|
RTLIL::IdString new_id(std::string file, int line, std::string func);
|
||||||
|
RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix);
|
||||||
|
|
||||||
#define NEW_ID \
|
#define NEW_ID \
|
||||||
YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
|
YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)
|
||||||
|
#define NEW_ID_SUFFIX(suffix) \
|
||||||
|
YOSYS_NAMESPACE_PREFIX new_id_suffix(__FILE__, __LINE__, __FUNCTION__, suffix)
|
||||||
|
|
||||||
// Create a statically allocated IdString object, using for example ID::A or ID($add).
|
// Create a statically allocated IdString object, using for example ID::A or ID($add).
|
||||||
//
|
//
|
||||||
|
|
|
@ -40,7 +40,10 @@ struct Clk2fflogicPass : public Pass {
|
||||||
log("\n");
|
log("\n");
|
||||||
}
|
}
|
||||||
SigSpec wrap_async_control(Module *module, SigSpec sig, bool polarity) {
|
SigSpec wrap_async_control(Module *module, SigSpec sig, bool polarity) {
|
||||||
Wire *past_sig = module->addWire(NEW_ID, GetSize(sig));
|
return wrap_async_control(module, sig, polarity, NEW_ID);
|
||||||
|
}
|
||||||
|
SigSpec wrap_async_control(Module *module, SigSpec sig, bool polarity, IdString past_sig_id) {
|
||||||
|
Wire *past_sig = module->addWire(past_sig_id, GetSize(sig));
|
||||||
module->addFf(NEW_ID, sig, past_sig);
|
module->addFf(NEW_ID, sig, past_sig);
|
||||||
if (polarity)
|
if (polarity)
|
||||||
sig = module->Or(NEW_ID, sig, past_sig);
|
sig = module->Or(NEW_ID, sig, past_sig);
|
||||||
|
@ -105,7 +108,7 @@ struct Clk2fflogicPass : public Pass {
|
||||||
i, log_id(module), log_id(mem.memid), log_signal(port.clk),
|
i, log_id(module), log_id(mem.memid), log_signal(port.clk),
|
||||||
log_signal(port.addr), log_signal(port.data));
|
log_signal(port.addr), log_signal(port.data));
|
||||||
|
|
||||||
Wire *past_clk = module->addWire(NEW_ID);
|
Wire *past_clk = module->addWire(NEW_ID_SUFFIX(stringf("%s#%d#past_clk#%s", log_id(mem.memid), i, log_signal(port.clk))));
|
||||||
past_clk->attributes[ID::init] = port.clk_polarity ? State::S1 : State::S0;
|
past_clk->attributes[ID::init] = port.clk_polarity ? State::S1 : State::S0;
|
||||||
module->addFf(NEW_ID, port.clk, past_clk);
|
module->addFf(NEW_ID, port.clk, past_clk);
|
||||||
|
|
||||||
|
@ -121,13 +124,13 @@ struct Clk2fflogicPass : public Pass {
|
||||||
|
|
||||||
SigSpec clock_edge = module->Eqx(NEW_ID, {port.clk, SigSpec(past_clk)}, clock_edge_pattern);
|
SigSpec clock_edge = module->Eqx(NEW_ID, {port.clk, SigSpec(past_clk)}, clock_edge_pattern);
|
||||||
|
|
||||||
SigSpec en_q = module->addWire(NEW_ID, GetSize(port.en));
|
SigSpec en_q = module->addWire(NEW_ID_SUFFIX(stringf("%s#%d#en_q", log_id(mem.memid), i)), GetSize(port.en));
|
||||||
module->addFf(NEW_ID, port.en, en_q);
|
module->addFf(NEW_ID, port.en, en_q);
|
||||||
|
|
||||||
SigSpec addr_q = module->addWire(NEW_ID, GetSize(port.addr));
|
SigSpec addr_q = module->addWire(NEW_ID_SUFFIX(stringf("%s#%d#addr_q", log_id(mem.memid), i)), GetSize(port.addr));
|
||||||
module->addFf(NEW_ID, port.addr, addr_q);
|
module->addFf(NEW_ID, port.addr, addr_q);
|
||||||
|
|
||||||
SigSpec data_q = module->addWire(NEW_ID, GetSize(port.data));
|
SigSpec data_q = module->addWire(NEW_ID_SUFFIX(stringf("%s#%d#data_q", log_id(mem.memid), i)), GetSize(port.data));
|
||||||
module->addFf(NEW_ID, port.data, data_q);
|
module->addFf(NEW_ID, port.data, data_q);
|
||||||
|
|
||||||
port.clk = State::S0;
|
port.clk = State::S0;
|
||||||
|
@ -153,7 +156,13 @@ struct Clk2fflogicPass : public Pass {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire *past_q = module->addWire(NEW_ID, ff.width);
|
// Strip spaces from signal name, since Yosys IDs can't contain spaces
|
||||||
|
// Spaces only occur when have a signal that's a slice of a larger bus,
|
||||||
|
// e.g. "\myreg [5:0]", so removing spaces shouldn't result in loss of uniqueness
|
||||||
|
std::string sig_q_str = log_signal(ff.sig_q);
|
||||||
|
sig_q_str.erase(std::remove(sig_q_str.begin(), sig_q_str.end(), ' '), sig_q_str.end());
|
||||||
|
|
||||||
|
Wire *past_q = module->addWire(NEW_ID_SUFFIX(stringf("%s#past_q_wire", sig_q_str.c_str())), ff.width);
|
||||||
if (!ff.is_fine) {
|
if (!ff.is_fine) {
|
||||||
module->addFf(NEW_ID, ff.sig_q, past_q);
|
module->addFf(NEW_ID, ff.sig_q, past_q);
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,7 +174,7 @@ struct Clk2fflogicPass : public Pass {
|
||||||
if (ff.has_clk) {
|
if (ff.has_clk) {
|
||||||
ff.unmap_ce_srst(module);
|
ff.unmap_ce_srst(module);
|
||||||
|
|
||||||
Wire *past_clk = module->addWire(NEW_ID);
|
Wire *past_clk = module->addWire(NEW_ID_SUFFIX(stringf("%s#past_clk#%s", sig_q_str.c_str(), log_signal(ff.sig_clk))));
|
||||||
initvals.set_init(past_clk, ff.pol_clk ? State::S1 : State::S0);
|
initvals.set_init(past_clk, ff.pol_clk ? State::S1 : State::S0);
|
||||||
|
|
||||||
if (!ff.is_fine)
|
if (!ff.is_fine)
|
||||||
|
@ -189,7 +198,7 @@ struct Clk2fflogicPass : public Pass {
|
||||||
|
|
||||||
SigSpec clock_edge = module->Eqx(NEW_ID, {ff.sig_clk, SigSpec(past_clk)}, clock_edge_pattern);
|
SigSpec clock_edge = module->Eqx(NEW_ID, {ff.sig_clk, SigSpec(past_clk)}, clock_edge_pattern);
|
||||||
|
|
||||||
Wire *past_d = module->addWire(NEW_ID, ff.width);
|
Wire *past_d = module->addWire(NEW_ID_SUFFIX(stringf("%s#past_d_wire", sig_q_str.c_str())), ff.width);
|
||||||
if (!ff.is_fine)
|
if (!ff.is_fine)
|
||||||
module->addFf(NEW_ID, ff.sig_d, past_d);
|
module->addFf(NEW_ID, ff.sig_d, past_d);
|
||||||
else
|
else
|
||||||
|
@ -236,7 +245,8 @@ struct Clk2fflogicPass : public Pass {
|
||||||
module->addAndGate(NEW_ID, qval, clrval, ff.sig_q);
|
module->addAndGate(NEW_ID, qval, clrval, ff.sig_q);
|
||||||
}
|
}
|
||||||
} else if (ff.has_arst) {
|
} else if (ff.has_arst) {
|
||||||
SigSpec arst = wrap_async_control(module, ff.sig_arst, ff.pol_arst);
|
IdString id = NEW_ID_SUFFIX(stringf("%s#past_arst#%s", sig_q_str.c_str(), log_signal(ff.sig_arst)));
|
||||||
|
SigSpec arst = wrap_async_control(module, ff.sig_arst, ff.pol_arst, id);
|
||||||
if (!ff.is_fine)
|
if (!ff.is_fine)
|
||||||
module->addMux(NEW_ID, qval, ff.val_arst, arst, ff.sig_q);
|
module->addMux(NEW_ID, qval, ff.val_arst, arst, ff.sig_q);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue