3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-20 22:25:49 +00:00

WIP migration to twine

This commit is contained in:
Emil J. Tywoniak 2026-06-18 19:27:41 +02:00
parent 96b0ba9581
commit 0c450ce8c8
110 changed files with 1225 additions and 1082 deletions

View file

@ -83,6 +83,8 @@ Wire* Patch::commit_wire(std::unique_ptr<Wire> wire) {
Wire* raw = wire.release();
TwineRef id = twine_staging.resolve(staged_wire_names_.at(raw));
staged_wire_names_.erase(raw);
if (!raw->meta_)
raw->meta_ = mod->design->alloc_obj_meta();
raw->meta_->name = id;
mod->wires_[raw->meta_->name] = raw;
raw->module = mod;
@ -93,9 +95,15 @@ Cell* Patch::commit_cell(std::unique_ptr<Cell> cell) {
Cell* raw = cell.release();
TwineRef id = twine_staging.resolve(staged_cell_names_.at(raw));
staged_cell_names_.erase(raw);
if (!raw->meta_)
raw->meta_ = mod->design->alloc_obj_meta();
raw->meta_->name = id;
raw->module = mod;
mod->cells_[raw->meta_->name] = raw;
if (auto it = staged_cell_src_.find(raw); it != staged_cell_src_.end()) {
raw->set_src_attribute(twine_staging.resolve(it->second));
staged_cell_src_.erase(it);
}
raw->initIndex();
return raw;
}

View file

@ -28,6 +28,7 @@ public:
vector<std::unique_ptr<Cell>> cells_ = {};
TwineChildPool twine_staging;
dict<RTLIL::Cell*, TwineRef> staged_cell_names_;
dict<RTLIL::Cell*, TwineRef> staged_cell_src_;
dict<RTLIL::Wire*, TwineRef> staged_wire_names_;
dict<const std::string*, TwineRef> staged_prefix_cache_;
@ -80,6 +81,13 @@ public:
RTLIL::Cell *addCell(Twine &&name, TwineRef type);
RTLIL::Cell *addCell(TwineRef name, Twine &&type);
// CellAdderMixin hook: staged cells are detached, so record the src and
// apply it once the cell is committed (commit_cell), resolving it through
// twine_staging so the ref may be twine_staging-local (interned without
// touching the per-Design pool). patch()/patch_ports() may still override
// it via apply_src merging from the rewritten cell.
void cell_set_src(RTLIL::Cell *cell, TwineRef src) { if (src != Twine::Null) staged_cell_src_[cell] = src; }
// NEW_ID analog for twine names; see NEW_TWINE in yosys_common.h.
// Returned refs are twine_staging-local and die at the next commit.
TwineRef new_name(const std::string *prefix);