Skip to content

Commit ca7a609

Browse files
committed
Added serialization of property maps
Signed-off-by: Maciej Kurc <[email protected]>
1 parent 200aa75 commit ca7a609

File tree

1 file changed

+68
-15
lines changed

1 file changed

+68
-15
lines changed

vpr/src/base/write_interchange_netlist.cpp

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class NetlistBuilder {
3333
logical_netlist.setName(netlist_.netlist_name());
3434

3535
// Build and serialize cell library
36-
build_library(logical_netlist);
36+
buildLibrary(logical_netlist);
3737

3838
// Build and serialize the netlist
39-
build_netlist(logical_netlist);
39+
buildNetlist(logical_netlist);
4040

4141
// Serialize the string list
4242
auto strList = logical_netlist.initStrList(strings_.size());
@@ -49,12 +49,14 @@ class NetlistBuilder {
4949

5050
protected:
5151

52+
typedef std::unordered_map<std::string, std::string> Properties;
53+
5254
struct Port {
5355
uint32_t index;
5456
Direction dir;
5557
bool isBus;
5658
uint32_t bitLo, bitHi;
57-
// TODO: Property map
59+
Properties properties;
5860
};
5961

6062
struct PortInstance {
@@ -66,20 +68,20 @@ class NetlistBuilder {
6668

6769
struct Net {
6870
std::unordered_map<std::string, std::vector<PortInstance>> ports;
69-
// TODO: Property map
71+
Properties properties;
7072
};
7173

7274
struct CellDeclaration {
7375
uint32_t index;
7476
std::vector<std::string> ports;
75-
// TODO: Property map
77+
Properties properties;
7678
};
7779

7880
struct CellInstance {
7981
uint32_t index;
8082
std::string type;
8183
std::string name;
82-
// TODO: Property map
84+
Properties properties;
8385
};
8486

8587
struct Cell {
@@ -101,7 +103,7 @@ class NetlistBuilder {
101103

102104
// ....................................................
103105

104-
void build_library (LogicalNetlist::Netlist::Builder& logical_netlist) {
106+
void buildLibrary (LogicalNetlist::Netlist::Builder& logical_netlist) {
105107

106108
// Collect models and their ports
107109
std::unordered_map<std::string, const t_model*> models;
@@ -132,7 +134,9 @@ class NetlistBuilder {
132134
bus.setBusStart(port.bitLo);
133135
bus.setBusEnd(port.bitHi);
134136
}
135-
// TODO: Prop map
137+
138+
auto propMap = portList[port.index].initPropMap();
139+
buildPropertyMap(propMap, port.properties);
136140
}
137141

138142
// Serialize cell definitions
@@ -147,11 +151,13 @@ class NetlistBuilder {
147151
const auto& port = ports_.at(std::make_pair(it.first, decl.ports[i]));
148152
ports.set(i, port.index);
149153
}
150-
// TODO: Prop map
154+
155+
auto propMap = cellDecls[decl.index].initPropMap();
156+
buildPropertyMap(propMap, decl.properties);
151157
}
152158
}
153159

154-
void build_netlist (LogicalNetlist::Netlist::Builder& logical_netlist) {
160+
void buildNetlist (LogicalNetlist::Netlist::Builder& logical_netlist) {
155161

156162
// Add cell instances
157163
for (const auto blk : netlist_.blocks()) {
@@ -179,7 +185,9 @@ class NetlistBuilder {
179185
instList[inst.index].setName(strId(inst.name));
180186
instList[inst.index].setView(strId("netlist"));
181187
instList[inst.index].setCell(cellDeclarations_.at(inst.type).index);
182-
// TODO: Prop map
188+
189+
auto propMap = instList[inst.index].initPropMap();
190+
buildPropertyMap(propMap, inst.properties);
183191
}
184192

185193
// Serialize top-level instance
@@ -276,7 +284,9 @@ class NetlistBuilder {
276284
}
277285
}
278286

279-
// TODO: prop map
287+
// Property map
288+
auto propMap = nets[netIndex].initPropMap();
289+
buildPropertyMap(propMap, net.properties);
280290

281291
// Next net
282292
netIndex++;
@@ -287,6 +297,17 @@ class NetlistBuilder {
287297
}
288298
}
289299

300+
void buildPropertyMap (::LogicalNetlist::Netlist::PropertyMap::Builder& propertyMap, const Properties& properties) {
301+
auto entries = propertyMap.initEntries(properties.size());
302+
size_t index = 0;
303+
304+
for (const auto& it : properties) {
305+
entries[index].setKey(strId(it.first));
306+
entries[index].setTextValue(strId(it.second)); // FIXME: VPR keeps all attributes / parameters as strings
307+
index++;
308+
}
309+
}
310+
290311
// ....................................................
291312

292313
static bool isIoModel (const char* str) {
@@ -315,8 +336,6 @@ class NetlistBuilder {
315336
// Create a new cell declaration from the model
316337
CellDeclaration decl;
317338

318-
// TODO: Property map
319-
320339
// Collect ports
321340
for(t_model_ports* p=model->inputs; p; p=p->next) {
322341
addPort(model->name, p, Direction::INPUT);
@@ -327,6 +346,13 @@ class NetlistBuilder {
327346
decl.ports.push_back(p->name);
328347
}
329348

349+
// Cell definition properties
350+
// FIXME: Should those information be written as properties? What
351+
// should be the mapping of those attributes to interchange properties ?
352+
if (model->never_prune) {
353+
decl.properties["never_prune"] = "1";
354+
}
355+
330356
// Add it
331357
decl.index = cellDeclarations_.size();
332358
cellDeclarations_.emplace(std::make_pair(model->name, decl));
@@ -354,6 +380,16 @@ class NetlistBuilder {
354380
port.bitHi = 0;
355381
}
356382

383+
// Port properties
384+
// FIXME: Should those information be written as properties? What
385+
// should be the mapping of those attributes to interchange properties ?
386+
if (modelPort->is_clock) {
387+
port.properties["is_clock"] = "1";
388+
}
389+
if (modelPort->is_non_clock_global) {
390+
port.properties["is_non_clock_global"] = "1";
391+
}
392+
357393
// Add the port
358394
port.index = ports_.size();
359395
ports_.emplace(std::make_pair(std::make_pair(modelName, modelPort->name), port));
@@ -368,7 +404,24 @@ class NetlistBuilder {
368404
inst.name = netlist_.block_name(block);
369405
inst.type = model->name;
370406

371-
// TODO: Property map
407+
// Collect attributes and parameters
408+
auto addProperty = [&](const std::pair<std::string, std::string>& prop) {
409+
if (inst.properties.count(prop.first)) {
410+
VTR_LOG_WARN("Duplicate property '%s'='%s' of cell instance '%s'\n",
411+
prop.first.c_str(), prop.second.c_str(), inst.name.c_str());
412+
} else {
413+
inst.properties.insert(prop);
414+
}
415+
};
416+
417+
// FIXME: The FPGA Interchange logical netlist format does not
418+
// differentiate between attributes and parameters.
419+
for (const auto& it : netlist_.block_attrs(block)) {
420+
addProperty(it);
421+
}
422+
for (const auto& it : netlist_.block_params(block)) {
423+
addProperty(it);
424+
}
372425

373426
// Add the cell instance
374427
inst.index = cellInstances_.size();

0 commit comments

Comments
 (0)