3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-15 03:35:40 +00:00

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

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