-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXSynthParser.cpp
More file actions
761 lines (639 loc) · 22.3 KB
/
XSynthParser.cpp
File metadata and controls
761 lines (639 loc) · 22.3 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/*************************************************************************/
/*
* Parser for Xilinx post-synthesis netlist
* by Gabriel Luca Nazar <glnazar@inf.ufrgs.br>
*
*/
/*************************************************************************/
#include <boost/foreach.hpp>
//using namespace boost;
//#define foreach BOOST_FOREACH
#include "XSynthParser.h"
using namespace std;
Circuit* circg;
void XSynthParser::parse(char *filename, Circuit &circ)
{
ifstream inFile;
char buf[BUF_SIZE], name[BUF_SIZE], bitName[BUF_SIZE], direction[4], type[128], to_downto[32], lutInit[18];
Net* newNet;
Lut* newLut;
Short* newShort;
Mux* newMux;
Buf* newBuf;
Xor* newXor;
FlipFlop* newFF;
unsigned int upper, lower, locX, locY;
int i, j;
bool end=false;
Net *netTarg, *netSrc;
inFile.open(filename);
circ.allIn.clear();
circ.components.clear();
circ.nets.clear();
circ.luts.clear();
circ.PIs.clear();
circ.POs.clear();
circ.clocks.clear();
circ.resets.clear();
circ.sets.clear();
circ.ffs.clear();
circ.vccNet = NULL;
circ.gndNet = NULL;
//skips initial comments until the entity declaration is found
inFile.getline(buf, BUF_SIZE);
while(buf[0] != 'e')
inFile.getline(buf, BUF_SIZE);
//gets top entity name
sscanf(buf, "entity %s is\n", name);
circ.name.assign(name);
cout << circ.name << endl;
nextNet = 0; //Next net
nextComp = 0; //Next component
nextLut = 0;
//gets PIs and POs from entity description
inFile.getline(buf, BUF_SIZE); //"port (" line
inFile.getline(buf, BUF_SIZE); //first port
while(buf[2] != ')'){
if(strstr(buf, " STD_LOGIC_VECTOR ")){
sscanf(buf, " %s : %s %s ( %d %s %d )", name, direction, type, &upper, to_downto, &lower);
//dealing with a vector port
if(upper < lower){ //checks if "upper" and "lower" limits are not switched
//"to" declaration (not "downto")
int aux = upper;
upper = lower;
lower = aux;
}
for(i=lower; i<=upper; i++){
if(options[OPT_NOVEC])
snprintf(bitName, BUF_SIZE, "%s_%d_nv", name, i); //generates this bit's name
else
snprintf(bitName, BUF_SIZE, "%s(%d)", name, i); //generates this bit's name
newNet = new Net(bitName, nextNet++);
if(direction[0] == 'i'){
newNet->isPI = true;
circ.PIs.push_back(newNet);
circ.allIn.push_back(newNet);
} else {
newNet->isPO = true;
circ.POs.push_back(newNet);
circ.allIn.push_back(newNet);
}
circ.nets.push_back(newNet);
//the symbolTable must maintain the original name, i.e., as if using STD_LOGIC_VECTOR
if(options[OPT_NOVEC]){
snprintf(bitName, BUF_SIZE, "%s(%d)", name, i); //generates this bit's name
symbolTable[string(bitName)] = newNet;
} else
symbolTable[newNet->name] = newNet;
}
} else {
sscanf(buf, " %s : %s %s", name, direction, type);
//std_logic port
newNet = new Net(name, nextNet++);
if(direction[0] == 'i') {
newNet->isPI = true;
circ.PIs.push_back(newNet);
circ.allIn.push_back(newNet);
} else {
newNet->isPO = true;
circ.POs.push_back(newNet);
circ.allIn.push_back(newNet);
}
circ.nets.push_back(newNet);
symbolTable[newNet->name] = newNet;
}
inFile.getline(buf, BUF_SIZE); //next port
}
inFile.getline(buf, BUF_SIZE); //end entity line
while(buf[0] != 'a') //scans until "architecture" line is found
inFile.getline(buf, BUF_SIZE);
//reads all signal declarations
while(buf[2] != 's')
inFile.getline(buf, BUF_SIZE); //reads first signal
while(buf[0] != 'b'){ //scans until "begin" line is found
if(strstr(buf, " STD_LOGIC_VECTOR ")){
sscanf(buf, " signal %s : %s ( %d %s %d );", name, type, &upper, to_downto, &lower);
//dealing with a vector signal
if(upper < lower){ //checks if "upper" and "lower" limits are not switched
//"to" declaration (not "downto")
int aux = upper;
upper = lower;
lower = aux;
}
for(i=lower; i<=upper; i++){
if(options[OPT_NOVEC])
snprintf(bitName, BUF_SIZE, "%s_%d_nv", name, i); //generates this bit's name
else
snprintf(bitName, BUF_SIZE, "%s(%d)", name, i); //generates this bit's name
newNet = new Net(bitName, nextNet++);
circ.nets.push_back(newNet);
//the symbolTable must maintain the original name, i.e., as if using STD_LOGIC_VECTOR
if(options[OPT_NOVEC]){
snprintf(bitName, BUF_SIZE, "%s(%d)", name, i); //generates this bit's name
symbolTable[string(bitName)] = newNet;
} else
symbolTable[newNet->name] = newNet;
}
} else {
sscanf(buf, " signal %s : %s;", name, type);
//std_logic signal
newNet = new Net(name, nextNet++);
circ.nets.push_back(newNet);
symbolTable[newNet->name] = newNet;
}
inFile.getline(buf, BUF_SIZE);
}
//parses all components
inFile.getline(buf, BUF_SIZE); //gets the first component line
while(1){
if(strchr(buf, ':')){
//component instance
compType ctype;
sscanf(buf, " %s : %s\n", name, type);
ctype = string2type(type);
if(ctype == UNKNOWN)
cout << "unknown type found: " << type << endl;
switch(ctype){
case LUT:
newLut = new Lut(name, nextLut++);
inFile.getline(buf, BUF_SIZE); //skips "generic map("
inFile.getline(buf, BUF_SIZE); //"INIT" line
sscanf(buf, " INIT => X\"%s\"", lutInit);
parseTable(lutInit, newLut->tableO6);
inFile.getline(buf, BUF_SIZE); //skips ")"
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //reads first input
while(buf[6] == 'I') { //reads all inputs
getNetName(buf + 12, name);
netSrc = symbolTable[name];
//if(netSrc->id == 17)
// cout << "name: " << newLut->name << endl;
newLut->inputs.push_back(netSrc);
netSrc->outputs.push_back(newLut);
inFile.getline(buf, BUF_SIZE); //reads next input
}
//parses output
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newLut->outputs.push_back(netTarg);
netTarg->setInput(newLut);
circ.luts.push_back(newLut);
circ.allIn.push_back(newLut);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case BUF:
newBuf = new Buf(name, nextComp);
inFile.getline(buf, BUF_SIZE); //skips "generic map"
while(buf[4] != 'p')
inFile.getline(buf, BUF_SIZE); //skips everything until the port map
inFile.getline(buf, BUF_SIZE); //input line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newBuf->inputs.push_back(netSrc);
netSrc->outputs.push_back(newBuf);
inFile.getline(buf, BUF_SIZE); //output line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newBuf->outputs.push_back(netTarg);
netTarg->setInput(newBuf);
if(netTarg->isPO){
circ.components.push_back(newBuf);
nextComp++;
}
circ.allIn.push_back(newBuf);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case MUXF7:
case MUXF8:
case MUXCY:
newMux = new Mux(name, nextComp++);
newMux->type = ctype;
if(ctype == MUXF8)
cout << "WARNING!! MUXF8 found!\n\n\n" << endl;
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //I0 (CI) line
getNetName(buf + 12, name);
netSrc = symbolTable[name];
newMux->inputs.push_back(netSrc);
netSrc->outputs.push_back(newMux);
inFile.getline(buf, BUF_SIZE); //I1 (DI) line
getNetName(buf + 12, name);
netSrc = symbolTable[name];
newMux->inputs.push_back(netSrc);
netSrc->outputs.push_back(newMux);
inFile.getline(buf, BUF_SIZE); //S line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newMux->inputs.push_back(netSrc);
netSrc->outputs.push_back(newMux);
inFile.getline(buf, BUF_SIZE); //O line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newMux->outputs.push_back(netTarg);
netTarg->setInput(newMux);
circ.components.push_back(newMux);
circ.allIn.push_back(newMux);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case INV: //an inverter will be mapped into a LUT by ISE, so I might do it right now
newLut = new Lut(name, nextLut++);
inFile.getline(buf, BUF_SIZE); //skips "generic map"
while(buf[4] != 'p')
inFile.getline(buf, BUF_SIZE); //skips everything until the port map
//inverter truth table
newLut->tableO6.resize(2);
newLut->tableO6[0] = true;
newLut->tableO6[1] = false;
inFile.getline(buf, BUF_SIZE); //input line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newLut->inputs.push_back(netSrc);
netSrc->outputs.push_back(newLut);
inFile.getline(buf, BUF_SIZE); //output line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newLut->outputs.push_back(netTarg);
netTarg->setInput(newLut);
circ.luts.push_back(newLut);
circ.allIn.push_back(newLut);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case XORCY:
newXor = new Xor(name, nextComp++);
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //CI line
getNetName(buf + 12, name);
netSrc = symbolTable[name];
newXor->inputs.push_back(netSrc);
netSrc->outputs.push_back(newXor);
inFile.getline(buf, BUF_SIZE); //LI line
getNetName(buf + 12, name);
netSrc = symbolTable[name];
newXor->inputs.push_back(netSrc);
netSrc->outputs.push_back(newXor);
inFile.getline(buf, BUF_SIZE); //O line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newXor->outputs.push_back(netTarg);
netTarg->setInput(newXor);
circ.components.push_back(newXor);
circ.allIn.push_back(newXor);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case DSP48E:
while(buf[5] != ';')
inFile.getline(buf, BUF_SIZE);
break;
case FDR:
newFF = new FlipFlop(name, nextComp++, FDR);
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //(C) clock line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.clocks.insert(netSrc); //This net is a clock, it may need special treatment
inFile.getline(buf, BUF_SIZE); //D line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //R line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.resets.insert(netSrc); //This net is a reset, it may need special treatment
if(!(strstr(name, "GLNRST") && strlen(name) == 6)){
fprintf(stderr, "Rst named: %s\n", name);
exit(0);
}
inFile.getline(buf, BUF_SIZE); //Q line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newFF->outputs.push_back(netTarg);
netTarg->setInput(newFF);
circ.ffs.push_back(newFF);
circ.allIn.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case FDRS:
newFF = new FlipFlop(name, nextComp++, FDRS);
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //(C) clock line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.clocks.insert(netSrc); //This net is a clock, it may need special treatment
inFile.getline(buf, BUF_SIZE); //D line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //R line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.resets.insert(netSrc); //This net is a reset, it may need special treatment
if(!(strstr(name, "GLNRST") && strlen(name) == 6)){
fprintf(stderr, "Rst named: %s\n", name);
exit(0);
}
inFile.getline(buf, BUF_SIZE); //S line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.sets.insert(netSrc); //This net is a set, it may need special treatment
if(strstr(name, "GLNRST")){
fprintf(stderr, "Set named: %s\n", name);
exit(0);
}
inFile.getline(buf, BUF_SIZE); //Q line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newFF->outputs.push_back(netTarg);
netTarg->setInput(newFF);
circ.ffs.push_back(newFF);
circ.allIn.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case FDRSE:
newFF = new FlipFlop(name, nextComp++, FDRSE);
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //(C) clock line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.clocks.insert(netSrc); //This net is a clock, it may need special treatment
inFile.getline(buf, BUF_SIZE); //CE line
getNetName(buf + 12, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //D line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //R line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.resets.insert(netSrc); //This net is a reset, it may need special treatment
if(!(strstr(name, "GLNRST") && strlen(name) == 6)){
fprintf(stderr, "Rst named: %s\n", name);
exit(0);
}
inFile.getline(buf, BUF_SIZE); //S line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.sets.insert(netSrc); //This net is a set, it may need special treatment
if(strstr(name, "GLNRST")){
fprintf(stderr, "Set named: %s\n", name);
exit(0);
}
inFile.getline(buf, BUF_SIZE); //Q line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newFF->outputs.push_back(netTarg);
netTarg->setInput(newFF);
circ.ffs.push_back(newFF);
circ.allIn.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case FDRE:
newFF = new FlipFlop(name, nextComp++, FDRE);
inFile.getline(buf, BUF_SIZE); //skips "port map("
inFile.getline(buf, BUF_SIZE); //(C) clock line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.clocks.insert(netSrc); //This net is a clock, it may need special treatment
inFile.getline(buf, BUF_SIZE); //CE line
getNetName(buf + 12, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //D line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //R line
getNetName(buf + 11, name);
netSrc = symbolTable[name];
newFF->inputs.push_back(netSrc);
netSrc->outputs.push_back(newFF);
circ.resets.insert(netSrc); //This net is a reset, it may need special treatment
if(!(strstr(name, "GLNRST") && strlen(name) == 6)){
fprintf(stderr, "Rst named: %s\n", name);
exit(0);
}
inFile.getline(buf, BUF_SIZE); //Q line
getNetName(buf + 11, name);
netTarg = symbolTable[name];
newFF->outputs.push_back(netTarg);
netTarg->setInput(newFF);
circ.ffs.push_back(newFF);
circ.allIn.push_back(newFF);
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case ZERO:
inFile.getline(buf, BUF_SIZE); //skips "generic map"
while(buf[4] != 'p') //skips everything until the port map
inFile.getline(buf, BUF_SIZE); //some X_ZEROs have generic map..
inFile.getline(buf, BUF_SIZE); //reads output
getNetName(buf + 11, name);
netTarg = symbolTable[name];
netTarg->setInput(NULL, GND);
circ.gndNet = netTarg;
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
case ONE:
inFile.getline(buf, BUF_SIZE); //skips "generic map"
while(buf[4] != 'p') //skips everything until the port map
inFile.getline(buf, BUF_SIZE);
inFile.getline(buf, BUF_SIZE); //reads output
getNetName(buf + 11, name);
netTarg = symbolTable[name];
netTarg->setInput(NULL, VCC);
circ.vccNet = netTarg;
inFile.getline(buf, BUF_SIZE); //skips ");"
break;
default:
end = true;
break;
}
if(end) //if an unknown component was found, then it's the end (usually an X_)
break;
} else {
if(!strstr(buf, "=")){
cout << "Parsing error at line: " << buf << endl;
exit(0);
}
//short circuit
newShort = new Short(nextComp++);
getNetName(buf+2, name);
netTarg = symbolTable[name];
newShort->outputs.push_back(netTarg);
getNetName(strchr(buf, '=')+2, name);
netSrc = symbolTable[name];
newShort->inputs.push_back(netSrc);
netTarg->setInput(newShort);
netSrc->outputs.push_back(newShort);
//if(netTarg->isPO){
circ.components.push_back(newShort);
circ.allIn.push_back(newShort);
// nextComp++;
//}
}
inFile.getline(buf, BUF_SIZE); //gets next line
while(buf[0] == 0) //skips empty lines
inFile.getline(buf, BUF_SIZE);
if(buf[0] == 'e') //end reached
break;
}
#if 0
circg = ˆ
//buffer and short circuit clean-up phase
for(i=circ.nets.size()-1; i>=0; i--){
Net *n;
n = circ.nets[i];
cout << "net " << i << " = "<< n->getName() << endl;
if(!n->isPO) {
if(!n->isPI && n->input == NULL && n->value == VARSIG){
cout << n->getName() << " not PI with NULL input! name: \"" << n->name << "\"" << "i = " << i << endl;
exit(0);
}
if((n->isPI || n->value != VARSIG) || (n->input->type != SHORT && n->input->type != BUF))
bufCleanup(n, n);
else
circ.nets.erase(circ.nets.begin() + i);
}
}
#endif
//counts flip-flops with constant input
circ.constInputFFs=0;
for(i=0; i<circ.ffs.size(); i++) {
if(circ.ffs[i]->type == FDR || circ.ffs[i]->type == FDRS){
if(circ.ffs[i]->inputs[1]->value != VARSIG)
circ.constInputFFs++;
} else if(circ.ffs[i]->type == FDRE || circ.ffs[i]->type == FDRSE) {
if(circ.ffs[i]->inputs[2]->value != VARSIG)
circ.constInputFFs++;
} else {
cout << "Unknown FF type " << circ.ffs[i]->type << " at parser" << endl;
}
}
for(i=0; i<circ.luts.size(); i++)
if(i != circ.luts[i]->id)
cout << circ.luts[i]->name << " i = " << i << "; id = " << circ.luts[i]->id << endl;
for(i=0; i<circ.nets.size(); i++)
circ.nets[i]->id = i;
for(i=0; i<circ.components.size(); i++)
circ.components[i]->id = i;
for(i=0; i<circ.allIn.size(); i++) {
circ.allIn[i]->key = i;
cout << circ.allIn[i]->name << ".key = " << circ.allIn[i]->key << endl;
}
cout << endl << endl;
}
/*************************************************************************/
void XSynthParser::getNetName(char *src, char *dst){
int i;
for(i=0; src[i] != ' ' && src[i] != 0 && src[i] != ',' && src[i] != ';'; i++)
dst[i] = src[i];
dst[i] = 0;
}
/*************************************************************************/
compType XSynthParser::string2type(char *src){
if(strstr(src, "LUT"))
return LUT;
/*if(strstr(src, "BUFG"))
return BUF;*/
if(strstr(src, "IBUF"))
return BUF;
if(strstr(src, "OBUF"))
return BUF;
if(strstr(src, "MUXF7"))
return MUXF7;
if(strstr(src, "MUXF8"))
return MUXF8;
if(strstr(src, "MUXCY"))
return MUXCY;
if(strstr(src, "XORCY"))
return XORCY;
if(strstr(src, "INV"))
return INV;
if(strstr(src, "FDR") && strlen(src) == 3)
return FDR;
if(strstr(src, "FDRS") && strlen(src) == 4)
return FDRS;
if(strstr(src, "FDRSE") && strlen(src) == 5)
return FDRSE;
if(strstr(src, "FDRE") && strlen(src) == 4)
return FDRE;
//if(strstr(src, "DSP48E"))
// return DSP48E;
if(strstr(src, "GND"))
return ZERO;
if(strstr(src, "VCC"))
return ONE;
return UNKNOWN;
}
/*************************************************************************/
void XSynthParser::parseTable(char *src, vector<bool> &table){
int i, j;
char aux[2];
int val;
bool swapvar;
aux[1] = 0;
for(i=0; src[i] != 0 && src[i] != '"'; i++){
aux[0] = src[i];
sscanf(aux, "%X", &val);
for(j=0; j<4; j++)
table.push_back((val & (8 >> j)) != 0);
}
//mirrored table
for(i=0; i < table.size()/2; i++){
swapvar = table[i];
table[i] = table[table.size() - (i+1)];
table[table.size() - (i+1)] = swapvar;
}
}
/*************************************************************************/
void XSynthParser::bufCleanup(Net* driver, Net* load){
int i, j, k;
if(!load->isPO){
BOOST_FOREACH(Component* comp2, load->outputs)
if(comp2->type == BUF || comp2->type == SHORT)
bufCleanup(driver, comp2->outputs[0]);
for(i=0; i<load->outputs.size(); i++){
Component* comp = load->outputs[i];
if((comp->type == BUF || comp->type == SHORT) && !comp->outputs[0]->isPO){
for(j=0; j<comp->outputs[0]->outputs.size(); j++) //components driven by the buffer output
for(k=0; k<comp->outputs[0]->outputs[j]->inputs.size(); k++) //inputs of those components
if(comp->outputs[0]->outputs[j]->inputs[k] == comp->outputs[0]){
comp->outputs[0]->outputs[j]->inputs[k] = driver;
driver->outputs.push_back(comp->outputs[0]->outputs[j]);
}
cout << "removed buffer! out = " << comp->outputs[0]->name << endl;
circg->components.erase(circg->components.begin()+comp->id);
for(j=comp->id; j<circg->components.size(); j++)
circg->components[j]->id = j;
delete comp->outputs[0];
delete comp;
load->outputs.erase(load->outputs.begin()+i);
i--;
}
}
}
}