nexus: Implement IdStringList for all arch object names
Signed-off-by: D. Shah <dave@ds0.me>
This commit is contained in:
parent
b31b21fd51
commit
6566a011b4
@ -181,6 +181,12 @@ template <typename T, size_t N> class SSOArray
|
||||
std::fill(begin(), end(), init);
|
||||
}
|
||||
|
||||
SSOArray(const SSOArray &other) : m_size(other.size())
|
||||
{
|
||||
alloc();
|
||||
std::copy(other.begin(), other.end(), begin());
|
||||
}
|
||||
|
||||
template <typename Tother> SSOArray(const Tother &other) : m_size(other.size())
|
||||
{
|
||||
alloc();
|
||||
|
@ -32,20 +32,6 @@
|
||||
|
||||
NEXTPNR_NAMESPACE_BEGIN
|
||||
|
||||
namespace {
|
||||
static std::tuple<int, int, std::string> split_identifier_name(const std::string &name)
|
||||
{
|
||||
size_t first_slash = name.find('/');
|
||||
NPNR_ASSERT(first_slash != std::string::npos);
|
||||
size_t second_slash = name.find('/', first_slash + 1);
|
||||
NPNR_ASSERT(second_slash != std::string::npos);
|
||||
return std::make_tuple(std::stoi(name.substr(1, first_slash)),
|
||||
std::stoi(name.substr(first_slash + 2, second_slash - first_slash)),
|
||||
name.substr(second_slash + 1));
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void IdString::initialize_arch(const BaseCtx *ctx)
|
||||
@ -134,6 +120,17 @@ Arch::Arch(ArchArgs args) : args(args)
|
||||
ts.bels_by_z[bel.z].index = j;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < chip_info->width; i++) {
|
||||
IdString x_id = id(stringf("X%d", i));
|
||||
x_ids.push_back(x_id);
|
||||
id_to_x[x_id] = i;
|
||||
}
|
||||
for (int i = 0; i < chip_info->height; i++) {
|
||||
IdString y_id = id(stringf("Y%d", i));
|
||||
y_ids.push_back(y_id);
|
||||
id_to_y[y_id] = i;
|
||||
}
|
||||
init_cell_pin_data();
|
||||
// Validate and set up package
|
||||
package_idx = -1;
|
||||
@ -193,17 +190,17 @@ IdString Arch::archArgsToId(ArchArgs args) const { return id(args.device); }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
BelId Arch::getBelByName(IdString name) const
|
||||
BelId Arch::getBelByName(IdStringList name) const
|
||||
{
|
||||
int x, y;
|
||||
std::string belname;
|
||||
std::tie(x, y, belname) = split_identifier_name(name.str(this));
|
||||
if (name.size() != 3)
|
||||
return BelId();
|
||||
int x = id_to_x.at(name[0]);
|
||||
int y = id_to_y.at(name[1]);
|
||||
NPNR_ASSERT(x >= 0 && x < chip_info->width);
|
||||
NPNR_ASSERT(y >= 0 && y < chip_info->height);
|
||||
auto &tile = db->loctypes[chip_info->grid[y * chip_info->width + x].loc_type];
|
||||
IdString bn = id(belname);
|
||||
for (size_t i = 0; i < tile.bels.size(); i++) {
|
||||
if (tile.bels[i].name == bn.index) {
|
||||
if (tile.bels[i].name == name[2].index) {
|
||||
BelId ret;
|
||||
ret.tile = y * chip_info->width + x;
|
||||
ret.index = i;
|
||||
@ -305,17 +302,17 @@ std::vector<std::pair<IdString, std::string>> Arch::getBelAttrs(BelId bel) const
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
WireId Arch::getWireByName(IdString name) const
|
||||
WireId Arch::getWireByName(IdStringList name) const
|
||||
{
|
||||
int x, y;
|
||||
std::string wirename;
|
||||
std::tie(x, y, wirename) = split_identifier_name(name.str(this));
|
||||
if (name.size() != 3)
|
||||
return WireId();
|
||||
int x = id_to_x.at(name[0]);
|
||||
int y = id_to_y.at(name[1]);
|
||||
NPNR_ASSERT(x >= 0 && x < chip_info->width);
|
||||
NPNR_ASSERT(y >= 0 && y < chip_info->height);
|
||||
auto &tile = db->loctypes[chip_info->grid[y * chip_info->width + x].loc_type];
|
||||
IdString wn = id(wirename);
|
||||
for (size_t i = 0; i < tile.wires.size(); i++) {
|
||||
if (tile.wires[i].name == wn.index) {
|
||||
if (tile.wires[i].name == name[2].index) {
|
||||
WireId ret;
|
||||
ret.tile = y * chip_info->width + x;
|
||||
ret.index = i;
|
||||
@ -342,26 +339,27 @@ std::vector<std::pair<IdString, std::string>> Arch::getWireAttrs(WireId wire) co
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
PipId Arch::getPipByName(IdString name) const
|
||||
PipId Arch::getPipByName(IdStringList name) const
|
||||
{
|
||||
int x, y;
|
||||
std::string pipname;
|
||||
std::tie(x, y, pipname) = split_identifier_name(name.str(this));
|
||||
if (name.size() != 5)
|
||||
return PipId();
|
||||
int x = id_to_x.at(name[0]);
|
||||
int y = id_to_y.at(name[1]);
|
||||
NPNR_ASSERT(x >= 0 && x < chip_info->width);
|
||||
NPNR_ASSERT(y >= 0 && y < chip_info->height);
|
||||
PipId ret;
|
||||
ret.tile = y * chip_info->width + x;
|
||||
auto sep_pos = pipname.find(':');
|
||||
ret.index = std::stoi(pipname.substr(0, sep_pos));
|
||||
ret.index = std::stoi(name[2].str(this));
|
||||
return ret;
|
||||
}
|
||||
|
||||
IdString Arch::getPipName(PipId pip) const
|
||||
IdStringList Arch::getPipName(PipId pip) const
|
||||
{
|
||||
NPNR_ASSERT(pip != PipId());
|
||||
return id(stringf("X%d/Y%d/%d:%s->%s", pip.tile % chip_info->width, pip.tile / chip_info->width, pip.index,
|
||||
nameOf(loc_data(pip).wires[pip_data(pip).from_wire].name),
|
||||
nameOf(loc_data(pip).wires[pip_data(pip).to_wire].name)));
|
||||
std::array<IdString, 5> ids{x_ids.at(pip.tile % chip_info->width), y_ids.at(pip.tile / chip_info->width),
|
||||
id(stringf("%d", pip.index)), IdString(loc_data(pip).wires[pip_data(pip).to_wire].name),
|
||||
IdString(loc_data(pip).wires[pip_data(pip).from_wire].name)};
|
||||
return IdStringList(ids);
|
||||
}
|
||||
|
||||
IdString Arch::getPipType(PipId pip) const { return IdString(); }
|
||||
|
43
nexus/arch.h
43
nexus/arch.h
@ -897,6 +897,11 @@ struct Arch : BaseCtx
|
||||
std::unordered_map<WireId, NetInfo *> wire_to_net;
|
||||
std::unordered_map<PipId, NetInfo *> pip_to_net;
|
||||
|
||||
// fast access to X and Y IdStrings for building object names
|
||||
std::vector<IdString> x_ids, y_ids;
|
||||
// inverse of the above for name->object mapping
|
||||
std::unordered_map<IdString, int> id_to_x, id_to_y;
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
std::string getChipName() const;
|
||||
@ -913,17 +918,14 @@ struct Arch : BaseCtx
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
BelId getBelByName(IdString name) const;
|
||||
BelId getBelByName(IdStringList name) const;
|
||||
|
||||
IdString getBelName(BelId bel) const
|
||||
IdStringList getBelName(BelId bel) const
|
||||
{
|
||||
std::string name = "X";
|
||||
name += std::to_string(bel.tile % chip_info->width);
|
||||
name += "/Y";
|
||||
name += std::to_string(bel.tile / chip_info->width);
|
||||
name += "/";
|
||||
name += nameOf(IdString(bel_data(bel).name));
|
||||
return id(name);
|
||||
NPNR_ASSERT(bel != BelId());
|
||||
std::array<IdString, 3> ids{x_ids.at(bel.tile % chip_info->width), y_ids.at(bel.tile / chip_info->width),
|
||||
IdString(bel_data(bel).name)};
|
||||
return IdStringList(ids);
|
||||
}
|
||||
|
||||
uint32_t getBelChecksum(BelId bel) const { return (bel.tile << 16) ^ bel.index; }
|
||||
@ -1024,16 +1026,13 @@ struct Arch : BaseCtx
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
WireId getWireByName(IdString name) const;
|
||||
IdString getWireName(WireId wire) const
|
||||
WireId getWireByName(IdStringList name) const;
|
||||
IdStringList getWireName(WireId wire) const
|
||||
{
|
||||
std::string name = "X";
|
||||
name += std::to_string(wire.tile % chip_info->width);
|
||||
name += "/Y";
|
||||
name += std::to_string(wire.tile / chip_info->width);
|
||||
name += "/";
|
||||
name += nameOf(IdString(wire_data(wire).name));
|
||||
return id(name);
|
||||
NPNR_ASSERT(wire != WireId());
|
||||
std::array<IdString, 3> ids{x_ids.at(wire.tile % chip_info->width), y_ids.at(wire.tile / chip_info->width),
|
||||
IdString(wire_data(wire).name)};
|
||||
return IdStringList(ids);
|
||||
}
|
||||
|
||||
IdString getWireType(WireId wire) const;
|
||||
@ -1137,8 +1136,8 @@ struct Arch : BaseCtx
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
PipId getPipByName(IdString name) const;
|
||||
IdString getPipName(PipId pip) const;
|
||||
PipId getPipByName(IdStringList name) const;
|
||||
IdStringList getPipName(PipId pip) const;
|
||||
|
||||
void bindPip(PipId pip, NetInfo *net, PlaceStrength strength)
|
||||
{
|
||||
@ -1290,8 +1289,8 @@ struct Arch : BaseCtx
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
GroupId getGroupByName(IdString name) const { return GroupId(); }
|
||||
IdString getGroupName(GroupId group) const { return IdString(); }
|
||||
GroupId getGroupByName(IdStringList name) const { return GroupId(); }
|
||||
IdStringList getGroupName(GroupId group) const { return IdStringList(); }
|
||||
std::vector<GroupId> getGroups() const { return {}; }
|
||||
std::vector<BelId> getGroupBels(GroupId group) const { return {}; }
|
||||
std::vector<WireId> getGroupWires(GroupId group) const { return {}; }
|
||||
|
@ -544,7 +544,7 @@ struct NexusPacker
|
||||
{
|
||||
if (!ci->attrs.count(id_BEL))
|
||||
return BelId();
|
||||
return ctx->getBelByName(ctx->id(ci->attrs.at(id_BEL).as_string()));
|
||||
return ctx->getBelByNameStr(ci->attrs.at(id_BEL).as_string());
|
||||
}
|
||||
|
||||
void pack_io()
|
||||
|
Loading…
Reference in New Issue
Block a user