Convert to use torc_info

This commit is contained in:
Eddie Hung 2018-08-12 22:09:16 -07:00
parent 7b15569c69
commit 72c785db0e
2 changed files with 63 additions and 39 deletions

View File

@ -33,10 +33,26 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
const DDB *torc = nullptr; std::unique_ptr<const TorcInfo> torc_info;
const Sites *torc_sites = nullptr; TorcInfo::TorcInfo(Arch *ctx, const std::string &inDeviceName, const std::string &inPackageName)
const Tiles *torc_tiles = nullptr; : ddb(new DDB(inDeviceName, inPackageName)), sites(ddb->getSites()), tiles(ddb->getTiles()), site_index_to_type(construct_site_index_to_type(ctx, sites))
std::vector<IdString> bel_index_to_type; {
}
std::vector<IdString> TorcInfo::construct_site_index_to_type(Arch* ctx, const Sites &sites)
{
std::vector<IdString> site_index_to_type;
site_index_to_type.resize(sites.getSiteCount());
for (SiteIndex i(0); i < sites.getSiteCount(); ++i) {
const auto& s = sites.getSite(i);
auto pd = s.getPrimitiveDefPtr();
const auto& type = pd->getName();
if (type == "SLICEL" || type == "SLICEM")
site_index_to_type[i] = id_QUARTER_SLICE;
else
site_index_to_type[i] = ctx->id(type);
}
return site_index_to_type;
}
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -54,7 +70,7 @@ Arch::Arch(ArchArgs args) : args(args)
{ {
torc::common::DirectoryTree directoryTree("../../torc/src/torc"); torc::common::DirectoryTree directoryTree("../../torc/src/torc");
if (args.type == ArchArgs::Z020) { if (args.type == ArchArgs::Z020) {
torc = new DDB("xc7z020", "clg484"); torc_info = std::unique_ptr<TorcInfo>(new TorcInfo(this, "xc7z020", "clg484"));
} else { } else {
log_error("Unsupported XC7 chip type.\n"); log_error("Unsupported XC7 chip type.\n");
} }
@ -69,21 +85,7 @@ Arch::Arch(ArchArgs args) : args(args)
// if (package_info == nullptr) // if (package_info == nullptr)
// log_error("Unsupported package '%s'.\n", args.package.c_str()); // log_error("Unsupported package '%s'.\n", args.package.c_str());
torc_sites = &torc->getSites(); bel_to_cell.resize(torc_info->sites.getSiteCount());
torc_tiles = &torc->getTiles();
bel_index_to_type.resize(torc_sites->getSiteCount());
for (SiteIndex i(0); i < torc_sites->getSiteCount(); ++i) {
const auto& s = torc_sites->getSite(i);
auto pd = s.getPrimitiveDefPtr();
const auto& type = pd->getName();
if (type == "SLICEL" || type == "SLICEM")
bel_index_to_type[i] = id_QUARTER_SLICE;
else
bel_index_to_type[i] = id(type);
}
bel_to_cell.resize(torc_sites->getSiteCount());
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -112,7 +114,7 @@ BelId Arch::getBelByName(IdString name) const
{ {
BelId ret; BelId ret;
auto it = torc_sites->findSiteIndex(name.str(this)); auto it = torc_info->sites.findSiteIndex(name.str(this));
if (it != SiteIndex(-1)) if (it != SiteIndex(-1))
ret.index = it; ret.index = it;
@ -124,10 +126,10 @@ BelId Arch::getBelByLocation(Loc loc) const
BelId bel; BelId bel;
if (bel_by_loc.empty()) { if (bel_by_loc.empty()) {
for (SiteIndex i(0); i < torc_sites->getSiteCount(); ++i) { for (SiteIndex i(0); i < torc_info->sites.getSiteCount(); ++i) {
BelId b; BelId b;
b.index = i; b.index = i;
if (bel_index_to_type[i] == id_QUARTER_SLICE) { if (torc_info->site_index_to_type[i] == id_QUARTER_SLICE) {
b.pos = BelId::A; b.pos = BelId::A;
bel_by_loc[getBelLocation(b)] = b; bel_by_loc[getBelLocation(b)] = b;
b.pos = BelId::B; b.pos = BelId::B;
@ -156,8 +158,8 @@ BelRange Arch::getBelsByTile(int x, int y) const
br.b.pos = b.pos; br.b.pos = b.pos;
br.e = br.b; br.e = br.b;
if (br.e.index != SiteIndex(torc_sites->getSiteCount())) { if (br.e.index != SiteIndex(torc_info->sites.getSiteCount())) {
while (br.e.index < SiteIndex(torc_sites->getSiteCount()) && torc_sites->getSite((*br.e).index).getTileIndex() == torc_sites->getSite((*br.b).index).getTileIndex()) while (br.e.index < SiteIndex(torc_info->sites.getSiteCount()) && torc_info->sites.getSite((*br.e).index).getTileIndex() == torc_info->sites.getSite((*br.b).index).getTileIndex())
br.e++; br.e++;
} }
@ -196,9 +198,9 @@ WireId Arch::getBelPinWire(BelId bel, IdString pin) const
{ {
WireId ret; WireId ret;
const auto& site = torc_sites->getSite(bel.index); const auto& site = torc_info->sites.getSite(bel.index);
auto pin_name = pin.str(this); auto pin_name = pin.str(this);
if (bel_index_to_type[bel.index] == id_QUARTER_SLICE) if (torc_info->site_index_to_type[bel.index] == id_QUARTER_SLICE)
pin_name[0] = bel.pos; pin_name[0] = bel.pos;
ret.index = site.getPinTilewire(pin_name); ret.index = site.getPinTilewire(pin_name);

View File

@ -233,10 +233,27 @@ NPNR_PACKED_STRUCT(struct ChipInfoPOD {
}); });
extern const DDB *torc; struct Arch;
extern const Sites *torc_sites; struct TorcInfo {
extern const Tiles *torc_tiles; TorcInfo(Arch *ctx, const std::string &inDeviceName, const std::string &inPackageName);
extern std::vector<IdString> bel_index_to_type; std::unique_ptr<const DDB> ddb;
const Sites &sites;
const Tiles &tiles;
SiteIndex sites_begin() const { return SiteIndex(0); }
SiteIndex sites_end() const { return SiteIndex(sites.getSiteCount()); }
const TileInfo& site_index_to_tile_info(SiteIndex si) const {
const auto& site = sites.getSite(si);
return tiles.getTileInfo(site.getTileIndex());
}
const std::string& site_index_to_name(SiteIndex si) const {
return sites.getSite(si).getName();
}
const std::vector<IdString> site_index_to_type;
static std::vector<IdString> construct_site_index_to_type(Arch *ctx, const Sites &sites);
};
extern std::unique_ptr<const TorcInfo> torc_info;
/************************ End of chipdb section. ************************/ /************************ End of chipdb section. ************************/
@ -245,14 +262,14 @@ struct BelIterator : public BelId
{ {
BelIterator operator++() BelIterator operator++()
{ {
if (bel_index_to_type[index] == id_QUARTER_SLICE) { if (torc_info->site_index_to_type[index] == id_QUARTER_SLICE) {
if (pos < D) { if (pos < D) {
++pos; ++pos;
return *this; return *this;
} }
} }
if (bel_index_to_type[++index] == id_QUARTER_SLICE) if (torc_info->site_index_to_type[++index] == id_QUARTER_SLICE)
pos = A; pos = A;
else else
pos = NOT_APPLICABLE; pos = NOT_APPLICABLE;
@ -428,7 +445,13 @@ struct Arch : BaseCtx
IdString getBelName(BelId bel) const IdString getBelName(BelId bel) const
{ {
NPNR_ASSERT(bel != BelId()); NPNR_ASSERT(bel != BelId());
return id(torc_sites->getSite(bel.index).getName()); auto name = torc_info->site_index_to_name(bel.index);
if (torc_info->site_index_to_type[bel.index] == id_QUARTER_SLICE) {
name.reserve(name.size() + 2);
name += "_";
name += bel.pos;
}
return id(name);
} }
uint32_t getBelChecksum(BelId bel) const { return bel.index; } uint32_t getBelChecksum(BelId bel) const { return bel.index; }
@ -477,15 +500,14 @@ struct Arch : BaseCtx
BelRange getBels() const BelRange getBels() const
{ {
BelRange range; BelRange range;
range.b.index = SiteIndex(0); range.b.index = torc_info->sites_begin();
range.e.index = SiteIndex(torc_sites->getSiteCount()); range.e.index = torc_info->sites_end();
return range; return range;
} }
Loc getBelLocation(BelId bel) const Loc getBelLocation(BelId bel) const
{ {
const auto& site = torc_sites->getSite(bel.index); const auto& tile_info = torc_info->site_index_to_tile_info(bel.index);
const auto& tile_info = torc_tiles->getTileInfo(site.getTileIndex());
Loc loc; Loc loc;
loc.x = tile_info.getCol(); loc.x = tile_info.getCol();
loc.y = tile_info.getRow(); loc.y = tile_info.getRow();
@ -501,7 +523,7 @@ struct Arch : BaseCtx
IdString getBelType(BelId bel) const IdString getBelType(BelId bel) const
{ {
NPNR_ASSERT(bel != BelId()); NPNR_ASSERT(bel != BelId());
return bel_index_to_type[bel.index]; return torc_info->site_index_to_type[bel.index];
} }
WireId getBelPinWire(BelId bel, IdString pin) const; WireId getBelPinWire(BelId bel, IdString pin) const;