mirror of
https://github.com/YosysHQ/yosys
synced 2026-06-02 15:18:07 +00:00
rtlil: allow friends to use Cell constructors with a factory token pattern
This commit is contained in:
parent
b3f605e0d2
commit
3e6b740430
3 changed files with 8 additions and 6 deletions
|
|
@ -3129,7 +3129,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 *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
|
||||||
{
|
{
|
||||||
RTLIL::Cell *cell = new RTLIL::Cell;
|
RTLIL::Cell *cell = new RTLIL::Cell(Cell::ConstructToken{});
|
||||||
cell->name = std::move(name);
|
cell->name = std::move(name);
|
||||||
cell->type = type;
|
cell->type = type;
|
||||||
add(cell);
|
add(cell);
|
||||||
|
|
@ -4243,7 +4243,7 @@ std::string RTLIL::Process::to_rtlil_str() const
|
||||||
return f.str();
|
return f.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
RTLIL::Cell::Cell() : module(nullptr)
|
RTLIL::Cell::Cell(RTLIL::Cell::ConstructToken) : module(nullptr)
|
||||||
{
|
{
|
||||||
static unsigned int hashidx_count = 123456789;
|
static unsigned int hashidx_count = 123456789;
|
||||||
hashidx_count = mkhash_xorshift(hashidx_count);
|
hashidx_count = mkhash_xorshift(hashidx_count);
|
||||||
|
|
|
||||||
|
|
@ -2525,18 +2525,20 @@ struct RTLIL::Memory : public RTLIL::NamedObject
|
||||||
|
|
||||||
struct RTLIL::Cell : public RTLIL::NamedObject
|
struct RTLIL::Cell : public RTLIL::NamedObject
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
struct ConstructToken { explicit ConstructToken() = default; };
|
||||||
|
public:
|
||||||
Hasher::hash_t hashidx_;
|
Hasher::hash_t hashidx_;
|
||||||
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
|
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
|
||||||
|
|
||||||
public:
|
|
||||||
// use module->addCell() and module->remove() to create or destroy cells
|
// use module->addCell() and module->remove() to create or destroy cells
|
||||||
friend struct RTLIL::Module;
|
friend struct RTLIL::Module;
|
||||||
friend struct RTLIL::Patch;
|
friend struct RTLIL::Patch;
|
||||||
Cell();
|
Cell(ConstructToken);
|
||||||
~Cell();
|
~Cell();
|
||||||
|
|
||||||
// do not simply copy cells
|
// do not simply copy cells
|
||||||
Cell(RTLIL::Cell &other) = delete;
|
Cell(ConstructToken, RTLIL::Cell &other);
|
||||||
void operator=(RTLIL::Cell &other) = delete;
|
void operator=(RTLIL::Cell &other) = delete;
|
||||||
|
|
||||||
RTLIL::Module *module;
|
RTLIL::Module *module;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
using namespace RTLIL;
|
using namespace RTLIL;
|
||||||
Cell* Patch::addCell(IdString name, IdString type) {
|
Cell* Patch::addCell(IdString name, IdString type) {
|
||||||
auto& cell = cells_.emplace_back();
|
auto& cell = cells_.emplace_back(Cell::ConstructToken{});
|
||||||
cell.name = std::move(name);
|
cell.name = std::move(name);
|
||||||
cell.type = type;
|
cell.type = type;
|
||||||
return &cell;
|
return &cell;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue