13
13
14
14
#include < zlib.h>
15
15
16
-
17
16
// ============================================================================
18
17
19
-
20
18
class NetlistBuilder {
21
- public:
22
-
19
+ public:
23
20
using Direction = ::LogicalNetlist::Netlist::Direction;
24
21
25
22
// ....................................................
26
23
27
- NetlistBuilder (const AtomNetlist& netlist, const t_arch& arch) :
28
- netlist_ (netlist),
29
- arch_ (arch)
30
- {}
24
+ NetlistBuilder (const AtomNetlist& netlist, const t_arch& arch)
25
+ : netlist_(netlist)
26
+ , arch_(arch) {}
31
27
32
- void build (LogicalNetlist::Netlist::Builder& logical_netlist) {
28
+ void build (LogicalNetlist::Netlist::Builder& logical_netlist) {
33
29
logical_netlist.setName (netlist_.netlist_name ());
34
30
35
31
// Build and serialize cell library
@@ -47,8 +43,7 @@ class NetlistBuilder {
47
43
48
44
// ....................................................
49
45
50
- protected:
51
-
46
+ protected:
52
47
typedef std::unordered_map<std::string, std::string> Properties;
53
48
54
49
struct Port {
@@ -103,8 +98,7 @@ class NetlistBuilder {
103
98
104
99
// ....................................................
105
100
106
- void buildLibrary (LogicalNetlist::Netlist::Builder& logical_netlist) {
107
-
101
+ void buildLibrary (LogicalNetlist::Netlist::Builder& logical_netlist) {
108
102
// Collect models and their ports
109
103
std::unordered_map<std::string, const t_model*> models;
110
104
for (const auto blk : netlist_.blocks ()) {
@@ -147,7 +141,7 @@ class NetlistBuilder {
147
141
cellDecls[decl.index ].setView (strId (" netlist" ));
148
142
cellDecls[decl.index ].setLib (strId (" work" ));
149
143
auto ports = cellDecls[decl.index ].initPorts (decl.ports .size ());
150
- for (size_t i= 0 ; i< decl.ports .size (); ++i) {
144
+ for (size_t i = 0 ; i < decl.ports .size (); ++i) {
151
145
const auto & port = ports_.at (std::make_pair (it.first , decl.ports [i]));
152
146
ports.set (i, port.index );
153
147
}
@@ -157,8 +151,7 @@ class NetlistBuilder {
157
151
}
158
152
}
159
153
160
- void buildNetlist (LogicalNetlist::Netlist::Builder& logical_netlist) {
161
-
154
+ void buildNetlist (LogicalNetlist::Netlist::Builder& logical_netlist) {
162
155
// Add cell instances
163
156
for (const auto blk : netlist_.blocks ()) {
164
157
const t_model* model = netlist_.block_model (blk);
@@ -230,22 +223,21 @@ class NetlistBuilder {
230
223
auto cellList = logical_netlist.initCellList (groups.size ());
231
224
size_t groupIndex = 0 ;
232
225
for (const auto & it : groups) {
233
- const auto type = it.first ;
226
+ const auto type = it.first ;
234
227
const auto & group = it.second ;
235
228
236
229
cellList[groupIndex].setIndex (cellDeclarations_.at (type).index );
237
230
238
231
// Instances
239
232
auto insts = cellList[groupIndex].initInsts (group.instances .size ());
240
- for (size_t i= 0 ; i< group.instances .size (); ++i) {
233
+ for (size_t i = 0 ; i < group.instances .size (); ++i) {
241
234
insts.set (i, group.instances [i]);
242
235
}
243
236
244
237
// Nets
245
238
auto nets = cellList[groupIndex].initNets (group.nets .size ());
246
239
size_t netIndex = 0 ;
247
240
for (const auto & net_name : group.nets ) {
248
-
249
241
VTR_ASSERT (nets_.find (net_name) != nets_.end ());
250
242
const auto & net = nets_.at (net_name);
251
243
@@ -264,10 +256,8 @@ class NetlistBuilder {
264
256
265
257
// Serialize
266
258
auto portInsts = nets[netIndex].initPortInsts (ports.size ());
267
- for (size_t i=0 ; i<ports.size (); ++i) {
268
-
269
- auto key = ports[i].isTop ? std::make_pair (netlist_.netlist_name (), net_name) :
270
- std::make_pair (type, ports[i].port );
259
+ for (size_t i = 0 ; i < ports.size (); ++i) {
260
+ auto key = ports[i].isTop ? std::make_pair (netlist_.netlist_name (), net_name) : std::make_pair (type, ports[i].port );
271
261
272
262
const auto & port = ports_.at (key);
273
263
portInsts[i].setPort (port.index );
@@ -297,7 +287,7 @@ class NetlistBuilder {
297
287
}
298
288
}
299
289
300
- void buildPropertyMap (::LogicalNetlist::Netlist::PropertyMap::Builder& propertyMap, const Properties& properties) {
290
+ void buildPropertyMap (::LogicalNetlist::Netlist::PropertyMap::Builder& propertyMap, const Properties& properties) {
301
291
auto entries = propertyMap.initEntries (properties.size ());
302
292
size_t index = 0 ;
303
293
@@ -310,12 +300,11 @@ class NetlistBuilder {
310
300
311
301
// ....................................................
312
302
313
- static bool isIoModel (const char * str) {
314
- return !strcmp (str, MODEL_INPUT) ||
315
- !strcmp (str, MODEL_OUTPUT);
303
+ static bool isIoModel (const char * str) {
304
+ return !strcmp (str, MODEL_INPUT) || !strcmp (str, MODEL_OUTPUT);
316
305
}
317
306
318
- uint32_t strId (const std::string& str) {
307
+ uint32_t strId (const std::string& str) {
319
308
if (strings_.count (str)) {
320
309
return strings_[str];
321
310
} else {
@@ -325,8 +314,7 @@ class NetlistBuilder {
325
314
}
326
315
}
327
316
328
- void addCellDeclaration (const t_model* model) {
329
-
317
+ void addCellDeclaration (const t_model* model) {
330
318
// Already exists
331
319
auto it = cellDeclarations_.find (model->name );
332
320
if (it != cellDeclarations_.end ()) {
@@ -337,11 +325,11 @@ class NetlistBuilder {
337
325
CellDeclaration decl;
338
326
339
327
// Collect ports
340
- for (t_model_ports* p= model->inputs ; p; p= p->next ) {
328
+ for (t_model_ports* p = model->inputs ; p; p = p->next ) {
341
329
addPort (model->name , p, Direction::INPUT);
342
330
decl.ports .push_back (p->name );
343
331
}
344
- for (t_model_ports* p= model->outputs ; p; p= p->next ) {
332
+ for (t_model_ports* p = model->outputs ; p; p = p->next ) {
345
333
addPort (model->name , p, Direction::OUTPUT);
346
334
decl.ports .push_back (p->name );
347
335
}
@@ -358,8 +346,7 @@ class NetlistBuilder {
358
346
cellDeclarations_.emplace (std::make_pair (model->name , decl));
359
347
}
360
348
361
- void addPort (const std::string& modelName, const t_model_ports* modelPort, Direction dir) {
362
-
349
+ void addPort (const std::string& modelName, const t_model_ports* modelPort, Direction dir) {
363
350
// Already exists
364
351
auto it = ports_.find (std::make_pair (modelName, modelPort->name ));
365
352
if (it != ports_.end ()) {
@@ -369,7 +356,7 @@ class NetlistBuilder {
369
356
// Build the port
370
357
Port port;
371
358
port.dir = dir;
372
-
359
+
373
360
if (modelPort->size > 1 ) {
374
361
port.isBus = true ;
375
362
port.bitLo = 0 ;
@@ -390,12 +377,12 @@ class NetlistBuilder {
390
377
port.properties [" is_non_clock_global" ] = " 1" ;
391
378
}
392
379
393
- // Add the port
380
+ // Add the port
394
381
port.index = ports_.size ();
395
382
ports_.emplace (std::make_pair (std::make_pair (modelName, modelPort->name ), port));
396
383
};
397
384
398
- uint32_t addCellInstance (const AtomBlockId& block) {
385
+ uint32_t addCellInstance (const AtomBlockId& block) {
399
386
const t_model* model = netlist_.block_model (block);
400
387
VTR_ASSERT (model != nullptr );
401
388
@@ -408,7 +395,7 @@ class NetlistBuilder {
408
395
auto addProperty = [&](const std::pair<std::string, std::string>& prop) {
409
396
if (inst.properties .count (prop.first )) {
410
397
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 ());
398
+ prop.first .c_str (), prop.second .c_str (), inst.name .c_str ());
412
399
} else {
413
400
inst.properties .insert (prop);
414
401
}
@@ -431,30 +418,28 @@ class NetlistBuilder {
431
418
return inst.index ;
432
419
}
433
420
434
- void addNet (const AtomNetId& net_id) {
435
-
421
+ void addNet (const AtomNetId& net_id) {
436
422
Net net;
437
423
438
424
// Handle driver / endpoints
439
425
for (const auto & pin_id : netlist_.net_pins (net_id)) {
440
-
441
426
// Block
442
- const auto & blk_id = netlist_.pin_block (pin_id);
443
- const auto & blk_name = netlist_.block_name (blk_id);
427
+ const auto & blk_id = netlist_.pin_block (pin_id);
428
+ const auto & blk_name = netlist_.block_name (blk_id);
444
429
445
430
// Port / bit
446
- const auto & port_id = netlist_.pin_port (pin_id);
447
- const auto & port_bit = netlist_.pin_port_bit (pin_id);
431
+ const auto & port_id = netlist_.pin_port (pin_id);
432
+ const auto & port_bit = netlist_.pin_port_bit (pin_id);
448
433
const auto & port_name = netlist_.port_name (port_id);
449
434
450
435
// Find the cell declaration
451
436
const t_model* model = netlist_.block_model (blk_id);
452
437
VTR_ASSERT (model != nullptr );
453
438
454
- PortInstance portInst;
455
- portInst.cell = blk_name;
456
- portInst.port = port_name;
457
- portInst.bit = port_bit;
439
+ PortInstance portInst;
440
+ portInst.cell = blk_name;
441
+ portInst.port = port_name;
442
+ portInst.bit = port_bit;
458
443
portInst.isTop = isIoModel (model->name );
459
444
460
445
net.ports [model->name ].push_back (portInst);
@@ -466,8 +451,7 @@ class NetlistBuilder {
466
451
nets_.emplace (std::make_pair (name, net));
467
452
}
468
453
469
- uint32_t buildTopLevelCellDeclaration () {
470
-
454
+ uint32_t buildTopLevelCellDeclaration () {
471
455
CellDeclaration decl;
472
456
473
457
// Collect top-level ports
@@ -486,12 +470,10 @@ class NetlistBuilder {
486
470
if (!strcmp (model->name , MODEL_INPUT)) {
487
471
VTR_ASSERT (netlist_.block_output_pins (blk_id).size () == 1 );
488
472
port.dir = Direction::INPUT;
489
- }
490
- else if (!strcmp (model->name , MODEL_OUTPUT)) {
473
+ } else if (!strcmp (model->name , MODEL_OUTPUT)) {
491
474
VTR_ASSERT (netlist_.block_input_pins (blk_id).size () == 1 );
492
475
port.dir = Direction::OUTPUT;
493
- }
494
- else {
476
+ } else {
495
477
VTR_ASSERT (false );
496
478
}
497
479
@@ -524,16 +506,13 @@ class NetlistBuilder {
524
506
525
507
// ============================================================================
526
508
527
-
528
- void write_interchange_netlist (
509
+ void write_interchange_netlist (
529
510
const std::string& ic_netlist_file,
530
511
const AtomNetlist& netlist,
531
- const t_arch& arch)
532
- {
512
+ const t_arch& arch) {
533
513
// Initialize the builder
534
514
::capnp::MallocMessageBuilder message;
535
- LogicalNetlist::Netlist::Builder logical_netlist =
536
- message.initRoot <LogicalNetlist::Netlist>();
515
+ LogicalNetlist::Netlist::Builder logical_netlist = message.initRoot <LogicalNetlist::Netlist>();
537
516
538
517
// Build the netlist
539
518
auto builder = NetlistBuilder (netlist, arch);
0 commit comments