Add IdString API

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-06-12 15:08:01 +02:00
parent 592a627e0c
commit a139654980
7 changed files with 61 additions and 24 deletions

View File

@ -41,8 +41,43 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
// replace with proper IdString later struct IdString
typedef std::string IdString; {
std::string data;
IdString() {}
IdString(std::string s) : data(s) {}
IdString(const char *s) : data(s) {}
const char *c_str() const { return data.c_str(); }
const std::string &str() const { return data; }
operator const char *() const { return c_str(); }
operator const std::string &() const { return str(); }
bool operator<(const IdString &other) const { return data < other.data; }
bool operator==(const IdString &other) const { return data == other.data; }
bool operator==(const std::string &s) const { return data == s; }
bool operator==(const char *s) const { return data == s; }
size_t size() const { return data.size(); }
bool empty() const { return data.empty(); }
};
NEXTPNR_NAMESPACE_END
namespace std {
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX IdString>
{
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX IdString &obj) const
noexcept
{
return std::hash<std::string>()(obj.data);
}
};
}
NEXTPNR_NAMESPACE_BEGIN
struct GraphicElement struct GraphicElement
{ {

View File

@ -100,7 +100,7 @@ void place_design(Design *design)
if (cell->bel != BelId()) if (cell->bel != BelId())
continue; continue;
// Only place one type of Bel at a time // Only place one type of Bel at a time
if (cell->type.compare(bel_type_name) != 0) if (cell->type != bel_type_name)
continue; continue;
while ((bi != blist.end()) && while ((bi != blist.end()) &&
@ -115,7 +115,7 @@ void place_design(Design *design)
design->chip.bindBel(cell->bel, cell->name); design->chip.bindBel(cell->bel, cell->name);
// Back annotate location // Back annotate location
cell->attrs["BEL"] = design->chip.getBelName(cell->bel); cell->attrs["BEL"] = design->chip.getBelName(cell->bel).str();
} }
} }
} }

View File

@ -24,7 +24,7 @@ bool check_all_nets_driven(Design *design)
log_info(" Checking name of port \'%s\' " log_info(" Checking name of port \'%s\' "
"against \'%s\'\n", "against \'%s\'\n",
port_entry.first.c_str(), port.name.c_str()); port_entry.first.c_str(), port.name.c_str());
assert(port.name.compare(port_entry.first) == 0); assert(port.name == port_entry.first);
assert(port.name.size() > 0); assert(port.name.size() > 0);
if (port.net == NULL) { if (port.net == NULL) {
@ -45,10 +45,9 @@ bool check_all_nets_driven(Design *design)
for (auto net_entry : design->nets) { for (auto net_entry : design->nets) {
NetInfo *net = net_entry.second; NetInfo *net = net_entry.second;
assert(net->name.compare(net_entry.first) == 0); assert(net->name == net_entry.first);
if ((net->driver.cell != NULL) && if ((net->driver.cell != NULL) && (net->driver.cell->type != "GND") &&
(net->driver.cell->type.compare("GND") != 0) && (net->driver.cell->type != "VCC")) {
(net->driver.cell->type.compare("VCC") != 0)) {
if (debug) if (debug)
log_info(" Checking for a driver cell named \'%s\'\n", log_info(" Checking for a driver cell named \'%s\'\n",
@ -57,8 +56,8 @@ bool check_all_nets_driven(Design *design)
} }
for (auto user : net->users) { for (auto user : net->users) {
if ((user.cell != NULL) && (user.cell->type.compare("GND") != 0) && if ((user.cell != NULL) && (user.cell->type != "GND") &&
(user.cell->type.compare("VCC") != 0)) { (user.cell->type != "VCC")) {
if (debug) if (debug)
log_info(" Checking for a user cell named \'%s\'\n", log_info(" Checking for a user cell named \'%s\'\n",

View File

@ -224,10 +224,10 @@ NetInfo *ground_net(NetInfo *net)
PortInfo port_info; PortInfo port_info;
PortRef port_ref; PortRef port_ref;
cell->name = string(net->name + ".GND"); cell->name = string(net->name.str() + ".GND");
cell->type = string("GND"); cell->type = string("GND");
port_info.name = cell->name + "[]"; port_info.name = cell->name.str() + "[]";
port_info.net = net; port_info.net = net;
port_info.type = PORT_OUT; port_info.type = PORT_OUT;
@ -247,10 +247,10 @@ NetInfo *vcc_net(NetInfo *net)
PortInfo port_info; PortInfo port_info;
PortRef port_ref; PortRef port_ref;
cell->name = string(net->name + ".VCC"); cell->name = string(net->name.str() + ".VCC");
cell->type = string("VCC"); cell->type = string("VCC");
port_info.name = cell->name + "[]"; port_info.name = cell->name.str() + "[]";
port_info.net = net; port_info.net = net;
port_info.type = PORT_OUT; port_info.type = PORT_OUT;
@ -269,7 +269,7 @@ NetInfo *floating_net(NetInfo *net)
PortInfo port_info; PortInfo port_info;
PortRef port_ref; PortRef port_ref;
port_info.name = net->name + ".floating"; port_info.name = net->name.str() + ".floating";
port_info.net = net; port_info.net = net;
port_info.type = PORT_OUT; port_info.type = PORT_OUT;

View File

@ -33,8 +33,8 @@ CellInfo *create_ice_cell(Design *design, IdString type, IdString name)
static int auto_idx = 0; static int auto_idx = 0;
CellInfo *new_cell = new CellInfo(); CellInfo *new_cell = new CellInfo();
if (name == IdString()) { if (name == IdString()) {
new_cell->name = new_cell->name = IdString("$nextpnr_" + type.str() + "_" +
IdString("$nextpnr_" + type + "_" + std::to_string(auto_idx++)); std::to_string(auto_idx++));
} else { } else {
new_cell->name = name; new_cell->name = name;
} }
@ -82,7 +82,7 @@ void lut_to_lc(CellInfo *lut, CellInfo *lc, bool no_dff)
void dff_to_lc(CellInfo *dff, CellInfo *lc, bool pass_thru_lut) void dff_to_lc(CellInfo *dff, CellInfo *lc, bool pass_thru_lut)
{ {
lc->params["DFF_ENABLE"] = "1"; lc->params["DFF_ENABLE"] = "1";
std::string config = std::string(dff->type).substr(6); std::string config = dff->type.str().substr(6);
auto citer = config.begin(); auto citer = config.begin();
replace_port(dff, "C", lc, "CLK"); replace_port(dff, "C", lc, "CLK");

View File

@ -217,7 +217,8 @@ NEXTPNR_NAMESPACE_END
namespace std { namespace std {
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId> template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId>
{ {
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelId &bel) const noexcept std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelId &bel) const
noexcept
{ {
return bel.index; return bel.index;
} }
@ -225,7 +226,8 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId>
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId> template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId>
{ {
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX WireId &wire) const noexcept std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX WireId &wire) const
noexcept
{ {
return wire.index; return wire.index;
} }
@ -233,7 +235,8 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId>
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX PipId> template <> struct hash<NEXTPNR_NAMESPACE_PREFIX PipId>
{ {
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &wire) const noexcept std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &wire) const
noexcept
{ {
return wire.index; return wire.index;
} }

View File

@ -38,7 +38,7 @@ static void pack_lut_lutffs(Design *design)
ci->type.c_str()); ci->type.c_str());
if (is_lut(ci)) { if (is_lut(ci)) {
CellInfo *packed = create_ice_cell(design, "ICESTORM_LC", CellInfo *packed = create_ice_cell(design, "ICESTORM_LC",
std::string(ci->name) + "_LC"); ci->name.str() + "_LC");
packed_cells.insert(ci->name); packed_cells.insert(ci->name);
new_cells.push_back(packed); new_cells.push_back(packed);
log_info("packed cell %s into %s\n", ci->name.c_str(), log_info("packed cell %s into %s\n", ci->name.c_str(),
@ -77,7 +77,7 @@ static void pack_nonlut_ffs(Design *design)
CellInfo *ci = cell.second; CellInfo *ci = cell.second;
if (is_ff(ci)) { if (is_ff(ci)) {
CellInfo *packed = create_ice_cell(design, "ICESTORM_LC", CellInfo *packed = create_ice_cell(design, "ICESTORM_LC",
std::string(ci->name) + "_LC"); ci->name.str() + "_LC");
packed_cells.insert(ci->name); packed_cells.insert(ci->name);
new_cells.push_back(packed); new_cells.push_back(packed);
dff_to_lc(ci, packed, true); dff_to_lc(ci, packed, true);