3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-15 11:45:41 +00:00

rtlil: fix masquerade

This commit is contained in:
Emil J. Tywoniak 2026-06-06 13:32:57 +02:00
parent 2d3b7e9c92
commit 1a8a95b472
11 changed files with 77 additions and 39 deletions

View file

@ -258,7 +258,8 @@ void RTLIL::OwningIdString::collect_garbage()
for (auto &[idx, design] : *RTLIL::Design::get_all_designs()) {
for (RTLIL::Module *module : design->modules()) {
collectors[0].trace_named(*module);
collectors[0].trace_keys(module->attributes);
collectors[0].trace(RTLIL::IdString(module->name));
ParallelDispatchThreadPool::Subpool subpool(thread_pool, ThreadPool::work_pool_size(0, module->cells_size(), 1000));
subpool.run([&collectors, module](const ParallelDispatchThreadPool::RunCtx &ctx) {
for (int i : ctx.item_range(module->cells_size()))
@ -3266,8 +3267,18 @@ RTLIL::Module *RTLIL::Module::clone(RTLIL::Design *dst, bool src_id_verbatim) co
RTLIL::Module *new_mod = new RTLIL::Module;
new_mod->design = dst;
new_mod->name = name;
dst->add(new_mod);
cloneInto(new_mod, src_id_verbatim);
dst->add(new_mod);
return new_mod;
}
RTLIL::Module *RTLIL::Module::clone(RTLIL::Design *dst, RTLIL::IdString target_name, bool src_id_verbatim) const
{
RTLIL::Module *new_mod = new RTLIL::Module;
new_mod->design = dst;
new_mod->name = target_name;
cloneInto(new_mod, src_id_verbatim);
dst->add(new_mod);
return new_mod;
}

View file

@ -2807,6 +2807,13 @@ public:
// still hits the (now-unused) inline base field. Writing requires
// module->design to be set first.
struct RTLIL::ModuleNameMasq {
// Copying/moving is forbidden: a ModuleNameMasq derives its identity from
// `this` via offsetof(Module, name), so any instance not embedded in a
// Module would resolve to garbage. All conversions go through
// operator IdString() at the embedded location.
ModuleNameMasq() = default;
ModuleNameMasq(const ModuleNameMasq&) = delete;
ModuleNameMasq(ModuleNameMasq&&) = delete;
operator RTLIL::IdString() const;
ModuleNameMasq& operator=(RTLIL::IdString id);
// Without this, `new_mod->name = src_mod->name` invokes the implicit
@ -2951,6 +2958,10 @@ public:
// preserve their type (AstModule). `src_id_verbatim` is forwarded to
// cloneInto.
virtual RTLIL::Module *clone(RTLIL::Design *dst, bool src_id_verbatim = false) const;
// As above, but additionally renames the new module to `target_name` in
// `dst`. Used when source and destination designs may contain modules
// with the same name and the new one must take a different identity.
virtual RTLIL::Module *clone(RTLIL::Design *dst, RTLIL::IdString target_name, bool src_id_verbatim = false) const;
bool has_memories() const;
bool has_processes() const;