twine: auto type WIP

This commit is contained in:
Emil J. Tywoniak 2026-06-22 00:29:11 +02:00
parent b27432326f
commit ef4ed3ef15
4 changed files with 60 additions and 12 deletions

View File

@ -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_*

View File

@ -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;
}

View File

@ -120,12 +120,19 @@ struct Twine {
auto operator<=>(const Suffix&) const = default;
};
std::variant<std::monostate, std::string, std::vector<TwineRef>, Suffix> data;
struct AutoPrefix {
const std::string *prefix;
std::string tail;
auto operator<=>(const AutoPrefix&) const = default;
};
std::variant<std::monostate, std::string, std::vector<TwineRef>, Suffix, AutoPrefix> data;
bool is_dead() const { return std::holds_alternative<std::monostate>(data); }
bool is_leaf() const { return std::holds_alternative<std::string>(data); }
bool is_concat() const { return std::holds_alternative<std::vector<TwineRef>>(data); }
bool is_suffix() const { return std::holds_alternative<Suffix>(data); }
bool is_auto_prefix() const { return std::holds_alternative<AutoPrefix>(data); }
bool is_flat() const { return is_leaf() || is_suffix(); }
const std::string &leaf() const { return std::get<std::string>(data); }
const std::vector<TwineRef> &children() const { return std::get<std::vector<TwineRef>>(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<Twine::AutoPrefix>(&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<Twine::Suffix>(&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<Twine::AutoPrefix>(&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<std::string>(&t.data)) {
assert(!leaf->empty());

View File

@ -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<const std::string> 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<const std::string> 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;