2018-05-23 11:35:49 +02:00
|
|
|
#include <stdint.h>
|
2018-05-23 17:58:57 +02:00
|
|
|
#include <vector>
|
2018-05-23 11:35:49 +02:00
|
|
|
#include <string>
|
2018-05-23 17:58:57 +02:00
|
|
|
#include <unordered_set>
|
|
|
|
|
#include <unordered_map>
|
2018-05-23 11:35:49 +02:00
|
|
|
|
|
|
|
|
// replace with proper IdString later
|
|
|
|
|
typedef std::string IdString;
|
|
|
|
|
|
2018-05-23 17:58:57 +02:00
|
|
|
// replace with haslib later
|
|
|
|
|
template<typename T> using pool = std::unordered_set<T>;
|
|
|
|
|
template<typename T, typename U> using dict = std::unordered_map<T, U>;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2018-05-23 11:35:49 +02:00
|
|
|
// -------------------------------------------------------
|
|
|
|
|
// Arch-specific declarations
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
struct BelId
|
|
|
|
|
{
|
|
|
|
|
uint8_t tile_x = 0, tile_y = 0;
|
|
|
|
|
uint16_t index = 0;
|
|
|
|
|
|
|
|
|
|
bool nil() const {
|
|
|
|
|
return !tile_x && !tile_y && !index;
|
|
|
|
|
}
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
|
struct WireId
|
2018-05-23 11:35:49 +02:00
|
|
|
{
|
|
|
|
|
uint8_t tile_x = 0, tile_y = 0;
|
|
|
|
|
uint16_t index = 0;
|
|
|
|
|
|
|
|
|
|
bool nil() const {
|
|
|
|
|
return !tile_x && !tile_y && !index;
|
|
|
|
|
}
|
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
2018-05-23 17:58:57 +02:00
|
|
|
namespace std
|
|
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
template<> struct hash<BelId>
|
|
|
|
|
{
|
|
|
|
|
std::size_t operator()(const BelId &bel) const noexcept
|
|
|
|
|
{
|
|
|
|
|
std::size_t result = std::hash<int>{}(bel.index);
|
|
|
|
|
result ^= std::hash<int>{}(bel.tile_x) + 0x9e3779b9 + (result << 6) + (result >> 2);
|
|
|
|
|
result ^= std::hash<int>{}(bel.tile_y) + 0x9e3779b9 + (result << 6) + (result >> 2);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<> struct hash<WireId>
|
2018-05-23 17:58:57 +02:00
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
std::size_t operator()(const WireId &wire) const noexcept
|
2018-05-23 17:58:57 +02:00
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
std::size_t result = std::hash<int>{}(wire.index);
|
|
|
|
|
result ^= std::hash<int>{}(wire.tile_x) + 0x9e3779b9 + (result << 6) + (result >> 2);
|
|
|
|
|
result ^= std::hash<int>{}(wire.tile_y) + 0x9e3779b9 + (result << 6) + (result >> 2);
|
2018-05-23 17:58:57 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
struct BelIterator
|
|
|
|
|
{
|
|
|
|
|
BelId *ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
void operator++() { ptr++; }
|
|
|
|
|
bool operator!=(const BelIterator &other) const { return ptr != other.ptr; }
|
|
|
|
|
BelId operator*() const { return *ptr; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BelRange
|
2018-05-23 11:35:49 +02:00
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
BelIterator b, e;
|
|
|
|
|
BelIterator begin() const { return b; }
|
|
|
|
|
BelIterator end() const { return e; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct WireIterator
|
|
|
|
|
{
|
|
|
|
|
WireId *ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
void operator++() { ptr++; }
|
|
|
|
|
bool operator!=(const WireIterator &other) const { return ptr != other.ptr; }
|
|
|
|
|
WireId operator*() const { return *ptr; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct WireRange
|
|
|
|
|
{
|
|
|
|
|
WireIterator b, e;
|
|
|
|
|
WireIterator begin() const { return b; }
|
|
|
|
|
WireIterator end() const { return e; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct WireDelay
|
|
|
|
|
{
|
|
|
|
|
WireId wire;
|
|
|
|
|
float delay;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct WireDelayIterator
|
|
|
|
|
{
|
|
|
|
|
WireDelay *ptr = nullptr;
|
2018-05-23 17:58:57 +02:00
|
|
|
|
|
|
|
|
void operator++() { ptr++; }
|
2018-05-26 10:36:33 +02:00
|
|
|
bool operator!=(const WireDelayIterator &other) const { return ptr != other.ptr; }
|
|
|
|
|
WireDelay operator*() const { return *ptr; }
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
struct WireDelayRange
|
2018-05-23 11:35:49 +02:00
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
WireDelayIterator b, e;
|
|
|
|
|
WireDelayIterator begin() const { return b; }
|
|
|
|
|
WireDelayIterator end() const { return e; }
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BelPin
|
|
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
BelId bel;
|
2018-05-23 11:35:49 +02:00
|
|
|
IdString pin;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BelPinIterator
|
|
|
|
|
{
|
2018-05-23 17:58:57 +02:00
|
|
|
BelPin *ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
void operator++() { ptr++; }
|
|
|
|
|
bool operator!=(const BelPinIterator &other) const { return ptr != other.ptr; }
|
|
|
|
|
BelPin operator*() const { return *ptr; }
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BelPinRange
|
|
|
|
|
{
|
2018-05-23 17:58:57 +02:00
|
|
|
BelPinIterator b, e;
|
|
|
|
|
BelPinIterator begin() const { return b; }
|
|
|
|
|
BelPinIterator end() const { return e; }
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GuiLine
|
|
|
|
|
{
|
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
struct ChipArgs
|
|
|
|
|
{
|
|
|
|
|
// ...
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-23 11:35:49 +02:00
|
|
|
struct Chip
|
|
|
|
|
{
|
2018-05-23 14:53:55 +02:00
|
|
|
// ...
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
Chip(ChipArgs args);
|
2018-05-23 11:35:49 +02:00
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
void setBelActive(BelId bel, bool active);
|
|
|
|
|
bool getBelActive(BelId bel);
|
2018-05-23 14:53:55 +02:00
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
BelId getBelByName(IdString name) const;
|
|
|
|
|
WireId getWireByName(IdString name) const;
|
|
|
|
|
IdString getBelName(BelId bel) const;
|
|
|
|
|
IdString getWireName(WireId wire) const;
|
2018-05-23 14:53:55 +02:00
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
BelRange getBels() const;
|
|
|
|
|
BelRange getBelsByType(IdString type) const;
|
|
|
|
|
IdString getBelType(BelId bel) const;
|
2018-05-23 11:35:49 +02:00
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
void getBelPosition(BelId bel, float &x, float &y) const;
|
|
|
|
|
void getWirePosition(WireId wire, float &x, float &y) const;
|
|
|
|
|
vector<GuiLine> getBelGuiLines(BelId bel) const;
|
|
|
|
|
vector<GuiLine> getWireGuiLines(WireId wire) const;
|
2018-05-23 11:35:49 +02:00
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
WireRange getWires() const;
|
|
|
|
|
WireDelayRange getWiresUphill(WireId wire) const;
|
|
|
|
|
WireDelayRange getWiresDownhill(WireId wire) const;
|
|
|
|
|
WireDelayRange getWiresBidir(WireId wire) const;
|
|
|
|
|
WireDelayRange getWireAliases(WireId wire) const;
|
2018-05-23 11:35:49 +02:00
|
|
|
|
2018-05-23 14:53:55 +02:00
|
|
|
// the following will only operate on / return "active" BELs
|
|
|
|
|
// multiple active uphill BELs for a wire will cause a runtime error
|
2018-05-26 10:36:33 +02:00
|
|
|
WireId getWireBelPin(BelId bel, IdString pin) const;
|
|
|
|
|
BelPin getBelPinUphill(WireId wire) const;
|
|
|
|
|
BelPinRange getBelPinsDownhill(WireId wire) const;
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------
|
|
|
|
|
// Generic declarations
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
struct CellInfo;
|
|
|
|
|
|
2018-05-23 11:35:49 +02:00
|
|
|
struct PortRef
|
|
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
CellInfo *cell;
|
|
|
|
|
IdString port;
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NetInfo
|
|
|
|
|
{
|
|
|
|
|
IdString name;
|
|
|
|
|
PortRef driver;
|
|
|
|
|
vector<PortRef> users;
|
|
|
|
|
dict<IdString, std::string> attrs;
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
// wire -> (uphill_wire, delay)
|
|
|
|
|
dict<WireId, std::pair<WireId, float>> wires;
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum PortType
|
|
|
|
|
{
|
|
|
|
|
PORT_IN = 0,
|
|
|
|
|
PORT_OUT = 1,
|
|
|
|
|
PORT_INOUT = 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PortInfo
|
|
|
|
|
{
|
2018-05-26 10:36:33 +02:00
|
|
|
IdString name;
|
|
|
|
|
NetInfo *net;
|
2018-05-23 11:35:49 +02:00
|
|
|
PortType type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CellInfo
|
|
|
|
|
{
|
|
|
|
|
IdString name, type;
|
|
|
|
|
dict<IdString, PortInfo> ports;
|
|
|
|
|
dict<IdString, std::string> attrs, params;
|
|
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
BelId bel;
|
2018-05-23 14:53:55 +02:00
|
|
|
// cell_port -> bel_pin
|
2018-05-23 11:35:49 +02:00
|
|
|
dict<IdString, IdString> pins;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Design
|
|
|
|
|
{
|
2018-05-23 17:58:57 +02:00
|
|
|
struct Chip chip;
|
2018-05-23 11:35:49 +02:00
|
|
|
|
2018-05-26 10:36:33 +02:00
|
|
|
Design(ChipArgs args) : chip(args) {
|
2018-05-23 11:35:49 +02:00
|
|
|
// ...
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 17:58:57 +02:00
|
|
|
dict<IdString, NetInfo*> nets;
|
|
|
|
|
dict<IdString, CellInfo*> cells;
|
2018-05-23 11:35:49 +02:00
|
|
|
};
|