Add IdString API
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
592a627e0c
commit
a139654980
@ -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
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -224,10 +224,10 @@ NetInfo *ground_net(NetInfo *net)
|
||||
PortInfo port_info;
|
||||
PortRef port_ref;
|
||||
|
||||
cell->name = string(net->name + ".GND");
|
||||
cell->name = string(net->name.str() + ".GND");
|
||||
cell->type = string("GND");
|
||||
|
||||
port_info.name = cell->name + "[]";
|
||||
port_info.name = cell->name.str() + "[]";
|
||||
port_info.net = net;
|
||||
port_info.type = PORT_OUT;
|
||||
|
||||
@ -247,10 +247,10 @@ NetInfo *vcc_net(NetInfo *net)
|
||||
PortInfo port_info;
|
||||
PortRef port_ref;
|
||||
|
||||
cell->name = string(net->name + ".VCC");
|
||||
cell->name = string(net->name.str() + ".VCC");
|
||||
cell->type = string("VCC");
|
||||
|
||||
port_info.name = cell->name + "[]";
|
||||
port_info.name = cell->name.str() + "[]";
|
||||
port_info.net = net;
|
||||
port_info.type = PORT_OUT;
|
||||
|
||||
@ -269,7 +269,7 @@ NetInfo *floating_net(NetInfo *net)
|
||||
PortInfo port_info;
|
||||
PortRef port_ref;
|
||||
|
||||
port_info.name = net->name + ".floating";
|
||||
port_info.name = net->name.str() + ".floating";
|
||||
port_info.net = net;
|
||||
port_info.type = PORT_OUT;
|
||||
|
||||
|
@ -33,8 +33,8 @@ CellInfo *create_ice_cell(Design *design, IdString type, IdString name)
|
||||
static int auto_idx = 0;
|
||||
CellInfo *new_cell = new CellInfo();
|
||||
if (name == IdString()) {
|
||||
new_cell->name =
|
||||
IdString("$nextpnr_" + type + "_" + std::to_string(auto_idx++));
|
||||
new_cell->name = IdString("$nextpnr_" + type.str() + "_" +
|
||||
std::to_string(auto_idx++));
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
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();
|
||||
replace_port(dff, "C", lc, "CLK");
|
||||
|
||||
|
@ -217,7 +217,8 @@ NEXTPNR_NAMESPACE_END
|
||||
namespace std {
|
||||
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;
|
||||
}
|
||||
@ -225,7 +226,8 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId>
|
||||
|
||||
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;
|
||||
}
|
||||
@ -233,7 +235,8 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ static void pack_lut_lutffs(Design *design)
|
||||
ci->type.c_str());
|
||||
if (is_lut(ci)) {
|
||||
CellInfo *packed = create_ice_cell(design, "ICESTORM_LC",
|
||||
std::string(ci->name) + "_LC");
|
||||
ci->name.str() + "_LC");
|
||||
packed_cells.insert(ci->name);
|
||||
new_cells.push_back(packed);
|
||||
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;
|
||||
if (is_ff(ci)) {
|
||||
CellInfo *packed = create_ice_cell(design, "ICESTORM_LC",
|
||||
std::string(ci->name) + "_LC");
|
||||
ci->name.str() + "_LC");
|
||||
packed_cells.insert(ci->name);
|
||||
new_cells.push_back(packed);
|
||||
dff_to_lc(ci, packed, true);
|
||||
|
Loading…
Reference in New Issue
Block a user