From ef4ed3ef15b9d638d3327f759bd6876881121298 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Mon, 22 Jun 2026 00:29:11 +0200 Subject: [PATCH] twine: auto type WIP --- Makefile | 24 ++++++++++++++++++++++++ kernel/rtlil.cc | 23 ++++++++++++++++------- kernel/twine.h | 17 ++++++++++++++++- kernel/yosys_common.h | 8 ++++---- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index b7b4eeab6..0c435bc64 100644 --- a/Makefile +++ b/Makefile @@ -722,10 +722,25 @@ OBJS += libs/subcircuit/subcircuit.o include $(YOSYS_SRC)/kernel/unstable/Makefile.inc +ifeq ($(SKIP_BROKEN),1) +# Expanded build: pull in every pass/backend/frontend/techlib; objects that +# still fail to compile are listed in broken_objs.mk and filtered from the link. include $(YOSYS_SRC)/frontends/*/Makefile.inc include $(YOSYS_SRC)/passes/*/Makefile.inc include $(YOSYS_SRC)/backends/*/Makefile.inc include $(YOSYS_SRC)/techlibs/*/Makefile.inc +else +# Curated migration build (default): only the dirs known to compile+link. +include $(YOSYS_SRC)/frontends/*/Makefile.inc +include $(YOSYS_SRC)/passes/cmds/Makefile.inc +include $(YOSYS_SRC)/passes/hierarchy/Makefile.inc +include $(YOSYS_SRC)/passes/memory/Makefile.inc +include $(YOSYS_SRC)/passes/opt/Makefile.inc +include $(YOSYS_SRC)/passes/proc/Makefile.inc +include $(YOSYS_SRC)/passes/tests/Makefile.inc +include $(YOSYS_SRC)/backends/rtlil/Makefile.inc +include $(YOSYS_SRC)/backends/verilog/Makefile.inc +endif else @@ -785,6 +800,14 @@ share: $(EXTRA_TARGETS) @echo " Share directory created." @echo "" +# SKIP_BROKEN=1 drops the objects listed in broken_objs.mk from the link, so a +# full (non-SMALL) build can produce a working binary while some TUs still fail +# to compile. Regenerate broken_objs.mk as files get fixed. +ifeq ($(SKIP_BROKEN),1) +-include $(YOSYS_SRC)/broken_objs.mk +OBJS := $(filter-out $(BROKEN_OBJS),$(OBJS)) +endif + $(PROGRAM_PREFIX)yosys$(EXE): $(OBJS) $(P) $(CXX) -o $(PROGRAM_PREFIX)yosys$(EXE) $(EXE_LINKFLAGS) $(LINKFLAGS) $(OBJS) $(EXE_LIBS) $(LIBS) $(LIBS_VERIFIC) @@ -1103,6 +1126,7 @@ docs: docs/prep clean: clean-py clean-unit-test rm -rf share rm -f $(OBJS) $(GENFILES) $(TARGETS) $(EXTRA_TARGETS) $(EXTRA_OBJS) + find kernel frontends passes backends techlibs -name '*.o' -delete rm -f kernel/version_*.o kernel/version_*.cc rm -f libs/*/*.d frontends/*/*.d passes/*/*.d backends/*/*.d kernel/*.d techlibs/*/*.d rm -rf vloghtb/Makefile vloghtb/refdat vloghtb/rtl vloghtb/scripts vloghtb/spec vloghtb/check_yosys vloghtb/vloghammer_tb.tar.bz2 vloghtb/temp vloghtb/log_test_* diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 250528841..ecb784732 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -3797,15 +3797,24 @@ RTLIL::Cell *RTLIL::Module::addCell(Twine name, Twine type) RTLIL::Cell *RTLIL::Module::addCell(TwineRef name, const RTLIL::Cell *other) { - RTLIL::Cell *cell = addCell(name, other->type_impl); - cell->connections_ = other->connections_; + const RTLIL::Design *src_design = other->module ? other->module->design : nullptr; + bool cross_pool = src_design && this->design && src_design != this->design; + + TwineRef type = other->type_impl; + if (cross_pool) + type = this->design->twines.copy_from(src_design->twines, other->type_impl); + + RTLIL::Cell *cell = addCell(name, type); + if (cross_pool) { + for (auto &c : other->connections_) + cell->connections_[this->design->twines.copy_from(src_design->twines, c.first)] = c.second; + } else { + cell->connections_ = other->connections_; + } cell->parameters = other->parameters; cell->attributes = other->attributes; - { - const RTLIL::Design *src_design = other->module ? other->module->design : nullptr; - if (src_design && this->design) - copy_src_into(other, src_design, cell, this->design); - } + if (src_design && this->design) + copy_src_into(other, src_design, cell, this->design); return cell; } diff --git a/kernel/twine.h b/kernel/twine.h index 8f9372061..8fb4cf2c4 100644 --- a/kernel/twine.h +++ b/kernel/twine.h @@ -120,12 +120,19 @@ struct Twine { auto operator<=>(const Suffix&) const = default; }; - std::variant, Suffix> data; + struct AutoPrefix { + const std::string *prefix; + std::string tail; + auto operator<=>(const AutoPrefix&) const = default; + }; + + std::variant, Suffix, AutoPrefix> data; bool is_dead() const { return std::holds_alternative(data); } bool is_leaf() const { return std::holds_alternative(data); } bool is_concat() const { return std::holds_alternative>(data); } bool is_suffix() const { return std::holds_alternative(data); } + bool is_auto_prefix() const { return std::holds_alternative(data); } bool is_flat() const { return is_leaf() || is_suffix(); } const std::string &leaf() const { return std::get(data); } const std::vector &children() const { return std::get>(data); } @@ -363,6 +370,10 @@ struct TwinePool { // and tag publicity themselves (or use the add(std::string) overload). // Suffix names inherit the prefix handle's publicity. TwineRef add(Twine t) { + if (auto *ap = std::get_if(&t.data)) { + TwineRef pref = add_inner(Twine{*ap->prefix}); + return add_inner(Twine{Twine::Suffix{pref, std::move(ap->tail)}}); + } bool is_public = false; if (auto *sfx = std::get_if(&t.data)) { is_public = twine_is_public(sfx->prefix); @@ -649,6 +660,10 @@ struct TwineChildPool { // Local analog of TwinePool::add; see there for the convention. TwineRef add(Twine t) { + if (auto *ap = std::get_if(&t.data)) { + TwineRef pref = add_inner(Twine{*ap->prefix}); + return add_inner(Twine{Twine::Suffix{pref, std::move(ap->tail)}}); + } bool is_public = false; if (auto *leaf = std::get_if(&t.data)) { assert(!leaf->empty()); diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index 11197052d..00da6cf0e 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -305,15 +305,15 @@ RTLIL::IdString new_id_suffix(std::string_view file, int line, std::string_view #define NEW_ID_SUFFIX(suffix) \ YOSYS_NAMESPACE_PREFIX new_id_suffix(__FILE__, __LINE__, __FUNCTION__, suffix) #define NEW_TWINE \ - YOSYS_NAMESPACE_PREFIX Twine{*[](std::string_view func) -> const std::string * { \ + YOSYS_NAMESPACE_PREFIX Twine{YOSYS_NAMESPACE_PREFIX Twine::AutoPrefix{[](std::string_view func) -> const std::string * { \ static std::unique_ptr prefix(YOSYS_NAMESPACE_PREFIX create_id_prefix(__FILE__, __LINE__, func)); \ return prefix.get(); \ - }(__FUNCTION__) + std::to_string(YOSYS_NAMESPACE_PREFIX autoidx++)} + }(__FUNCTION__), std::to_string(YOSYS_NAMESPACE_PREFIX autoidx++)}} #define NEW_TWINE_SUFFIX(suffix) \ - YOSYS_NAMESPACE_PREFIX Twine{*[](std::string_view func) -> const std::string * { \ + YOSYS_NAMESPACE_PREFIX Twine{YOSYS_NAMESPACE_PREFIX Twine::AutoPrefix{[](std::string_view func) -> const std::string * { \ static std::unique_ptr prefix(YOSYS_NAMESPACE_PREFIX create_id_prefix(__FILE__, __LINE__, func)); \ return prefix.get(); \ - }(__FUNCTION__) + std::string(suffix) + "$" + std::to_string(YOSYS_NAMESPACE_PREFIX autoidx++)} + }(__FUNCTION__), std::string(suffix) + "$" + std::to_string(YOSYS_NAMESPACE_PREFIX autoidx++)}} namespace ID = RTLIL::ID;