@@ -33,10 +33,10 @@ class NetlistBuilder {
33
33
logical_netlist.setName (netlist_.netlist_name ());
34
34
35
35
// Build and serialize cell library
36
- build_library (logical_netlist);
36
+ buildLibrary (logical_netlist);
37
37
38
38
// Build and serialize the netlist
39
- build_netlist (logical_netlist);
39
+ buildNetlist (logical_netlist);
40
40
41
41
// Serialize the string list
42
42
auto strList = logical_netlist.initStrList (strings_.size ());
@@ -49,12 +49,14 @@ class NetlistBuilder {
49
49
50
50
protected:
51
51
52
+ typedef std::unordered_map<std::string, std::string> Properties;
53
+
52
54
struct Port {
53
55
uint32_t index;
54
56
Direction dir;
55
57
bool isBus;
56
58
uint32_t bitLo, bitHi;
57
- // TODO: Property map
59
+ Properties properties;
58
60
};
59
61
60
62
struct PortInstance {
@@ -66,20 +68,20 @@ class NetlistBuilder {
66
68
67
69
struct Net {
68
70
std::unordered_map<std::string, std::vector<PortInstance>> ports;
69
- // TODO: Property map
71
+ Properties properties;
70
72
};
71
73
72
74
struct CellDeclaration {
73
75
uint32_t index;
74
76
std::vector<std::string> ports;
75
- // TODO: Property map
77
+ Properties properties;
76
78
};
77
79
78
80
struct CellInstance {
79
81
uint32_t index;
80
82
std::string type;
81
83
std::string name;
82
- // TODO: Property map
84
+ Properties properties;
83
85
};
84
86
85
87
struct Cell {
@@ -101,7 +103,7 @@ class NetlistBuilder {
101
103
102
104
// ....................................................
103
105
104
- void build_library (LogicalNetlist::Netlist::Builder& logical_netlist) {
106
+ void buildLibrary (LogicalNetlist::Netlist::Builder& logical_netlist) {
105
107
106
108
// Collect models and their ports
107
109
std::unordered_map<std::string, const t_model*> models;
@@ -132,7 +134,9 @@ class NetlistBuilder {
132
134
bus.setBusStart (port.bitLo );
133
135
bus.setBusEnd (port.bitHi );
134
136
}
135
- // TODO: Prop map
137
+
138
+ auto propMap = portList[port.index ].initPropMap ();
139
+ buildPropertyMap (propMap, port.properties );
136
140
}
137
141
138
142
// Serialize cell definitions
@@ -147,11 +151,13 @@ class NetlistBuilder {
147
151
const auto & port = ports_.at (std::make_pair (it.first , decl.ports [i]));
148
152
ports.set (i, port.index );
149
153
}
150
- // TODO: Prop map
154
+
155
+ auto propMap = cellDecls[decl.index ].initPropMap ();
156
+ buildPropertyMap (propMap, decl.properties );
151
157
}
152
158
}
153
159
154
- void build_netlist (LogicalNetlist::Netlist::Builder& logical_netlist) {
160
+ void buildNetlist (LogicalNetlist::Netlist::Builder& logical_netlist) {
155
161
156
162
// Add cell instances
157
163
for (const auto blk : netlist_.blocks ()) {
@@ -179,7 +185,9 @@ class NetlistBuilder {
179
185
instList[inst.index ].setName (strId (inst.name ));
180
186
instList[inst.index ].setView (strId (" netlist" ));
181
187
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 );
183
191
}
184
192
185
193
// Serialize top-level instance
@@ -276,7 +284,9 @@ class NetlistBuilder {
276
284
}
277
285
}
278
286
279
- // TODO: prop map
287
+ // Property map
288
+ auto propMap = nets[netIndex].initPropMap ();
289
+ buildPropertyMap (propMap, net.properties );
280
290
281
291
// Next net
282
292
netIndex++;
@@ -287,6 +297,17 @@ class NetlistBuilder {
287
297
}
288
298
}
289
299
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
+
290
311
// ....................................................
291
312
292
313
static bool isIoModel (const char * str) {
@@ -315,8 +336,6 @@ class NetlistBuilder {
315
336
// Create a new cell declaration from the model
316
337
CellDeclaration decl;
317
338
318
- // TODO: Property map
319
-
320
339
// Collect ports
321
340
for (t_model_ports* p=model->inputs ; p; p=p->next ) {
322
341
addPort (model->name , p, Direction::INPUT);
@@ -327,6 +346,13 @@ class NetlistBuilder {
327
346
decl.ports .push_back (p->name );
328
347
}
329
348
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
+
330
356
// Add it
331
357
decl.index = cellDeclarations_.size ();
332
358
cellDeclarations_.emplace (std::make_pair (model->name , decl));
@@ -354,6 +380,16 @@ class NetlistBuilder {
354
380
port.bitHi = 0 ;
355
381
}
356
382
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
+
357
393
// Add the port
358
394
port.index = ports_.size ();
359
395
ports_.emplace (std::make_pair (std::make_pair (modelName, modelPort->name ), port));
@@ -368,7 +404,24 @@ class NetlistBuilder {
368
404
inst.name = netlist_.block_name (block);
369
405
inst.type = model->name ;
370
406
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
+ }
372
425
373
426
// Add the cell instance
374
427
inst.index = cellInstances_.size ();
0 commit comments