Add fast IdString <-> PortPin conversion
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
7e879953d6
commit
9c275d0a65
@ -28,7 +28,15 @@ void IdString::initialize()
|
|||||||
{
|
{
|
||||||
database_str_to_idx = new std::unordered_map<std::string, int>;
|
database_str_to_idx = new std::unordered_map<std::string, int>;
|
||||||
database_idx_to_str = new std::vector<const std::string*>;
|
database_idx_to_str = new std::vector<const std::string*>;
|
||||||
auto insert_rc = database_str_to_idx->insert({std::string(), 0});
|
initialize_add("", 0);
|
||||||
|
initialize_chip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IdString::initialize_add(const char *s, int idx)
|
||||||
|
{
|
||||||
|
assert(database_str_to_idx->count(s) == 0);
|
||||||
|
assert(database_idx_to_str->size() == idx);
|
||||||
|
auto insert_rc = database_str_to_idx->insert({s, idx});
|
||||||
database_idx_to_str->push_back(&insert_rc.first->first);
|
database_idx_to_str->push_back(&insert_rc.first->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,9 @@ struct IdString
|
|||||||
static std::unordered_map<std::string, int> *database_str_to_idx;
|
static std::unordered_map<std::string, int> *database_str_to_idx;
|
||||||
static std::vector<const std::string*> *database_idx_to_str;
|
static std::vector<const std::string*> *database_idx_to_str;
|
||||||
|
|
||||||
void initialize();
|
static void initialize();
|
||||||
|
static void initialize_chip();
|
||||||
|
static void initialize_add(const char *s, int idx);
|
||||||
|
|
||||||
IdString() {}
|
IdString() {}
|
||||||
|
|
||||||
|
@ -24,6 +24,9 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
Chip::Chip(ChipArgs) {}
|
Chip::Chip(ChipArgs) {}
|
||||||
|
|
||||||
std::string Chip::getChipName() { return "Dummy"; }
|
std::string Chip::getChipName() { return "Dummy"; }
|
||||||
|
|
||||||
|
void IdString::initialize_chip() {}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
BelId Chip::getBelByName(IdString name) const { return BelId(); }
|
BelId Chip::getBelByName(IdString name) const { return BelId(); }
|
||||||
|
@ -52,27 +52,25 @@ BelType belTypeFromId(IdString id)
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
void IdString::initialize_chip()
|
||||||
|
{
|
||||||
|
#define X(t) initialize_add(#t, PIN_##t);
|
||||||
|
#include "portpins.inc"
|
||||||
|
#undef X
|
||||||
|
}
|
||||||
|
|
||||||
IdString portPinToId(PortPin type)
|
IdString portPinToId(PortPin type)
|
||||||
{
|
{
|
||||||
#define X(t) \
|
IdString ret;
|
||||||
if (type == PIN_##t) \
|
if (type > 0 && type < PIN_MAXIDX)
|
||||||
return #t;
|
ret.index = type;
|
||||||
|
return ret;
|
||||||
#include "portpins.inc"
|
|
||||||
|
|
||||||
#undef X
|
|
||||||
return IdString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PortPin portPinFromId(IdString id)
|
PortPin portPinFromId(IdString id)
|
||||||
{
|
{
|
||||||
#define X(t) \
|
if (id.index > 0 && id.index < PIN_MAXIDX)
|
||||||
if (id == #t) \
|
return PortPin(id.index);
|
||||||
return PIN_##t;
|
|
||||||
|
|
||||||
#include "portpins.inc"
|
|
||||||
|
|
||||||
#undef X
|
|
||||||
return PIN_NONE;
|
return PIN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ enum PortPin
|
|||||||
#define X(t) PIN_##t,
|
#define X(t) PIN_##t,
|
||||||
#include "portpins.inc"
|
#include "portpins.inc"
|
||||||
#undef X
|
#undef X
|
||||||
|
PIN_MAXIDX
|
||||||
};
|
};
|
||||||
|
|
||||||
IdString portPinToId(PortPin type);
|
IdString portPinToId(PortPin type);
|
||||||
|
Loading…
Reference in New Issue
Block a user