2018-05-23 17:35:49 +08:00
|
|
|
#include <stdint.h>
|
2018-05-23 23:58:57 +08:00
|
|
|
#include <vector>
|
2018-05-23 17:35:49 +08:00
|
|
|
#include <string>
|
2018-05-23 23:58:57 +08:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <unordered_map>
|
2018-05-23 17:35:49 +08:00
|
|
|
|
|
|
|
// replace with proper IdString later
|
|
|
|
typedef std::string IdString;
|
|
|
|
|
2018-05-23 23:58:57 +08: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 17:35:49 +08:00
|
|
|
// -------------------------------------------------------
|
|
|
|
// Arch-specific declarations
|
|
|
|
|
|
|
|
struct ObjId
|
|
|
|
{
|
|
|
|
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 23:58:57 +08:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template<> struct hash<ObjId>
|
|
|
|
{
|
|
|
|
std::size_t operator()(const ObjId &obj) const noexcept
|
|
|
|
{
|
|
|
|
std::size_t result = std::hash<int>{}(obj.index);
|
|
|
|
result ^= std::hash<int>{}(obj.tile_x) + 0x9e3779b9 + (result << 6) + (result >> 2);
|
|
|
|
result ^= std::hash<int>{}(obj.tile_y) + 0x9e3779b9 + (result << 6) + (result >> 2);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-23 17:35:49 +08:00
|
|
|
struct ObjIterator
|
|
|
|
{
|
2018-05-23 23:58:57 +08:00
|
|
|
ObjId *ptr = nullptr;
|
|
|
|
|
|
|
|
void operator++() { ptr++; }
|
|
|
|
bool operator!=(const ObjIterator &other) const { return ptr != other.ptr; }
|
|
|
|
ObjId operator*() const { return *ptr; }
|
2018-05-23 17:35:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjRange
|
|
|
|
{
|
2018-05-23 23:58:57 +08:00
|
|
|
ObjIterator b, e;
|
|
|
|
ObjIterator begin() const { return b; }
|
|
|
|
ObjIterator end() const { return e; }
|
2018-05-23 17:35:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BelPin
|
|
|
|
{
|
|
|
|
ObjId bel;
|
|
|
|
IdString pin;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BelPinIterator
|
|
|
|
{
|
2018-05-23 23:58:57 +08: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 17:35:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BelPinRange
|
|
|
|
{
|
2018-05-23 23:58:57 +08:00
|
|
|
BelPinIterator b, e;
|
|
|
|
BelPinIterator begin() const { return b; }
|
|
|
|
BelPinIterator end() const { return e; }
|
2018-05-23 17:35:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GuiLine
|
|
|
|
{
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Chip
|
|
|
|
{
|
2018-05-23 20:53:55 +08:00
|
|
|
// ...
|
|
|
|
|
2018-05-23 17:35:49 +08:00
|
|
|
Chip(std::string cfg);
|
|
|
|
|
2018-05-23 20:53:55 +08:00
|
|
|
void setBelActive(ObjId bel, bool active);
|
|
|
|
bool getBelActive(ObjId bel);
|
|
|
|
|
2018-05-23 17:35:49 +08:00
|
|
|
ObjId getObjByName(IdString name) const;
|
|
|
|
IdString getObjName(ObjId obj) const;
|
2018-05-23 20:53:55 +08:00
|
|
|
|
|
|
|
ObjRange getBels() const;
|
2018-05-23 17:35:49 +08:00
|
|
|
ObjRange getBelsByType(IdString type) const;
|
2018-05-23 20:53:55 +08:00
|
|
|
IdString getBelType(ObjId bel) const;
|
2018-05-23 17:35:49 +08:00
|
|
|
|
|
|
|
void getObjPosition(ObjId obj, float &x, float &y) const;
|
|
|
|
vector<GuiLine> getGuiLines(ObjId obj) const;
|
|
|
|
|
|
|
|
ObjRange getWires() const;
|
2018-05-23 20:53:55 +08:00
|
|
|
ObjRange getWiresUphill(ObjId wire) const;
|
|
|
|
ObjRange getWiresDownhill(ObjId wire) const;
|
|
|
|
ObjRange getWiresBidir(ObjId wire) const;
|
2018-05-23 17:35:49 +08:00
|
|
|
ObjRange getWireAliases(ObjId wire) const;
|
|
|
|
|
2018-05-23 20:53:55 +08:00
|
|
|
// the following will only operate on / return "active" BELs
|
|
|
|
// multiple active uphill BELs for a wire will cause a runtime error
|
2018-05-23 17:35:49 +08:00
|
|
|
ObjId getWireBelPin(ObjId bel, IdString pin) const;
|
2018-05-23 20:53:55 +08:00
|
|
|
BelPin getBelPinUphill(ObjId wire) const;
|
|
|
|
BelPinRange getBelPinsDownhill(ObjId wire) const;
|
2018-05-23 17:35:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// Generic declarations
|
|
|
|
|
|
|
|
struct PortRef
|
|
|
|
{
|
|
|
|
IdString cell_name;
|
|
|
|
IdString port_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NetInfo
|
|
|
|
{
|
|
|
|
IdString name;
|
|
|
|
PortRef driver;
|
|
|
|
vector<PortRef> users;
|
|
|
|
dict<IdString, std::string> attrs;
|
|
|
|
|
2018-05-23 20:53:55 +08:00
|
|
|
// wire -> delay
|
2018-05-23 17:35:49 +08:00
|
|
|
dict<ObjId, float> wires;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum PortType
|
|
|
|
{
|
|
|
|
PORT_IN = 0,
|
|
|
|
PORT_OUT = 1,
|
|
|
|
PORT_INOUT = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PortInfo
|
|
|
|
{
|
|
|
|
IdString name, net;
|
|
|
|
PortType type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CellInfo
|
|
|
|
{
|
|
|
|
IdString name, type;
|
|
|
|
dict<IdString, PortInfo> ports;
|
|
|
|
dict<IdString, std::string> attrs, params;
|
|
|
|
|
|
|
|
ObjId bel;
|
2018-05-23 20:53:55 +08:00
|
|
|
// cell_port -> bel_pin
|
2018-05-23 17:35:49 +08:00
|
|
|
dict<IdString, IdString> pins;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Design
|
|
|
|
{
|
2018-05-23 23:58:57 +08:00
|
|
|
struct Chip chip;
|
2018-05-23 17:35:49 +08:00
|
|
|
|
2018-05-23 23:58:57 +08:00
|
|
|
Design(std::string chipCfg) : chip(chipCfg) {
|
2018-05-23 17:35:49 +08:00
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
2018-05-23 23:58:57 +08:00
|
|
|
dict<IdString, NetInfo*> nets;
|
|
|
|
dict<IdString, CellInfo*> cells;
|
2018-05-23 17:35:49 +08:00
|
|
|
};
|