mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-24 01:25:33 +00:00
$not now passes test_cell!
This commit is contained in:
parent
81f783bf62
commit
76102f0bc5
7 changed files with 108 additions and 33 deletions
|
@ -2212,14 +2212,15 @@ void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
|
|||
|
||||
void RTLIL::Module::remove(RTLIL::Cell *cell)
|
||||
{
|
||||
// TODO is this ok?
|
||||
// TODO monitors are broken when unsetPort is unused here
|
||||
// for
|
||||
// while (!cell->connections_.empty())
|
||||
// cell->unsetPort(cell->connections_.begin()->first);
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -2428,8 +2429,7 @@ RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, const RTLIL::Wire *oth
|
|||
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
|
||||
{
|
||||
RTLIL::Cell *cell = new RTLIL::Cell;
|
||||
std::cout << "RTLIL::Module::addCell " << name.c_str() << " " << type.c_str() << "to module " << this->name.c_str() << "\n";
|
||||
log("ptr 0x%016X\n", cell);
|
||||
// std::cout << "RTLIL::Module::addCell " << name.c_str() << " " << type.c_str() << "to module " << this->name.c_str() << "\n";
|
||||
cell->name = name;
|
||||
cell->type = type;
|
||||
if (RTLIL::Cell::is_legacy_type(type)) {
|
||||
|
@ -2459,7 +2459,6 @@ RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
|
|||
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, const RTLIL::Cell *other)
|
||||
{
|
||||
RTLIL::Cell *cell = addCell(name, other->type);
|
||||
cell->module = this;
|
||||
cell->connections_ = other->connections_;
|
||||
cell->parameters = other->parameters;
|
||||
cell->attributes = other->attributes;
|
||||
|
@ -3543,7 +3542,10 @@ void RTLIL::Cell::setPort(const RTLIL::IdString &portname, RTLIL::SigSpec signal
|
|||
}
|
||||
}
|
||||
|
||||
static const SigSpec discon_dummy;
|
||||
|
||||
const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &portname) const {
|
||||
// log("getPort this %d %s (%016X %016X)\n", this, portname.c_str(), &portname, portname.c_str());
|
||||
if (is_legacy())
|
||||
return legacy->getPort(portname);
|
||||
|
||||
|
@ -3553,7 +3555,7 @@ const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &portname) cons
|
|||
} else if (portname == ID::Y) {
|
||||
return not_.y;
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getPort()");
|
||||
}
|
||||
} else if (type == ID($pos)) {
|
||||
if (portname == ID::A) {
|
||||
|
@ -3561,7 +3563,7 @@ const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &portname) cons
|
|||
} else if (portname == ID::Y) {
|
||||
return pos.y;
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getPort()");
|
||||
}
|
||||
} else if (type == ID($neg)) {
|
||||
if (portname == ID::A) {
|
||||
|
@ -3569,10 +3571,10 @@ const RTLIL::SigSpec &RTLIL::Cell::getPort(const RTLIL::IdString &portname) cons
|
|||
} else if (portname == ID::Y) {
|
||||
return neg.y;
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getPort()");
|
||||
}
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getPort()");
|
||||
}
|
||||
}
|
||||
RTLIL::SigSpec &RTLIL::Cell::getMutPort(const RTLIL::IdString &portname) {
|
||||
|
@ -3585,7 +3587,7 @@ RTLIL::SigSpec &RTLIL::Cell::getMutPort(const RTLIL::IdString &portname) {
|
|||
} else if (portname == ID::Y) {
|
||||
return not_.y;
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getMutPort()");
|
||||
}
|
||||
} else if (type == ID($pos)) {
|
||||
if (portname == ID::A) {
|
||||
|
@ -3593,7 +3595,7 @@ RTLIL::SigSpec &RTLIL::Cell::getMutPort(const RTLIL::IdString &portname) {
|
|||
} else if (portname == ID::Y) {
|
||||
return pos.y;
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getMutPort()");
|
||||
}
|
||||
} else if (type == ID($neg)) {
|
||||
if (portname == ID::A) {
|
||||
|
@ -3601,10 +3603,10 @@ RTLIL::SigSpec &RTLIL::Cell::getMutPort(const RTLIL::IdString &portname) {
|
|||
} else if (portname == ID::Y) {
|
||||
return neg.y;
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getMutPort()");
|
||||
}
|
||||
} else {
|
||||
throw std::out_of_range("Cell::setPort()");
|
||||
throw std::out_of_range("Cell::getMutPort()");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3653,7 +3655,6 @@ void RTLIL::Cell::setParam(const RTLIL::IdString ¶mname, RTLIL::Const value)
|
|||
const RTLIL::Const& RTLIL::Cell::getParam(const RTLIL::IdString ¶mname) const {
|
||||
if (is_legacy())
|
||||
return legacy->getParam(paramname);
|
||||
log_debug("fr");
|
||||
|
||||
if (type == ID($not)) {
|
||||
if (paramname == ID::A_WIDTH) {
|
||||
|
|
|
@ -1707,7 +1707,7 @@ public:
|
|||
// 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) {
|
||||
log("operator[] on %s type %s\n", name.c_str(), parent->type.c_str());
|
||||
// log("operator[] on %s type %s\n", name.c_str(), parent->type.c_str());
|
||||
return parent->getMutParam(name);
|
||||
}
|
||||
void operator=(dict<IdString, Const> from) {
|
||||
|
@ -1724,6 +1724,26 @@ public:
|
|||
throw std::out_of_range("Cell::getParam()");
|
||||
}
|
||||
}
|
||||
void operator=(const FakeParams& from) {
|
||||
log_assert(parent->type == from.parent->type);
|
||||
|
||||
if (parent->is_legacy()) {
|
||||
log_assert(from.parent->is_legacy());
|
||||
parent->legacy->parameters = from.parent->legacy->parameters;
|
||||
// return;
|
||||
}
|
||||
auto this_it = begin();
|
||||
auto from_it = from.parent->parameters.begin();
|
||||
while (this_it != end() && from_it != from.parent->parameters.end()) {
|
||||
// Well-ordered
|
||||
log_assert((*this_it).first == (*from_it).first);
|
||||
(*this_it).second = (*from_it).second;
|
||||
++this_it;
|
||||
++from_it;
|
||||
}
|
||||
// Same params
|
||||
log_assert(this_it == this->end() && from_it == from.parent->parameters.end());
|
||||
}
|
||||
bool operator==(const FakeParams& other) const {
|
||||
auto this_it = this->begin();
|
||||
auto other_it = other.begin();
|
||||
|
@ -1742,7 +1762,7 @@ public:
|
|||
bool operator!=(const FakeParams& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
int count(RTLIL::IdString name) const {
|
||||
int count(const RTLIL::IdString& name) const {
|
||||
try {
|
||||
parent->getParam(name);
|
||||
} catch (const std::out_of_range& e) {
|
||||
|
@ -1952,12 +1972,14 @@ public:
|
|||
// but we rely on RTLIL::Cell always being constructed correctly
|
||||
// since its layout is fixed as defined by InternalOldCellChecker
|
||||
RTLIL::SigSpec& operator[](RTLIL::IdString portname) {
|
||||
log("operator[] on %s type %s\n", portname.c_str(), parent->type.c_str());
|
||||
// log("operator[] on %s type %s\n", portname.c_str(), parent->type.c_str());
|
||||
return parent->getMutPort(portname);
|
||||
}
|
||||
void operator=(dict<IdString, SigSpec> from) {
|
||||
if (parent->is_legacy())
|
||||
if (parent->is_legacy()) {
|
||||
parent->legacy->connections_ = from;
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent->type == ID($not)) {
|
||||
parent->not_.conns_from_dict(from);
|
||||
|
@ -1969,6 +1991,26 @@ public:
|
|||
throw std::out_of_range("Cell::getParam()");
|
||||
}
|
||||
}
|
||||
void operator=(const FakeConns& from) {
|
||||
log_assert(parent->type == from.parent->type);
|
||||
|
||||
if (parent->is_legacy()) {
|
||||
log_assert(from.parent->is_legacy());
|
||||
parent->legacy->connections_ = from.parent->legacy->connections_;
|
||||
// return;
|
||||
}
|
||||
auto this_it = begin();
|
||||
auto from_it = from.parent->connections_.begin();
|
||||
while (this_it != end() && from_it != from.parent->connections_.end()) {
|
||||
// Well-ordered
|
||||
log_assert((*this_it).first == (*from_it).first);
|
||||
(*this_it).second = (*from_it).second;
|
||||
++this_it;
|
||||
++from_it;
|
||||
}
|
||||
// Same params
|
||||
log_assert(this_it == this->end() && from_it == from.parent->connections_.end());
|
||||
}
|
||||
bool operator==(const FakeConns& other) const {
|
||||
auto this_it = this->begin();
|
||||
auto other_it = other.begin();
|
||||
|
@ -1987,12 +2029,15 @@ public:
|
|||
bool operator!=(const FakeConns& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
int count(RTLIL::IdString portname) const {
|
||||
int count(const RTLIL::IdString& portname) const {
|
||||
log("count this %d\n", this);
|
||||
try {
|
||||
parent->getPort(portname);
|
||||
} catch (const std::out_of_range& e) {
|
||||
log("count 0\n");
|
||||
return 0;
|
||||
}
|
||||
log("count 1\n");
|
||||
return 1;
|
||||
}
|
||||
size_t size() const {
|
||||
|
@ -2213,20 +2258,41 @@ public:
|
|||
const RTLIL::SigSpec &getPort(const RTLIL::IdString &portname) const;
|
||||
RTLIL::SigSpec &getMutPort(const RTLIL::IdString &portname);
|
||||
bool hasPort(const RTLIL::IdString &portname) const {
|
||||
// TODO hack?
|
||||
return connections_.count(portname) && !getPort(portname).empty();
|
||||
if (is_legacy()) {
|
||||
return legacy->hasPort(portname);
|
||||
} else if (type == ID($pos)) {
|
||||
return portname.in(ID::A, ID::Y) && !getPort(portname).empty();
|
||||
} else if (type == ID($neg)) {
|
||||
return portname.in(ID::A, ID::Y) && !getPort(portname).empty();
|
||||
} else if (type == ID($not)) {
|
||||
return portname.in(ID::A, ID::Y) && !getPort(portname).empty();
|
||||
} else {
|
||||
throw std::out_of_range("FakeParams::size()");
|
||||
}
|
||||
}
|
||||
void unsetPort(const RTLIL::IdString& portname) {
|
||||
if (is_legacy())
|
||||
legacy->unsetPort(portname);
|
||||
setPort(portname, SigSpec());
|
||||
}
|
||||
// The need for this function implies setPort will be used on incompat types
|
||||
void unsetPort(const RTLIL::IdString& portname) { (void)portname; }
|
||||
void setParam(const RTLIL::IdString ¶mname, RTLIL::Const value);
|
||||
// TODO is this reasonable at all?
|
||||
const RTLIL::Const& getParam(const RTLIL::IdString ¶mname) const;
|
||||
RTLIL::Const& getMutParam(const RTLIL::IdString ¶mname);
|
||||
bool hasParam(const RTLIL::IdString ¶mname) const {
|
||||
return parameters.count(paramname) && !getParam(paramname).empty();
|
||||
if (is_legacy()) {
|
||||
return legacy->hasParam(paramname);
|
||||
} else if (type.in(ID($pos), ID($neg), ID($not))) {
|
||||
return paramname.in(ID::A_WIDTH, ID::Y_WIDTH, ID::A_SIGNED) && !getParam(paramname).empty();
|
||||
} else {
|
||||
throw std::out_of_range("FakeParams::size()");
|
||||
}
|
||||
}
|
||||
void unsetParam(const RTLIL::IdString& paramname) {
|
||||
if (is_legacy())
|
||||
legacy->unsetParam(paramname);
|
||||
setPort(paramname, Const());
|
||||
}
|
||||
// The need for this function implies setPort will be used on incompat types
|
||||
void unsetParam(const RTLIL::IdString& paramname) { (void)paramname; }
|
||||
template<typename T>
|
||||
void rewrite_sigspecs2(T &functor) {
|
||||
// for(auto it = connections_.begin(); it != connections_.end(); ++it) {
|
||||
|
@ -2252,7 +2318,7 @@ public:
|
|||
private:
|
||||
// NOT the tag, but a helper - faster short-circuit if public?
|
||||
static bool is_legacy_type (RTLIL::IdString type) {
|
||||
return !type.in(ID($not), ID($pos), ID($neg));
|
||||
return !type.in(ID($not), ID($pos));
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue