diff options
author | David Shah <dave@ds0.me> | 2019-07-03 12:39:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-03 12:39:38 +0100 |
commit | 8f2813279c5888e655ee6f50f198cf8cb11b0b50 (patch) | |
tree | 0aac9464d3ea87d37cd0689903ba08094b7c0984 /common/nextpnr.cc | |
parent | ff958830d1097b9bfa3c3b34094e671741ef563d (diff) | |
parent | e27dc41a7646fd3377d2400059c916fbcc35119c (diff) | |
download | nextpnr-8f2813279c5888e655ee6f50f198cf8cb11b0b50.tar.gz nextpnr-8f2813279c5888e655ee6f50f198cf8cb11b0b50.tar.bz2 nextpnr-8f2813279c5888e655ee6f50f198cf8cb11b0b50.zip |
Merge pull request #284 from YosysHQ/json_write
Initial support for writing to json files from nextpnr.
Diffstat (limited to 'common/nextpnr.cc')
-rw-r--r-- | common/nextpnr.cc | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/common/nextpnr.cc b/common/nextpnr.cc index daaadf28..d4cc4917 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -18,6 +18,7 @@ */ #include "nextpnr.h" +#include <boost/algorithm/string.hpp> #include "log.h" NEXTPNR_NAMESPACE_BEGIN @@ -453,4 +454,118 @@ DecalXY BaseCtx::constructDecalXY(DecalId decal, float x, float y) return dxy; } +void BaseCtx::archInfoToAttributes() +{ + for (auto &cell : cells) { + auto ci = cell.second.get(); + if (ci->bel != BelId()) { + if (ci->attrs.find(id("BEL")) != ci->attrs.end()) { + ci->attrs.erase(ci->attrs.find(id("BEL"))); + } + ci->attrs[id("NEXTPNR_BEL")] = getCtx()->getBelName(ci->bel).c_str(this); + ci->attrs[id("BEL_STRENGTH")] = std::to_string((int)ci->belStrength); + } + if (ci->constr_x != ci->UNCONSTR) + ci->attrs[id("CONSTR_X")] = std::to_string(ci->constr_x); + if (ci->constr_y != ci->UNCONSTR) + ci->attrs[id("CONSTR_Y")] = std::to_string(ci->constr_y); + if (ci->constr_z != ci->UNCONSTR) { + ci->attrs[id("CONSTR_Z")] = std::to_string(ci->constr_z); + ci->attrs[id("CONSTR_ABS_Z")] = std::to_string(ci->constr_abs_z ? 1 : 0); + } + if (ci->constr_parent != nullptr) + ci->attrs[id("CONSTR_PARENT")] = ci->constr_parent->name.c_str(this); + if (!ci->constr_children.empty()) { + std::string constr = ""; + for (auto &item : ci->constr_children) { + if (!constr.empty()) + constr += std::string(";"); + constr += item->name.c_str(this); + } + ci->attrs[id("CONSTR_CHILDREN")] = constr; + } + } + for (auto &net : getCtx()->nets) { + auto ni = net.second.get(); + std::string routing; + bool first = true; + for (auto &item : ni->wires) { + if (!first) + routing += ";"; + routing += getCtx()->getWireName(item.first).c_str(this); + routing += ";"; + if (item.second.pip != PipId()) + routing += getCtx()->getPipName(item.second.pip).c_str(this); + routing += ";" + std::to_string(item.second.strength); + first = false; + } + ni->attrs[id("ROUTING")] = routing; + } +} + +void BaseCtx::attributesToArchInfo() +{ + for (auto &cell : cells) { + auto ci = cell.second.get(); + auto val = ci->attrs.find(id("NEXTPNR_BEL")); + if (val != ci->attrs.end()) { + auto str = ci->attrs.find(id("BEL_STRENGTH")); + PlaceStrength strength = PlaceStrength::STRENGTH_USER; + if (str != ci->attrs.end()) + strength = (PlaceStrength)std::stoi(str->second.str); + + BelId b = getCtx()->getBelByName(id(val->second.str)); + getCtx()->bindBel(b, ci, strength); + } + val = ci->attrs.find(id("CONSTR_X")); + if (val != ci->attrs.end()) + ci->constr_x = std::stoi(val->second.str); + + val = ci->attrs.find(id("CONSTR_Y")); + if (val != ci->attrs.end()) + ci->constr_y = std::stoi(val->second.str); + + val = ci->attrs.find(id("CONSTR_Z")); + if (val != ci->attrs.end()) + ci->constr_z = std::stoi(val->second.str); + + val = ci->attrs.find(id("CONSTR_ABS_Z")); + if (val != ci->attrs.end()) + ci->constr_abs_z = std::stoi(val->second.str) == 1; + + val = ci->attrs.find(id("CONSTR_PARENT")); + if (val != ci->attrs.end()) { + auto parent = cells.find(id(val->second.str)); + if (parent != cells.end()) + ci->constr_parent = parent->second.get(); + } + val = ci->attrs.find(id("CONSTR_CHILDREN")); + if (val != ci->attrs.end()) { + std::vector<std::string> strs; + boost::split(strs, val->second.str, boost::is_any_of(";")); + for (auto val : strs) { + ci->constr_children.push_back(cells.find(id(val.c_str()))->second.get()); + } + } + } + for (auto &net : getCtx()->nets) { + auto ni = net.second.get(); + auto val = ni->attrs.find(id("ROUTING")); + if (val != ni->attrs.end()) { + std::vector<std::string> strs; + boost::split(strs, val->second.str, boost::is_any_of(";")); + for (size_t i = 0; i < strs.size() / 3; i++) { + std::string wire = strs[i * 3]; + std::string pip = strs[i * 3 + 1]; + PlaceStrength strength = (PlaceStrength)std::stoi(strs[i * 3 + 2]); + if (pip.empty()) + getCtx()->bindWire(getCtx()->getWireByName(id(wire)), ni, strength); + else + getCtx()->bindPip(getCtx()->getPipByName(id(pip)), ni, strength); + } + } + } + getCtx()->assignArchInfo(); +} + NEXTPNR_NAMESPACE_END |