From 72c785db0e0f949492b805a896bec5f9e36f10ef Mon Sep 17 00:00:00 2001 From: Eddie Hung Date: Sun, 12 Aug 2018 22:09:16 -0700 Subject: [PATCH] Convert to use torc_info --- xc7/arch.cc | 56 +++++++++++++++++++++++++++-------------------------- xc7/arch.h | 46 +++++++++++++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/xc7/arch.cc b/xc7/arch.cc index caee112f..4e6f32f6 100644 --- a/xc7/arch.cc +++ b/xc7/arch.cc @@ -33,10 +33,26 @@ NEXTPNR_NAMESPACE_BEGIN -const DDB *torc = nullptr; -const Sites *torc_sites = nullptr; -const Tiles *torc_tiles = nullptr; -std::vector bel_index_to_type; +std::unique_ptr torc_info; +TorcInfo::TorcInfo(Arch *ctx, const std::string &inDeviceName, const std::string &inPackageName) + : ddb(new DDB(inDeviceName, inPackageName)), sites(ddb->getSites()), tiles(ddb->getTiles()), site_index_to_type(construct_site_index_to_type(ctx, sites)) +{ +} +std::vector TorcInfo::construct_site_index_to_type(Arch* ctx, const Sites &sites) +{ + std::vector 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"); if (args.type == ArchArgs::Z020) { - torc = new DDB("xc7z020", "clg484"); + torc_info = std::unique_ptr(new TorcInfo(this, "xc7z020", "clg484")); } else { log_error("Unsupported XC7 chip type.\n"); } @@ -69,21 +85,7 @@ Arch::Arch(ArchArgs args) : args(args) // if (package_info == nullptr) // log_error("Unsupported package '%s'.\n", args.package.c_str()); - torc_sites = &torc->getSites(); - 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()); + bel_to_cell.resize(torc_info->sites.getSiteCount()); } // ----------------------------------------------------------------------- @@ -112,7 +114,7 @@ BelId Arch::getBelByName(IdString name) const { BelId ret; - auto it = torc_sites->findSiteIndex(name.str(this)); + auto it = torc_info->sites.findSiteIndex(name.str(this)); if (it != SiteIndex(-1)) ret.index = it; @@ -124,10 +126,10 @@ BelId Arch::getBelByLocation(Loc loc) const BelId bel; 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; 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; bel_by_loc[getBelLocation(b)] = b; b.pos = BelId::B; @@ -156,8 +158,8 @@ BelRange Arch::getBelsByTile(int x, int y) const br.b.pos = b.pos; br.e = br.b; - if (br.e.index != SiteIndex(torc_sites->getSiteCount())) { - while (br.e.index < SiteIndex(torc_sites->getSiteCount()) && torc_sites->getSite((*br.e).index).getTileIndex() == torc_sites->getSite((*br.b).index).getTileIndex()) + if (br.e.index != SiteIndex(torc_info->sites.getSiteCount())) { + 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++; } @@ -196,9 +198,9 @@ WireId Arch::getBelPinWire(BelId bel, IdString pin) const { 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); - 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; ret.index = site.getPinTilewire(pin_name); diff --git a/xc7/arch.h b/xc7/arch.h index 295a0759..5f54a5ea 100644 --- a/xc7/arch.h +++ b/xc7/arch.h @@ -233,10 +233,27 @@ NPNR_PACKED_STRUCT(struct ChipInfoPOD { }); -extern const DDB *torc; -extern const Sites *torc_sites; -extern const Tiles *torc_tiles; -extern std::vector bel_index_to_type; +struct Arch; +struct TorcInfo { + TorcInfo(Arch *ctx, const std::string &inDeviceName, const std::string &inPackageName); + std::unique_ptr 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 site_index_to_type; + static std::vector construct_site_index_to_type(Arch *ctx, const Sites &sites); +}; +extern std::unique_ptr torc_info; /************************ End of chipdb section. ************************/ @@ -245,14 +262,14 @@ struct BelIterator : public BelId { 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) { ++pos; return *this; } } - if (bel_index_to_type[++index] == id_QUARTER_SLICE) + if (torc_info->site_index_to_type[++index] == id_QUARTER_SLICE) pos = A; else pos = NOT_APPLICABLE; @@ -428,7 +445,13 @@ struct Arch : BaseCtx IdString getBelName(BelId bel) const { 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; } @@ -477,15 +500,14 @@ struct Arch : BaseCtx BelRange getBels() const { BelRange range; - range.b.index = SiteIndex(0); - range.e.index = SiteIndex(torc_sites->getSiteCount()); + range.b.index = torc_info->sites_begin(); + range.e.index = torc_info->sites_end(); return range; } Loc getBelLocation(BelId bel) const { - const auto& site = torc_sites->getSite(bel.index); - const auto& tile_info = torc_tiles->getTileInfo(site.getTileIndex()); + const auto& tile_info = torc_info->site_index_to_tile_info(bel.index); Loc loc; loc.x = tile_info.getCol(); loc.y = tile_info.getRow(); @@ -501,7 +523,7 @@ struct Arch : BaseCtx IdString getBelType(BelId bel) const { 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;