diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-06-12 15:08:01 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2018-06-12 15:08:01 +0200 |
commit | a139654980b2d2560667b12c886de7518ec97c40 (patch) | |
tree | 7f8d1c6f5553af3ae637e087a86988b04faa5db7 /common | |
parent | 592a627e0c99ddf2cf06c286813a2d08962d8cd9 (diff) | |
download | nextpnr-a139654980b2d2560667b12c886de7518ec97c40.tar.gz nextpnr-a139654980b2d2560667b12c886de7518ec97c40.tar.bz2 nextpnr-a139654980b2d2560667b12c886de7518ec97c40.zip |
Add IdString API
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'common')
-rw-r--r-- | common/nextpnr.h | 39 | ||||
-rw-r--r-- | common/place.cc | 4 | ||||
-rw-r--r-- | common/rulecheck.cc | 13 |
3 files changed, 45 insertions, 11 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index 0c74c1ad..bc92719f 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -41,8 +41,43 @@ NEXTPNR_NAMESPACE_BEGIN -// replace with proper IdString later -typedef std::string IdString; +struct 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 { diff --git a/common/place.cc b/common/place.cc index e8fadd16..007fc748 100644 --- a/common/place.cc +++ b/common/place.cc @@ -100,7 +100,7 @@ void place_design(Design *design) if (cell->bel != BelId()) continue; // Only place one type of Bel at a time - if (cell->type.compare(bel_type_name) != 0) + if (cell->type != bel_type_name) continue; while ((bi != blist.end()) && @@ -115,7 +115,7 @@ void place_design(Design *design) design->chip.bindBel(cell->bel, cell->name); // Back annotate location - cell->attrs["BEL"] = design->chip.getBelName(cell->bel); + cell->attrs["BEL"] = design->chip.getBelName(cell->bel).str(); } } } diff --git a/common/rulecheck.cc b/common/rulecheck.cc index c0139a85..987eb602 100644 --- a/common/rulecheck.cc +++ b/common/rulecheck.cc @@ -24,7 +24,7 @@ bool check_all_nets_driven(Design *design) log_info(" Checking name of port \'%s\' " "against \'%s\'\n", 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); if (port.net == NULL) { @@ -45,10 +45,9 @@ bool check_all_nets_driven(Design *design) for (auto net_entry : design->nets) { NetInfo *net = net_entry.second; - assert(net->name.compare(net_entry.first) == 0); - if ((net->driver.cell != NULL) && - (net->driver.cell->type.compare("GND") != 0) && - (net->driver.cell->type.compare("VCC") != 0)) { + assert(net->name == net_entry.first); + if ((net->driver.cell != NULL) && (net->driver.cell->type != "GND") && + (net->driver.cell->type != "VCC")) { if (debug) 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) { - if ((user.cell != NULL) && (user.cell->type.compare("GND") != 0) && - (user.cell->type.compare("VCC") != 0)) { + if ((user.cell != NULL) && (user.cell->type != "GND") && + (user.cell->type != "VCC")) { if (debug) log_info(" Checking for a user cell named \'%s\'\n", |