Getting rid of .nil() methods, compare with zero- and default-constructed objects instead

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-06-09 18:41:38 +02:00
parent 0bc5b1c2d9
commit 8cabb39d6d
4 changed files with 36 additions and 48 deletions

View File

@ -41,7 +41,7 @@ BelType belTypeFromId(IdString id)
return TYPE_ICESTORM_RAM; return TYPE_ICESTORM_RAM;
if (id == "SB_IO") if (id == "SB_IO")
return TYPE_SB_IO; return TYPE_SB_IO;
return TYPE_NIL; return TYPE_NONE;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -67,7 +67,7 @@ PortPin portPinFromId(IdString id)
#include "portpins.inc" #include "portpins.inc"
#undef X #undef X
return PIN_NIL; return PIN_NONE;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -121,7 +121,7 @@ WireId Chip::getWireBelPin(BelId bel, PortPin pin) const
{ {
WireId ret; WireId ret;
assert(!bel.nil()); assert(bel != BelId());
int num_bel_wires = chip_info.bel_data[bel.index].num_bel_wires; int num_bel_wires = chip_info.bel_data[bel.index].num_bel_wires;
BelWirePOD *bel_wires = chip_info.bel_data[bel.index].bel_wires; BelWirePOD *bel_wires = chip_info.bel_data[bel.index].bel_wires;
@ -178,21 +178,21 @@ PipId Chip::getPipByName(IdString name) const
void Chip::getBelPosition(BelId bel, float &x, float &y) const void Chip::getBelPosition(BelId bel, float &x, float &y) const
{ {
assert(!bel.nil()); assert(bel != BelId());
x = chip_info.bel_data[bel.index].x; x = chip_info.bel_data[bel.index].x;
y = chip_info.bel_data[bel.index].y; y = chip_info.bel_data[bel.index].y;
} }
void Chip::getWirePosition(WireId wire, float &x, float &y) const void Chip::getWirePosition(WireId wire, float &x, float &y) const
{ {
assert(!wire.nil()); assert(wire != WireId());
x = chip_info.wire_data[wire.index].x; x = chip_info.wire_data[wire.index].x;
y = chip_info.wire_data[wire.index].y; y = chip_info.wire_data[wire.index].y;
} }
void Chip::getPipPosition(PipId pip, float &x, float &y) const void Chip::getPipPosition(PipId pip, float &x, float &y) const
{ {
assert(!pip.nil()); assert(pip != PipId());
x = chip_info.pip_data[pip.index].x; x = chip_info.pip_data[pip.index].x;
y = chip_info.pip_data[pip.index].y; y = chip_info.pip_data[pip.index].y;
} }

View File

@ -42,7 +42,7 @@ struct DelayInfo
enum BelType enum BelType
{ {
TYPE_NIL, TYPE_NONE,
TYPE_ICESTORM_LC, TYPE_ICESTORM_LC,
TYPE_ICESTORM_RAM, TYPE_ICESTORM_RAM,
TYPE_SB_IO TYPE_SB_IO
@ -53,7 +53,7 @@ BelType belTypeFromId(IdString id);
enum PortPin enum PortPin
{ {
PIN_NIL, PIN_NONE,
#define X(t) PIN_##t, #define X(t) PIN_##t,
#include "portpins.inc" #include "portpins.inc"
#undef X #undef X
@ -125,8 +125,6 @@ struct BelId
{ {
int32_t index = -1; int32_t index = -1;
bool nil() const { return index < 0; }
bool operator==(const BelId &other) const { return index == other.index; } bool operator==(const BelId &other) const { return index == other.index; }
bool operator!=(const BelId &other) const { return index != other.index; } bool operator!=(const BelId &other) const { return index != other.index; }
}; };
@ -135,8 +133,6 @@ struct WireId
{ {
int32_t index = -1; int32_t index = -1;
bool nil() const { return index < 0; }
bool operator==(const WireId &other) const { return index == other.index; } bool operator==(const WireId &other) const { return index == other.index; }
bool operator!=(const WireId &other) const { return index != other.index; } bool operator!=(const WireId &other) const { return index != other.index; }
}; };
@ -145,8 +141,6 @@ struct PipId
{ {
int32_t index = -1; int32_t index = -1;
bool nil() const { return index < 0; }
bool operator==(const PipId &other) const { return index == other.index; } bool operator==(const PipId &other) const { return index == other.index; }
bool operator!=(const PipId &other) const { return index != other.index; } bool operator!=(const PipId &other) const { return index != other.index; }
}; };
@ -371,33 +365,33 @@ struct Chip
IdString getBelName(BelId bel) const IdString getBelName(BelId bel) const
{ {
assert(!bel.nil()); assert(bel != BelId());
return chip_info.bel_data[bel.index].name; return chip_info.bel_data[bel.index].name;
} }
void bindBel(BelId bel, IdString cell) void bindBel(BelId bel, IdString cell)
{ {
assert(!bel.nil()); assert(bel != BelId());
assert(bel_to_cell[bel.index] == IdString()); assert(bel_to_cell[bel.index] == IdString());
bel_to_cell[bel.index] = cell; bel_to_cell[bel.index] = cell;
} }
void unbindBel(BelId bel) void unbindBel(BelId bel)
{ {
assert(!bel.nil()); assert(bel != BelId());
assert(bel_to_cell[bel.index] != IdString()); assert(bel_to_cell[bel.index] != IdString());
bel_to_cell[bel.index] = IdString(); bel_to_cell[bel.index] = IdString();
} }
bool checkBelAvail(BelId bel) const bool checkBelAvail(BelId bel) const
{ {
assert(!bel.nil()); assert(bel != BelId());
return bel_to_cell[bel.index] == IdString(); return bel_to_cell[bel.index] == IdString();
} }
IdString getBelCell(BelId bel) const IdString getBelCell(BelId bel) const
{ {
assert(!bel.nil()); assert(bel != BelId());
return bel_to_cell[bel.index]; return bel_to_cell[bel.index];
} }
@ -425,7 +419,7 @@ struct Chip
BelType getBelType(BelId bel) const BelType getBelType(BelId bel) const
{ {
assert(!bel.nil()); assert(bel != BelId());
return chip_info.bel_data[bel.index].type; return chip_info.bel_data[bel.index].type;
} }
@ -434,7 +428,7 @@ struct Chip
BelPin getBelPinUphill(WireId wire) const BelPin getBelPinUphill(WireId wire) const
{ {
BelPin ret; BelPin ret;
assert(!wire.nil()); assert(wire != WireId());
if (chip_info.wire_data[wire.index].bel_uphill.bel_index >= 0) { if (chip_info.wire_data[wire.index].bel_uphill.bel_index >= 0) {
ret.bel.index = ret.bel.index =
@ -448,7 +442,7 @@ struct Chip
BelPinRange getBelPinsDownhill(WireId wire) const BelPinRange getBelPinsDownhill(WireId wire) const
{ {
BelPinRange range; BelPinRange range;
assert(!wire.nil()); assert(wire != WireId());
range.b.ptr = chip_info.wire_data[wire.index].bels_downhill; range.b.ptr = chip_info.wire_data[wire.index].bels_downhill;
range.e.ptr = range.e.ptr =
range.b.ptr + chip_info.wire_data[wire.index].num_bels_downhill; range.b.ptr + chip_info.wire_data[wire.index].num_bels_downhill;
@ -461,33 +455,33 @@ struct Chip
IdString getWireName(WireId wire) const IdString getWireName(WireId wire) const
{ {
assert(!wire.nil()); assert(wire != WireId());
return chip_info.wire_data[wire.index].name; return chip_info.wire_data[wire.index].name;
} }
void bindWire(WireId wire, IdString net) void bindWire(WireId wire, IdString net)
{ {
assert(!wire.nil()); assert(wire != WireId());
assert(wire_to_net[wire.index] == IdString()); assert(wire_to_net[wire.index] == IdString());
wire_to_net[wire.index] = net; wire_to_net[wire.index] = net;
} }
void unbindWire(WireId wire) void unbindWire(WireId wire)
{ {
assert(!wire.nil()); assert(wire != WireId());
assert(wire_to_net[wire.index] != IdString()); assert(wire_to_net[wire.index] != IdString());
wire_to_net[wire.index] = IdString(); wire_to_net[wire.index] = IdString();
} }
bool checkWireAvail(WireId wire) const bool checkWireAvail(WireId wire) const
{ {
assert(!wire.nil()); assert(wire != WireId());
return wire_to_net[wire.index] == IdString(); return wire_to_net[wire.index] == IdString();
} }
IdString getWireNet(WireId wire) const IdString getWireNet(WireId wire) const
{ {
assert(!wire.nil()); assert(wire != WireId());
return wire_to_net[wire.index]; return wire_to_net[wire.index];
} }
@ -505,7 +499,7 @@ struct Chip
IdString getPipName(PipId pip) const IdString getPipName(PipId pip) const
{ {
assert(!pip.nil()); assert(pip != PipId());
std::string src_name = std::string src_name =
chip_info.wire_data[chip_info.pip_data[pip.index].src].name; chip_info.wire_data[chip_info.pip_data[pip.index].src].name;
std::string dst_name = std::string dst_name =
@ -515,27 +509,27 @@ struct Chip
void bindPip(PipId pip, IdString net) void bindPip(PipId pip, IdString net)
{ {
assert(!pip.nil()); assert(pip != PipId());
assert(pip_to_net[pip.index] == IdString()); assert(pip_to_net[pip.index] == IdString());
pip_to_net[pip.index] = net; pip_to_net[pip.index] = net;
} }
void unbindPip(PipId pip) void unbindPip(PipId pip)
{ {
assert(!pip.nil()); assert(pip != PipId());
assert(pip_to_net[pip.index] != IdString()); assert(pip_to_net[pip.index] != IdString());
pip_to_net[pip.index] = IdString(); pip_to_net[pip.index] = IdString();
} }
bool checkPipAvail(PipId pip) const bool checkPipAvail(PipId pip) const
{ {
assert(!pip.nil()); assert(pip != PipId());
return pip_to_net[pip.index] == IdString(); return pip_to_net[pip.index] == IdString();
} }
IdString getPipNet(PipId pip) const IdString getPipNet(PipId pip) const
{ {
assert(!pip.nil()); assert(pip != PipId());
return pip_to_net[pip.index]; return pip_to_net[pip.index];
} }
@ -550,7 +544,7 @@ struct Chip
WireId getPipSrcWire(PipId pip) const WireId getPipSrcWire(PipId pip) const
{ {
WireId wire; WireId wire;
assert(!pip.nil()); assert(pip != PipId());
wire.index = chip_info.pip_data[pip.index].src; wire.index = chip_info.pip_data[pip.index].src;
return wire; return wire;
} }
@ -558,7 +552,7 @@ struct Chip
WireId getPipDstWire(PipId pip) const WireId getPipDstWire(PipId pip) const
{ {
WireId wire; WireId wire;
assert(!pip.nil()); assert(pip != PipId());
wire.index = chip_info.pip_data[pip.index].dst; wire.index = chip_info.pip_data[pip.index].dst;
return wire; return wire;
} }
@ -566,7 +560,7 @@ struct Chip
DelayInfo getPipDelay(PipId pip) const DelayInfo getPipDelay(PipId pip) const
{ {
DelayInfo delay; DelayInfo delay;
assert(!pip.nil()); assert(pip != PipId());
delay.delay = chip_info.pip_data[pip.index].delay; delay.delay = chip_info.pip_data[pip.index].delay;
return delay; return delay;
} }
@ -574,7 +568,7 @@ struct Chip
PipRange getPipsDownhill(WireId wire) const PipRange getPipsDownhill(WireId wire) const
{ {
PipRange range; PipRange range;
assert(!wire.nil()); assert(wire != WireId());
range.b.cursor = chip_info.wire_data[wire.index].pips_downhill; range.b.cursor = chip_info.wire_data[wire.index].pips_downhill;
range.e.cursor = range.e.cursor =
range.b.cursor + chip_info.wire_data[wire.index].num_downhill; range.b.cursor + chip_info.wire_data[wire.index].num_downhill;
@ -584,7 +578,7 @@ struct Chip
PipRange getPipsUphill(WireId wire) const PipRange getPipsUphill(WireId wire) const
{ {
PipRange range; PipRange range;
assert(!wire.nil()); assert(wire != WireId());
range.b.cursor = chip_info.wire_data[wire.index].pips_uphill; range.b.cursor = chip_info.wire_data[wire.index].pips_uphill;
range.e.cursor = range.e.cursor =
range.b.cursor + chip_info.wire_data[wire.index].num_uphill; range.b.cursor + chip_info.wire_data[wire.index].num_uphill;
@ -594,7 +588,7 @@ struct Chip
PipRange getWireAliases(WireId wire) const PipRange getWireAliases(WireId wire) const
{ {
PipRange range; PipRange range;
assert(!wire.nil()); assert(wire != WireId());
range.b.cursor = nullptr; range.b.cursor = nullptr;
range.e.cursor = nullptr; range.e.cursor = nullptr;
return range; return range;

View File

@ -318,7 +318,7 @@ for wire in range(num_wires):
if wire in wire_uphill_belport: if wire in wire_uphill_belport:
info += "{%d, PIN_%s}, " % wire_uphill_belport[wire] info += "{%d, PIN_%s}, " % wire_uphill_belport[wire]
else: else:
info += "{-1, PIN_NIL}, " info += "{-1, PIN_NONE}, "
info += ("wire%d_downbels, " % wire) if num_bels_downhill > 0 else "nullptr, " info += ("wire%d_downbels, " % wire) if num_bels_downhill > 0 else "nullptr, "

View File

@ -38,17 +38,11 @@ void arch_wrap_python()
.value("UP5K", ChipArgs::UP5K) .value("UP5K", ChipArgs::UP5K)
.export_values(); .export_values();
class_<BelId>("BelId") class_<BelId>("BelId").def_readwrite("index", &BelId::index);
.def_readwrite("index", &BelId::index)
.def("nil", &BelId::nil);
class_<WireId>("WireId") class_<WireId>("WireId").def_readwrite("index", &WireId::index);
.def_readwrite("index", &WireId::index)
.def("nil", &WireId::nil);
class_<PipId>("PipId") class_<PipId>("PipId").def_readwrite("index", &PipId::index);
.def_readwrite("index", &PipId::index)
.def("nil", &WireId::nil);
class_<BelPin>("BelPin") class_<BelPin>("BelPin")
.def_readwrite("bel", &BelPin::bel) .def_readwrite("bel", &BelPin::bel)