mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-04 21:39:14 +00:00
Remove StaticIdString and just use IdString now that we can make it constexpr
This commit is contained in:
parent
3c2caffffe
commit
5cc3f27a5f
2 changed files with 9 additions and 40 deletions
|
|
@ -42,10 +42,6 @@ std::unordered_map<int, int> RTLIL::IdString::global_refcount_storage_;
|
||||||
std::vector<int> RTLIL::IdString::global_free_idx_list_;
|
std::vector<int> RTLIL::IdString::global_free_idx_list_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define X(_id) const RTLIL::OwningIdString RTLIL::IDInternal::_id(RTLIL::StaticId::_id);
|
|
||||||
#include "kernel/constids.inc"
|
|
||||||
#undef X
|
|
||||||
|
|
||||||
static void populate(std::string_view name)
|
static void populate(std::string_view name)
|
||||||
{
|
{
|
||||||
if (name[1] == '$') {
|
if (name[1] == '$') {
|
||||||
|
|
|
||||||
|
|
@ -120,20 +120,9 @@ namespace RTLIL
|
||||||
struct Process;
|
struct Process;
|
||||||
struct Binding;
|
struct Binding;
|
||||||
struct IdString;
|
struct IdString;
|
||||||
struct StaticIdString;
|
|
||||||
struct OwningIdString;
|
struct OwningIdString;
|
||||||
|
|
||||||
typedef std::pair<SigSpec, SigSpec> SigSig;
|
typedef std::pair<SigSpec, SigSpec> SigSig;
|
||||||
|
|
||||||
struct StaticIdString {
|
|
||||||
constexpr StaticIdString(StaticId id, const OwningIdString &id_str) : id_str(id_str), id(id) {}
|
|
||||||
constexpr inline operator const OwningIdString &() const { return id_str; }
|
|
||||||
constexpr inline int index() const { return static_cast<short>(id); }
|
|
||||||
constexpr inline const OwningIdString &id_string() const { return id_str; }
|
|
||||||
|
|
||||||
const OwningIdString &id_str;
|
|
||||||
const StaticId id;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RTLIL::IdString
|
struct RTLIL::IdString
|
||||||
|
|
@ -246,13 +235,13 @@ struct RTLIL::IdString
|
||||||
|
|
||||||
int index_;
|
int index_;
|
||||||
|
|
||||||
inline IdString() : index_(0) { }
|
constexpr inline IdString() : index_(0) { }
|
||||||
inline IdString(const char *str) : index_(insert(std::string_view(str))) { }
|
inline IdString(const char *str) : index_(insert(std::string_view(str))) { }
|
||||||
inline IdString(const IdString &str) : index_(str.index_) { }
|
constexpr inline IdString(const IdString &str) : index_(str.index_) { }
|
||||||
inline IdString(IdString &&str) : index_(str.index_) { str.index_ = 0; }
|
inline IdString(IdString &&str) : index_(str.index_) { str.index_ = 0; }
|
||||||
inline IdString(const std::string &str) : index_(insert(std::string_view(str))) { }
|
inline IdString(const std::string &str) : index_(insert(std::string_view(str))) { }
|
||||||
inline IdString(std::string_view str) : index_(insert(str)) { }
|
inline IdString(std::string_view str) : index_(insert(str)) { }
|
||||||
inline IdString(StaticId id) : index_(static_cast<short>(id)) {}
|
constexpr inline IdString(StaticId id) : index_(static_cast<short>(id)) {}
|
||||||
|
|
||||||
IdString &operator=(const IdString &rhs) = default;
|
IdString &operator=(const IdString &rhs) = default;
|
||||||
|
|
||||||
|
|
@ -288,8 +277,6 @@ struct RTLIL::IdString
|
||||||
|
|
||||||
inline bool operator==(const IdString &rhs) const { return index_ == rhs.index_; }
|
inline bool operator==(const IdString &rhs) const { return index_ == rhs.index_; }
|
||||||
inline bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; }
|
inline bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; }
|
||||||
inline bool operator==(const StaticIdString &rhs) const;
|
|
||||||
inline bool operator!=(const StaticIdString &rhs) const;
|
|
||||||
|
|
||||||
// The methods below are just convenience functions for better compatibility with std::string.
|
// The methods below are just convenience functions for better compatibility with std::string.
|
||||||
|
|
||||||
|
|
@ -374,7 +361,6 @@ struct RTLIL::IdString
|
||||||
}
|
}
|
||||||
|
|
||||||
bool in(const IdString &rhs) const { return *this == rhs; }
|
bool in(const IdString &rhs) const { return *this == rhs; }
|
||||||
bool in(const StaticIdString &rhs) const { return *this == rhs; }
|
|
||||||
bool in(const char *rhs) const { return *this == rhs; }
|
bool in(const char *rhs) const { return *this == rhs; }
|
||||||
bool in(const std::string &rhs) const { return *this == rhs; }
|
bool in(const std::string &rhs) const { return *this == rhs; }
|
||||||
inline bool in(const pool<IdString> &rhs) const;
|
inline bool in(const pool<IdString> &rhs) const;
|
||||||
|
|
@ -394,7 +380,6 @@ public:
|
||||||
|
|
||||||
struct RTLIL::OwningIdString : public RTLIL::IdString {
|
struct RTLIL::OwningIdString : public RTLIL::IdString {
|
||||||
inline OwningIdString() { }
|
inline OwningIdString() { }
|
||||||
inline OwningIdString(const StaticIdString &str) : IdString(str) { }
|
|
||||||
inline OwningIdString(const OwningIdString &str) : IdString(str) { get_reference(); }
|
inline OwningIdString(const OwningIdString &str) : IdString(str) { get_reference(); }
|
||||||
inline OwningIdString(const char *str) : IdString(str) { get_reference(); }
|
inline OwningIdString(const char *str) : IdString(str) { get_reference(); }
|
||||||
inline OwningIdString(const IdString &str) : IdString(str) { get_reference(); }
|
inline OwningIdString(const IdString &str) : IdString(str) { get_reference(); }
|
||||||
|
|
@ -502,21 +487,9 @@ inline bool RTLIL::IdString::in(const pool<IdString> &rhs) const { return rhs.co
|
||||||
[[deprecated]]
|
[[deprecated]]
|
||||||
inline bool RTLIL::IdString::in(const pool<IdString> &&rhs) const { return rhs.count(*this) != 0; }
|
inline bool RTLIL::IdString::in(const pool<IdString> &&rhs) const { return rhs.count(*this) != 0; }
|
||||||
|
|
||||||
inline bool RTLIL::IdString::operator==(const RTLIL::StaticIdString &rhs) const {
|
|
||||||
return index_ == rhs.index();
|
|
||||||
}
|
|
||||||
inline bool RTLIL::IdString::operator!=(const RTLIL::StaticIdString &rhs) const {
|
|
||||||
return index_ != rhs.index();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace RTLIL {
|
namespace RTLIL {
|
||||||
namespace IDInternal {
|
|
||||||
#define X(_id) extern const OwningIdString _id;
|
|
||||||
#include "kernel/constids.inc"
|
|
||||||
#undef X
|
|
||||||
}
|
|
||||||
namespace ID {
|
namespace ID {
|
||||||
#define X(_id) constexpr StaticIdString _id(StaticId::_id, IDInternal::_id);
|
#define X(_id) constexpr IdString _id(StaticId::_id);
|
||||||
#include "kernel/constids.inc"
|
#include "kernel/constids.inc"
|
||||||
#undef X
|
#undef X
|
||||||
}
|
}
|
||||||
|
|
@ -524,7 +497,7 @@ namespace RTLIL {
|
||||||
|
|
||||||
struct IdTableEntry {
|
struct IdTableEntry {
|
||||||
const std::string_view name;
|
const std::string_view name;
|
||||||
const RTLIL::StaticIdString static_id;
|
const RTLIL::IdString static_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr IdTableEntry IdTable[] = {
|
constexpr IdTableEntry IdTable[] = {
|
||||||
|
|
@ -557,15 +530,15 @@ constexpr int lookup_well_known_id(std::string_view name)
|
||||||
//
|
//
|
||||||
// sed -i.orig -r 's/"\\\\([a-zA-Z0-9_]+)"/ID(\1)/g; s/"(\$[a-zA-Z0-9_]+)"/ID(\1)/g;' <filename>
|
// sed -i.orig -r 's/"\\\\([a-zA-Z0-9_]+)"/ID(\1)/g; s/"(\$[a-zA-Z0-9_]+)"/ID(\1)/g;' <filename>
|
||||||
//
|
//
|
||||||
typedef const RTLIL::IdString &IDMacroHelperFunc();
|
typedef RTLIL::IdString IDMacroHelperFunc();
|
||||||
|
|
||||||
template <int IdTableIndex> struct IDMacroHelper {
|
template <int IdTableIndex> struct IDMacroHelper {
|
||||||
static constexpr RTLIL::StaticIdString eval(IDMacroHelperFunc) {
|
static constexpr RTLIL::IdString eval(IDMacroHelperFunc) {
|
||||||
return IdTable[IdTableIndex].static_id;
|
return IdTable[IdTableIndex].static_id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template <> struct IDMacroHelper<-1> {
|
template <> struct IDMacroHelper<-1> {
|
||||||
static constexpr const RTLIL::IdString &eval(IDMacroHelperFunc func) {
|
static constexpr RTLIL::IdString eval(IDMacroHelperFunc func) {
|
||||||
return func();
|
return func();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -574,7 +547,7 @@ template <> struct IDMacroHelper<-1> {
|
||||||
YOSYS_NAMESPACE_PREFIX IDMacroHelper< \
|
YOSYS_NAMESPACE_PREFIX IDMacroHelper< \
|
||||||
YOSYS_NAMESPACE_PREFIX lookup_well_known_id(#_id) \
|
YOSYS_NAMESPACE_PREFIX lookup_well_known_id(#_id) \
|
||||||
>::eval([]() \
|
>::eval([]() \
|
||||||
-> const YOSYS_NAMESPACE_PREFIX RTLIL::IdString & { \
|
-> YOSYS_NAMESPACE_PREFIX RTLIL::IdString { \
|
||||||
const char *p = "\\" #_id, *q = p[1] == '$' ? p+1 : p; \
|
const char *p = "\\" #_id, *q = p[1] == '$' ? p+1 : p; \
|
||||||
static const YOSYS_NAMESPACE_PREFIX RTLIL::IdString id = \
|
static const YOSYS_NAMESPACE_PREFIX RTLIL::IdString id = \
|
||||||
YOSYS_NAMESPACE_PREFIX RTLIL::OwningIdString::immortal(q); \
|
YOSYS_NAMESPACE_PREFIX RTLIL::OwningIdString::immortal(q); \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue