3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-24 01:25:33 +00:00
This commit is contained in:
Emil J. Tywoniak 2024-06-11 00:06:52 +02:00
parent c0a51c8a52
commit d7251df9a9
2 changed files with 157 additions and 61 deletions

View file

@ -1020,10 +1020,10 @@ namespace {
struct InternalOldCellChecker
{
RTLIL::Module *module;
RTLIL::OldCell *cell;
RTLIL::Cell *cell;
pool<RTLIL::IdString> expected_params, expected_ports;
InternalOldCellChecker(RTLIL::Module *module, RTLIL::OldCell *cell) : module(module), cell(cell) { }
InternalOldCellChecker(RTLIL::Module *module, RTLIL::Cell *cell) : module(module), cell(cell) { }
void error(int linenr)
{
@ -1090,7 +1090,7 @@ namespace {
for (auto &para : cell->parameters)
if (expected_params.count(para.first) == 0)
error(__LINE__);
for (auto &conn : cell->connections())
for (auto &conn : cell->connections_)
if (expected_ports.count(conn.first) == 0)
error(__LINE__);
@ -1219,7 +1219,7 @@ namespace {
port(ID::B, param(ID::B_WIDTH));
port(ID::Y, param(ID::Y_WIDTH));
check_expected();
Macc().from_cell(cell);
Macc().from_cell(cell->legacy);
return;
}
@ -2128,9 +2128,9 @@ std::vector<RTLIL::Wire*> RTLIL::Module::selected_wires() const
return result;
}
std::vector<RTLIL::OldCell*> RTLIL::Module::selected_cells() const
std::vector<RTLIL::Cell*> RTLIL::Module::selected_cells() const
{
std::vector<RTLIL::OldCell*> result;
std::vector<RTLIL::Cell*> result;
result.reserve(cells_.size());
for (auto &it : cells_)
if (design->selected(this, it.second))
@ -2147,13 +2147,14 @@ void RTLIL::Module::add(RTLIL::Wire *wire)
wire->module = this;
}
void RTLIL::Module::add(RTLIL::OldCell *cell)
void RTLIL::Module::add(RTLIL::Cell *cell)
{
log_assert(!cell->name.empty());
log_assert(count_id(cell->name) == 0);
log_assert(refcount_cells_ == 0);
cells_[cell->name] = cell;
cell->module = this;
// TODO
// cell->module = this;
}
void RTLIL::Module::add(RTLIL::Process *process)
@ -2208,14 +2209,16 @@ void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
}
}
void RTLIL::Module::remove(RTLIL::OldCell *cell)
void RTLIL::Module::remove(RTLIL::Cell *cell)
{
while (!cell->connections_.empty())
cell->unsetPort(cell->connections_.begin()->first);
// TODO is this ok?
// while (!cell->connections_.empty())
// cell->unsetPort(cell->connections_.begin()->first);
//
log_assert(cells_.count(cell->name) != 0);
log_assert(refcount_cells_ == 0);
cells_.erase(cell->name);
// log_assert(cells_.count(cell->name) != 0);
// log_assert(refcount_cells_ == 0);
// cells_.erase(cell->name);
delete cell;
}
@ -2235,7 +2238,7 @@ void RTLIL::Module::rename(RTLIL::Wire *wire, RTLIL::IdString new_name)
add(wire);
}
void RTLIL::Module::rename(RTLIL::OldCell *cell, RTLIL::IdString new_name)
void RTLIL::Module::rename(RTLIL::Cell *cell, RTLIL::IdString new_name)
{
log_assert(cells_[cell->name] == cell);
log_assert(refcount_wires_ == 0);
@ -2270,7 +2273,7 @@ void RTLIL::Module::swap_names(RTLIL::Wire *w1, RTLIL::Wire *w2)
wires_[w2->name] = w2;
}
void RTLIL::Module::swap_names(RTLIL::OldCell *c1, RTLIL::OldCell *c2)
void RTLIL::Module::swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2)
{
log_assert(cells_[c1->name] == c1);
log_assert(cells_[c2->name] == c2);
@ -2427,7 +2430,7 @@ RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
// std::cout << "alloc " << (long long)cell << " called " << cell->name.c_str() << "\n";
cell->name = name;
cell->type = type;
if (RTLIL::Cell::is_legacy(type)) {
if (RTLIL::Cell::is_legacy_type(type)) {
auto legOldCell = new RTLIL::OldCell;
legOldCell->name = name;
legOldCell->type = type;
@ -2436,14 +2439,15 @@ RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
return cell;
}
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, const RTLIL::OldCell *other)
{
RTLIL::Cell *cell = addCell(name, other->type);
cell->connections_ = other->connections_;
cell->parameters = other->parameters;
cell->attributes = other->attributes;
return cell;
}
// TODO ? brokey
// RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, const RTLIL::OldCell *other)
// {
// RTLIL::Cell *cell = addCell(name, other->type);
// cell->connections_ = other->connections_;
// cell->parameters = other->parameters;
// cell->attributes = other->attributes;
// return cell;
// }
RTLIL::Memory *RTLIL::Module::addMemory(RTLIL::IdString name, const RTLIL::Memory *other)
{
@ -3293,7 +3297,7 @@ RTLIL::Cell* RTLIL::Module::addAnyinit(RTLIL::IdString name, const RTLIL::SigSpe
RTLIL::SigSpec RTLIL::Module::Anyconst(RTLIL::IdString name, int width, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, width);
OldCell *cell = addCell(name, ID($anyconst));
Cell *cell = addCell(name, ID($anyconst));
cell->setParam(ID::WIDTH, width);
cell->setPort(ID::Y, sig);
cell->set_src_attribute(src);
@ -3303,7 +3307,7 @@ RTLIL::SigSpec RTLIL::Module::Anyconst(RTLIL::IdString name, int width, const st
RTLIL::SigSpec RTLIL::Module::Anyseq(RTLIL::IdString name, int width, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, width);
OldCell *cell = addCell(name, ID($anyseq));
Cell *cell = addCell(name, ID($anyseq));
cell->setParam(ID::WIDTH, width);
cell->setPort(ID::Y, sig);
cell->set_src_attribute(src);
@ -3313,7 +3317,7 @@ RTLIL::SigSpec RTLIL::Module::Anyseq(RTLIL::IdString name, int width, const std:
RTLIL::SigSpec RTLIL::Module::Allconst(RTLIL::IdString name, int width, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, width);
OldCell *cell = addCell(name, ID($allconst));
Cell *cell = addCell(name, ID($allconst));
cell->setParam(ID::WIDTH, width);
cell->setPort(ID::Y, sig);
cell->set_src_attribute(src);
@ -3323,7 +3327,7 @@ RTLIL::SigSpec RTLIL::Module::Allconst(RTLIL::IdString name, int width, const st
RTLIL::SigSpec RTLIL::Module::Allseq(RTLIL::IdString name, int width, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, width);
OldCell *cell = addCell(name, ID($allseq));
Cell *cell = addCell(name, ID($allseq));
cell->setParam(ID::WIDTH, width);
cell->setPort(ID::Y, sig);
cell->set_src_attribute(src);
@ -3333,7 +3337,7 @@ RTLIL::SigSpec RTLIL::Module::Allseq(RTLIL::IdString name, int width, const std:
RTLIL::SigSpec RTLIL::Module::Initstate(RTLIL::IdString name, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID);
OldCell *cell = addCell(name, ID($initstate));
Cell *cell = addCell(name, ID($initstate));
cell->setPort(ID::Y, sig);
cell->set_src_attribute(src);
return sig;
@ -3342,7 +3346,7 @@ RTLIL::SigSpec RTLIL::Module::Initstate(RTLIL::IdString name, const std::string
RTLIL::SigSpec RTLIL::Module::SetTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_s, const RTLIL::SigSpec &sig_c, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, sig_a.size());
OldCell *cell = addCell(name, ID($set_tag));
Cell *cell = addCell(name, ID($set_tag));
cell->parameters[ID::WIDTH] = sig_a.size();
cell->parameters[ID::TAG] = tag;
cell->setPort(ID::A, sig_a);
@ -3355,7 +3359,7 @@ RTLIL::SigSpec RTLIL::Module::SetTag(RTLIL::IdString name, const std::string &ta
RTLIL::Cell* RTLIL::Module::addSetTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_s, const RTLIL::SigSpec &sig_c, const RTLIL::SigSpec &sig_y, const std::string &src)
{
OldCell *cell = addCell(name, ID($set_tag));
Cell *cell = addCell(name, ID($set_tag));
cell->parameters[ID::WIDTH] = sig_a.size();
cell->parameters[ID::TAG] = tag;
cell->setPort(ID::A, sig_a);
@ -3369,7 +3373,7 @@ RTLIL::Cell* RTLIL::Module::addSetTag(RTLIL::IdString name, const std::string &t
RTLIL::SigSpec RTLIL::Module::GetTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, sig_a.size());
OldCell *cell = addCell(name, ID($get_tag));
Cell *cell = addCell(name, ID($get_tag));
cell->parameters[ID::WIDTH] = sig_a.size();
cell->parameters[ID::TAG] = tag;
cell->setPort(ID::A, sig_a);
@ -3393,7 +3397,7 @@ RTLIL::Cell* RTLIL::Module::addOverwriteTag(RTLIL::IdString name, const std::str
RTLIL::SigSpec RTLIL::Module::OriginalTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, sig_a.size());
OldCell *cell = addCell(name, ID($original_tag));
Cell *cell = addCell(name, ID($original_tag));
cell->parameters[ID::WIDTH] = sig_a.size();
cell->parameters[ID::TAG] = tag;
cell->setPort(ID::A, sig_a);
@ -3405,7 +3409,7 @@ RTLIL::SigSpec RTLIL::Module::OriginalTag(RTLIL::IdString name, const std::strin
RTLIL::SigSpec RTLIL::Module::FutureFF(RTLIL::IdString name, const RTLIL::SigSpec &sig_e, const std::string &src)
{
RTLIL::SigSpec sig = addWire(NEW_ID, sig_e.size());
OldCell *cell = addCell(name, ID($future_ff));
Cell *cell = addCell(name, ID($future_ff));
cell->parameters[ID::WIDTH] = sig_e.size();
cell->setPort(ID::A, sig_e);
cell->setPort(ID::Y, sig);
@ -3487,7 +3491,7 @@ RTLIL::Cell::~Cell()
}
constexpr void RTLIL::Cell::setPort(const RTLIL::IdString &portname, RTLIL::SigSpec signal) {
void RTLIL::Cell::setPort(const RTLIL::IdString &portname, RTLIL::SigSpec signal) {
if (is_legacy()) {
legacy->setPort(portname, signal);
return;
@ -3505,7 +3509,7 @@ constexpr void RTLIL::Cell::setPort(const RTLIL::IdString &portname, RTLIL::SigS
throw std::out_of_range("Cell::setPort()");
}
}
constexpr const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &portname) {
const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &portname) {
if (is_legacy())
return legacy->getPort(portname);
@ -3523,7 +3527,7 @@ constexpr const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &port
}
// TODO autogen
constexpr void RTLIL::Cell::setParam(const RTLIL::IdString &paramname, RTLIL::Const value) {
void RTLIL::Cell::setParam(const RTLIL::IdString &paramname, RTLIL::Const value) {
if (is_legacy()) {
legacy->setParam(paramname, value);
return;
@ -3543,8 +3547,8 @@ constexpr void RTLIL::Cell::setParam(const RTLIL::IdString &paramname, RTLIL::Co
}
// TODO autogen
constexpr const RTLIL::Const RTLIL::Cell::getParam(const RTLIL::IdString &paramname) {
if (is_legacy()) {
const RTLIL::Const RTLIL::Cell::getParam(const RTLIL::IdString &paramname) {
if (is_legacy())
return legacy->getParam(paramname);
if (type == ID($not)) {

View file

@ -1050,6 +1050,7 @@ struct RTLIL::Monitor
virtual void notify_module_add(RTLIL::Module*) { }
virtual void notify_module_del(RTLIL::Module*) { }
virtual void notify_connect(RTLIL::Cell*, const RTLIL::IdString&, const RTLIL::SigSpec&, const RTLIL::SigSpec&) { }
virtual void notify_connect(RTLIL::OldCell*, const RTLIL::IdString&, const RTLIL::SigSpec&, const RTLIL::SigSpec&) { }
virtual void notify_connect(RTLIL::Module*, const RTLIL::SigSig&) { }
virtual void notify_connect(RTLIL::Module*, const std::vector<RTLIL::SigSig>&) { }
virtual void notify_blackout(RTLIL::Module*) { }
@ -1649,6 +1650,12 @@ public:
RTLIL::Const at(RTLIL::IdString name) {
return parent->getParam(name);
}
// Watch out! This is different semantics than what dict has!
// but we rely on RTLIL::Cell always being constructed correctly
// since its layout is fixed as defined by InternalOldCellChecker
RTLIL::Const operator[](RTLIL::IdString name) {
return parent->getParam(name);
}
int count(RTLIL::IdString name) {
try {
parent->getParam(name);
@ -1657,6 +1664,7 @@ public:
}
return 1;
}
};
struct FakeConns {
RTLIL::Cell* parent;
@ -1671,7 +1679,23 @@ public:
}
return 1;
}
class iterator: public std::iterator<std::input_iterator_tag, std::pair<IdString, SigSpec>> {
size_t size() const {
if (parent->is_legacy()) {
return parent->legacy->connections_.size();
} else if (parent->type == ID($pos)) {
return parent->pos.connections().size();
} else if (parent->type == ID($neg)) {
return parent->neg.connections().size();
} else if (parent->type == ID($not)) {
return parent->not_.connections().size();
} else {
log_assert(false && "malformed cell or code broke");
}
}
bool empty() {
return !size();
}
class iterator: public std::iterator<std::bidirectional_iterator_tag, std::pair<IdString, SigSpec>> {
Cell* parent;
int position;
public:
@ -1686,6 +1710,55 @@ public:
bool operator!=(const iterator &other) const {
return !(*this == other);
}
std::pair<IdString, SigSpec>& operator*() const {
if (parent->is_legacy()) {
auto it = parent->legacy->connections_.begin();
it += position;
return *it;
} else if (parent->type == ID($pos)) {
// auto a = ();
return parent->pos.connections()[position];
} else if (parent->type == ID($neg)) {
return parent->neg.connections()[position];
} else if (parent->type == ID($not)) {
return parent->not_.connections()[position];
} else {
log_assert(false && "malformed cell or code broke");
}
}
};
iterator begin() {
return iterator(parent, 0);
}
iterator end() {
if (parent->is_legacy()) {
return iterator(parent, parent->legacy->connections_.size());
} else if (parent->type == ID($pos)) {
return iterator(parent, parent->pos.connections().size());
} else if (parent->type == ID($neg)) {
return iterator(parent, parent->neg.connections().size());
} else if (parent->type == ID($not)) {
return iterator(parent, parent->not_.connections().size());
} else {
log_assert(false && "malformed cell or code broke");
}
}
// CONST ITERATOR
class const_iterator: public std::iterator<std::input_iterator_tag, std::pair<IdString, SigSpec>> {
Cell* parent;
int position;
public:
const_iterator(Cell *parent, int position)
: parent(parent), position(position) {}
const_iterator& operator++() {
position++; return *this;
}
bool operator==(const const_iterator &other) const {
return position == other.position;
}
bool operator!=(const const_iterator &other) const {
return !(*this == other);
}
std::pair<IdString, SigSpec> operator*() const {
if (parent->is_legacy()) {
auto it = parent->legacy->connections_.begin();
@ -1698,25 +1771,26 @@ public:
} else if (parent->type == ID($not)) {
return parent->not_.connections()[position];
} else {
log_assert(false && "unreachable");
__builtin_unreachable();
}
}
iterator begin() const {
return iterator(parent, 0);
}
iterator end() const {
if (parent->is_legacy()) {
return iterator(parent, parent->legacy->connections_.size());
} else if (parent->type == ID($pos)) {
return iterator(parent, parent->pos.connections().size());
} else if (parent->type == ID($neg)) {
return iterator(parent, parent->neg.connections().size());
} else if (parent->type == ID($not)) {
return iterator(parent, parent->not_.connections().size());
log_assert(false && "malformed cell or code broke");
}
}
};
const_iterator begin() const {
return const_iterator(parent, 0);
}
const_iterator end() const {
if (parent->is_legacy()) {
return const_iterator(parent, parent->legacy->connections_.size());
} else if (parent->type == ID($pos)) {
return const_iterator(parent, parent->pos.connections().size());
} else if (parent->type == ID($neg)) {
return const_iterator(parent, parent->neg.connections().size());
} else if (parent->type == ID($not)) {
return const_iterator(parent, parent->not_.connections().size());
} else {
log_assert(false && "malformed cell or code broke");
}
}
};
FakeParams parameters;
FakeConns connections_;
@ -1728,14 +1802,32 @@ public:
};
// The weird bits
bool has_memid() { return is_legacy() && legacy->has_memid(); }
bool is_mem_cell() { return is_legacy() && legacy->is_mem_cell(); }
// TODO stub
void set_src_attribute(const std::string &src) { };
constexpr void setPort(const RTLIL::IdString &portname, RTLIL::SigSpec signal);
constexpr const RTLIL::SigSpec &getPort(const RTLIL::IdString &portname);
constexpr void setParam(const RTLIL::IdString &paramname, RTLIL::Const value);
constexpr const RTLIL::Const getParam(const RTLIL::IdString &paramname);
void setPort(const RTLIL::IdString &portname, RTLIL::SigSpec signal);
const RTLIL::SigSpec &getPort(const RTLIL::IdString &portname);
void setParam(const RTLIL::IdString &paramname, RTLIL::Const value);
const RTLIL::Const getParam(const RTLIL::IdString &paramname);
bool hasParam(const RTLIL::IdString &paramname) {
return parameters.count(paramname);
}
template<typename T>
void rewrite_sigspecs2(T &functor) {
for (auto &it : connections_)
functor(it.second);
}
template<typename T>
void rewrite_sigspecs(T &functor) {
for (auto &it : connections_)
functor(it.second);
}
void sort() {
if (is_legacy()) legacy->sort();
}
private:
// NOT the tag, but a helper - faster short-circuit if public?