mirror of
https://github.com/YosysHQ/yosys
synced 2026-07-20 14:15:49 +00:00
twine: start indexable colony with integer indices including preallocated twines
This commit is contained in:
parent
8ab96a4285
commit
015ab4e45b
7 changed files with 482 additions and 696 deletions
|
|
@ -3,43 +3,24 @@
|
|||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
// std::vector<Twine> TwinePool::globals_;
|
||||
constexpr inline std::array<Twine, STATIC_ID_END> globals_;
|
||||
std::vector<Twine> TwinePool::globals_;
|
||||
|
||||
TwineRef twine_populate(std::string name) {
|
||||
if (name[1] == '$') {
|
||||
// Skip prepended '\'
|
||||
name = name.substr(1);
|
||||
}
|
||||
TwinePool::globals_.push_back(Twine(name));
|
||||
return &TwinePool::globals_.back();
|
||||
TwinePool::globals_.push_back(Twine{std::move(name)});
|
||||
return TwinePool::globals_.size() - 1;
|
||||
}
|
||||
void twine_prepopulate() {
|
||||
int size = static_cast<short>(RTLIL::StaticId::STATIC_ID_END);
|
||||
TwinePool::globals_.reserve(size);
|
||||
TwinePool::globals_.push_back(Twine(""));
|
||||
TwinePool::globals_.reserve(STATIC_TWINE_END);
|
||||
TwinePool::globals_.push_back(Twine{std::string()});
|
||||
#define X(_id) twine_populate("\\" #_id);
|
||||
#include "kernel/constids.inc"
|
||||
#undef X
|
||||
}
|
||||
|
||||
#define X(N) constexpr TW TW::N{IDX_##N};
|
||||
#include "kernel/constids.inc"
|
||||
#undef X
|
||||
|
||||
TW::EnumType static_to_offset(TwineRef ref); {
|
||||
size_t offset = ref - &TwinePool::globals_.front();
|
||||
log_assert(offset > STATIC_TWINE_BEGIN);
|
||||
log_assert(offset < STATIC_TWINE_END);
|
||||
return (TW::EnumType)offset;
|
||||
}
|
||||
|
||||
TwineRef offset_to_static(TW::EnumType offset) {
|
||||
log_assert(offset > STATIC_TWINE_BEGIN);
|
||||
log_assert(offset < STATIC_TWINE_END);
|
||||
return &TwinePool::globals_[offset];
|
||||
}
|
||||
|
||||
// enum : short
|
||||
// {
|
||||
// STATIC_ID_BEGIN = 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue