mirror of
https://github.com/YosysHQ/yosys
synced 2026-05-25 03:16:22 +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 *cell = new RTLIL::Cell;
|
||||
RTLIL::Cell *cell = new RTLIL::Cell(Cell::ConstructToken{});
|
||||
cell->name = std::move(name);
|
||||
cell->type = type;
|
||||
add(cell);
|
||||
|
|
@ -4243,7 +4243,7 @@ std::string RTLIL::Process::to_rtlil_str() const
|
|||
return f.str();
|
||||
}
|
||||
|
||||
RTLIL::Cell::Cell() : module(nullptr)
|
||||
RTLIL::Cell::Cell(RTLIL::Cell::ConstructToken) : module(nullptr)
|
||||
{
|
||||
static unsigned int hashidx_count = 123456789;
|
||||
hashidx_count = mkhash_xorshift(hashidx_count);
|
||||
|
|
|
|||
|
|
@ -2525,18 +2525,20 @@ struct RTLIL::Memory : public RTLIL::NamedObject
|
|||
|
||||
struct RTLIL::Cell : public RTLIL::NamedObject
|
||||
{
|
||||
private:
|
||||
struct ConstructToken { explicit ConstructToken() = default; };
|
||||
public:
|
||||
Hasher::hash_t hashidx_;
|
||||
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
|
||||
|
||||
public:
|
||||
// use module->addCell() and module->remove() to create or destroy cells
|
||||
friend struct RTLIL::Module;
|
||||
friend struct RTLIL::Patch;
|
||||
Cell();
|
||||
Cell(ConstructToken);
|
||||
~Cell();
|
||||
|
||||
// do not simply copy cells
|
||||
Cell(RTLIL::Cell &other) = delete;
|
||||
Cell(ConstructToken, RTLIL::Cell &other);
|
||||
void operator=(RTLIL::Cell &other) = delete;
|
||||
|
||||
RTLIL::Module *module;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ YOSYS_NAMESPACE_BEGIN
|
|||
|
||||
using namespace RTLIL;
|
||||
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.type = type;
|
||||
return &cell;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue