Refactor IdString::global_ctx
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
b908b02022
commit
25f07549a1
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
BaseCtx *IdString::global_ctx = nullptr;
|
std::unordered_set<BaseCtx*> IdString::global_ctx;
|
||||||
|
|
||||||
void IdString::set(const BaseCtx *ctx, const std::string &s)
|
void IdString::set(const BaseCtx *ctx, const std::string &s)
|
||||||
{
|
{
|
||||||
|
@ -50,8 +50,6 @@ struct IdString
|
|||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
static BaseCtx *global_ctx;
|
|
||||||
|
|
||||||
static void initialize_arch(const BaseCtx *ctx);
|
static void initialize_arch(const BaseCtx *ctx);
|
||||||
static void initialize_add(const BaseCtx *ctx, const char *s, int idx);
|
static void initialize_add(const BaseCtx *ctx, const char *s, int idx);
|
||||||
|
|
||||||
@ -76,10 +74,12 @@ struct IdString
|
|||||||
|
|
||||||
// --- deprecated old API ---
|
// --- deprecated old API ---
|
||||||
|
|
||||||
|
static std::unordered_set<BaseCtx*> global_ctx;
|
||||||
|
|
||||||
const std::string &global_str() const __attribute__((deprecated))
|
const std::string &global_str() const __attribute__((deprecated))
|
||||||
{
|
{
|
||||||
assert(global_ctx != nullptr);
|
assert(global_ctx.size() == 1);
|
||||||
return str(global_ctx);
|
return str(*global_ctx.begin());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -204,8 +204,7 @@ struct BaseCtx
|
|||||||
|
|
||||||
BaseCtx()
|
BaseCtx()
|
||||||
{
|
{
|
||||||
// assert(IdString::global_ctx == nullptr);
|
IdString::global_ctx.insert(this);
|
||||||
IdString::global_ctx = this;
|
|
||||||
|
|
||||||
idstring_str_to_idx = new std::unordered_map<std::string, int>;
|
idstring_str_to_idx = new std::unordered_map<std::string, int>;
|
||||||
idstring_idx_to_str = new std::vector<const std::string *>;
|
idstring_idx_to_str = new std::vector<const std::string *>;
|
||||||
@ -215,6 +214,7 @@ struct BaseCtx
|
|||||||
|
|
||||||
~BaseCtx()
|
~BaseCtx()
|
||||||
{
|
{
|
||||||
|
IdString::global_ctx.erase(this);
|
||||||
delete idstring_str_to_idx;
|
delete idstring_str_to_idx;
|
||||||
delete idstring_idx_to_str;
|
delete idstring_idx_to_str;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user