aboutsummaryrefslogtreecommitdiffstats
path: root/apidraft.h
blob: f6e5a44b66ed4b5bfaa468574bc02e35fb179701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdint.h>
#include <string>

// replace with proper IdString later
typedef std::string IdString;

// -------------------------------------------------------
// Arch-specific declarations

#ifdef ARCH_ICE40
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));

struct ObjIterator
{
	// ...
	ObjId operator*() const;
};

struct ObjRange
{
	ObjIterator begin();
	ObjIterator end();
};

struct BelPin
{
	ObjId bel;
	IdString pin;
};

struct BelPinIterator
{
	// ...
	BelPin operator*() const;
};

struct BelPinRange
{
	BelPinIterator begin();
	BelPinIterator end();
};

struct GuiLine
{
	float x1, y1, x2, y2;
};

struct Chip
{
	Chip(std::string cfg);

	ObjId getObjByName(IdString name) const;
	IdString getObjName(ObjId obj) const;
	IdString getBelType(ObjId obj) const;
	ObjRange getBelsByType(IdString type) const;

	void getObjPosition(ObjId obj, float &x, float &y) const;
	vector<GuiLine> getGuiLines(ObjId obj) const;

	ObjRange getWires() const;
	ObjRange getWiresUphillWire(ObjId wire) const;
	ObjRange getWiresDownhillWire(ObjId wire) const;
	ObjRange getWiresBidirWire(ObjId wire) const;
	ObjRange getWireAliases(ObjId wire) const;

	ObjId getWireBelPin(ObjId bel, IdString pin) const;
	BelPin getBelPinUphillWire(ObjId wire) const;
	BelPinRange getBelPinsDownhillWire(ObjId wire) const;
};
#endif

// -------------------------------------------------------
// Generic declarations

struct PortRef
{
	IdString cell_name;
	IdString port_name;
};

struct NetInfo
{
	IdString name;
	PortRef driver;
	vector<PortRef> users;
	dict<IdString, std::string> attrs;

	// wire objid -> signal delay
	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;
	// port_name -> pin_name
	dict<IdString, IdString> pins;
};

struct Design
{
	struct Chip;

	Design(std::string chipCfg) : Chip(chipCfg) {
		// ...
	}

	dict<IdString, *NetInfo> nets;
	dict<IdString, *CellInfo> cells;
};