-
Notifications
You must be signed in to change notification settings - Fork 7
/
file_analyzer.cpp
executable file
·2761 lines (2437 loc) · 87.9 KB
/
file_analyzer.cpp
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* This is written by Zhiyang Ong to parse a STIL file into a FLAT tabular
* test pattern format that contains input test patterns for execution on
* automatic test equipment
*
* Function to parse files for static analysis, and generation of output
* file containing the test patterns for the automatic test equipment
*
* IMPORTANT ASSUMPTIONS:
* #Assume that the signals rise/fall at the rising edge of the selected clock
* #Assume that the patterns for the clocks masterClk and scanClk are
* insignificant
* This is because the first waveform block can be processed before the
* pattern for its clock can be defined. Thus, the clock can simply be defined
* only by its waveform properties.
* That is, define patterns for signals that are not associated as clocks
* #It is acceptable to have signal vectors, or input patterns to each signal,
* that are different in length.
* This is because they vary in input frequency, and the signal inputs differ
* in length.
*/
// Import Header files from the C++ STL and the directory
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <cstring>
#include <iomanip>
#include <climits>
#include <ctype.h>
#include "file_analyzer.h"
#include "ViolatedAssertion.h"
#include "ViolatedPostcondition.h"
#include "ViolatedPrecondition.h"
#include "signalZ.h"
using namespace std;
// =======================================================================
// Declaration of constants...
// Maximum number of characters per line in the input text file
//const int MAX_NUM_OF_CHAR_PER_LINE=1000;
// Common search keywords
const string file_analyzer::INVALID = string("INVALID");
const string file_analyzer::ALLPINS = string("allPins");
const string file_analyzer::BASEWFT = string("baseWFT");
const string file_analyzer::MACRODEFS = string("Macrodefs");
const string file_analyzer::MACRO = string("Macro");
const string file_analyzer::PATTERN = string("Pattern");
const string file_analyzer::PERIOD = string("Period");
const string file_analyzer::PROCEDURE = string("Procedures");
const string file_analyzer::SCANLOAD = string("SCANLOAD");
const string file_analyzer::SCANUNLOAD = string("SCANUNLOAD");
const string file_analyzer::SCANPROC = string("scanProc");
const string file_analyzer::SCANIN = string("scanIn");
const string file_analyzer::SCANOUT = string("scanOut");
const string file_analyzer::SCANOUT1 = string("scanOut1");
const string file_analyzer::SCANOUT2 = string("scanOut2");
const string file_analyzer::SCANCLK = string("scanClk");
const string file_analyzer::SIGNALGROUPS = string("SignalGroups");
const string file_analyzer::SHIFT = string("Shift");
const string file_analyzer::TIMING = string("Timing");
const string file_analyzer::MASTERCLK = string("masterClk");
const string file_analyzer::WAVEFORMTABLE = string("WaveformTable");
const string file_analyzer::WAVEFORMS = string("Waveforms");
const string file_analyzer::V = string("V");
const string file_analyzer::W = string("W");
const string file_analyzer::C = string("C");
const string file_analyzer::P = string("P");
const string file_analyzer::HEADER = string("Header");
const string file_analyzer::PIPINS = string("piPins");
const string file_analyzer::POPINS = string("poPins");
const string file_analyzer::CLOCK = string("Clock");
const string file_analyzer::OPEN_BRACKET = string("{");
const string file_analyzer::CLOSE_BRACKET = string("}");
//const int INVALID_CHAR_INDEX = -9999999;
//static const string file_analyzer::UNIT_OF_TIME = "ns";
const string file_analyzer::UNIT_OF_TIME = string("ns");
//static const int file_analyzer::MEASURE_OF_TIME = 5;
//const int file_analyzer::MEASURE_OF_TIME = 5;
/*
00798780.pdf - pg 64, symbol table
develop algor to seach for tokens within a field/BLOCK
skip token/block
determine number of I/O pins
for each input pin, place the input vector in some format
convert Ls and Hs to numbers... 1s and 0s
likewise for output pin
*/
// ==========================================================================
// Default constructor
file_analyzer::file_analyzer() {
in_file=INVALID;
out_file=INVALID;
period_t=INVALID_CHAR_INDEX;
}
// Standard constructor
file_analyzer::file_analyzer(string input_filename, string output_filename) {
in_file=input_filename;
out_file=output_filename;
/**
* Convert input filename to string in C so that the file I/O function
* in the C++ library can be utilised for opening the input file
*/
inputfile.open(in_file.c_str());
// Assertion to check if the input file exist
if(inputfile == NULL) {
cerr << "Input file, with the filename " << in_file
<< ", does not exist!" << endl;
throw ViolatedPrecondition("Invalid file name");
}
/**
* Convert output filename to string in C so that the file I/O function
* in the C++ library can be utilised for opening the output file
*/
outputfile.open(out_file.c_str());
// Assertion to check if the output file was opened properly
if(outputfile == NULL) {
cout << "Output file, with the filename " << out_file
<< ", does not exist!" << endl;
}
}
// =======================================================================
// Implement function definitions...
/**
* Function to parse the STIL file, abtract the test patterns from the
* signals filed, and parse them into the output file
* @param i_file is the input file in STIL format
* @param o_file is the output file containing the test patterns
*/
void file_analyzer::parse_input() {
// Parse the input file...
/**
* Array of characters to contain data obtained from the first
* n characters of each line
*/
char temp_buffer[MAX_NUM_OF_CHAR_PER_LINE];
// Store the currently processed token
char *cur_token;
/**
* C++ string representation of the search key to utilize functions from
* the C++ STL
*/
string key;
// Container for tokens in currently enumerated line of the input file
string cstr = "";
// While there are any more lines in the text file to be read
while(!inputfile.eof()) {
// Read the line's first 1000 characters
inputfile.getline(temp_buffer,MAX_NUM_OF_CHAR_PER_LINE);
// Convert the C string into a C++ string
cstr = temp_buffer;
// If this string is not empty
if(!cstr.empty()) {
// Set whitespace as teh delimiter for tokens
cur_token = strtok(temp_buffer, " ");
// Acquire the first token...
key = cur_token;
// Insert the token into a list of string tokens
list_tokens.push_back(key);
cur_token = strtok(NULL, " ");
while (cur_token != NULL) {
// Get the current token as an integer from the char array
// Move to the next available token
key = cur_token;
// Insert this token into a list of string tokens
list_tokens.push_back(key);
// Attempt to get the next string token
cur_token = strtok(NULL, " ");
/**
* Do NOT do any processing after this line since it can be null
*/
}
}
}
cout << "Size of list is:::" << list_tokens.size() << endl;
/*
cout<<"========================================================="<<endl;
str_l_p t_p=list_tokens.begin();
while(t_p != list_tokens.end()) {
cout<<"\t\t CURRENT TOKEN~~~"<<(*t_p)<<endl;
t_p++;
}
cout<<"========================================================="<<endl;
*/
/**
* cout << "Size of list is:::" << list_tokens.size() << endl;
* Used to verify that the reading of tokens from the input file, and the
* subsequent insertion of tokens into lists is correct
*
* Can also be verified with the following UNIX commands:
* more [name_of_input_file] | wc -w
*/
/**
* Print the header of the output file to indicate the day, month, date,
* and year in which the test patterns were created in the STIL file
*/
process_header();
// Acquire the signals of the circuit/system under test
process_sig_grps();
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"process pattern block"<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
/**
* Process the pattern block next, since this program is supposed to
* generate test patterns
*/
process_pattern_blk();
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"Dump the output to an output file..."<<endl;
dump_output();
// Close the input and output file streams...
close_io_streams();
}
/**
* Function to append a string to the output file
* @param current_ln is the current string to be appended as a line to
* the output file
* @return nothing
* O(1); COMPLETED
*/
void file_analyzer::print_output_ln(string current_ln) {
// Left align the data in the output file
outputfile.setf(ios::left);
outputfile << current_ln << endl;
}
/**
* Function to close the input and output filestreams
* O(1); COMPLETED
*/
void file_analyzer::close_io_streams() {
// Close the input filestream
inputfile.close();
// Close the output filestream
outputfile.close();
}
/**
* Function to search for the key within this given line
* @param search_key is the key to be searched for in this token
* @param cur_token is the token being searched
* @return true if search_key is found in cur_token
* else, return false
* O(1); COMPLETED
*/
bool file_analyzer::search_key_found(string search_key, string cur_token) {
if(cur_token.find(search_key) == string::npos) {
return false;
}else{
return true;
}
}
/**
* Function to place each token in the input file into a list of strings to
* facilitate manipulation/enumeration of the tokens
* @return a list of tokens, which are represented as strings
* O(n); COMPLETED
*/
str_l_p file_analyzer::find_token(string key) {
//cout << "\t\t KEY" << key << "!!!" << endl;
// Enumerate the list of tokens from the beginning
str_l_p p = list_tokens.begin();
// While the last token has not been processed...
while(p != list_tokens.end()) {
if((*p) == key) {
//cout << "\t\t search key IS FOUND" << (*p) << endl;
return p;
}
// Enumerate the next token...
p++;
//cout << "find" << (*p) << "$$$" << endl;
}
//cout << "\t\t Leave the field" << (*p) << endl;
return list_tokens.end();
}
/**
* Function to process the Pattern block
* @return nothing
*/
void file_analyzer::process_pattern_blk() {
cout<<">>>>>>>>>>>>>>>>>>>>>>void file_analyzer::process_pattern_blk()"<<endl;
/**
* Counter to indicate the number of tokens being processed
* Hence, they indicate the number of tokens that shall be skipped
* after a method/function call
* This avoids the need to keep track of the pointer location, upon the
* return of the method/function call
*/
int num_tkns=0;
// Search for the keyword "Pattern"...
str_l_p ptn = find_token(PATTERN);
cout<<"\t\tPATTERN\t\tFOUND\t\tPATTERN\t\tFOUND"<<endl;
// Assertion...
if(ptn == list_tokens.end()) {
cerr<<"Keyword "<<PATTERN<<" is not found!"<<endl;
throw ViolatedAssertion("Wrong keyword is used.");
}
// Pattern block has been located...
/*
Example of how to search for a string and access its neighbours
ptn++;
ptn++;
ptn++;
if(search_key_found((*ptn), MACRO)) {
cout << "find works" << endl;
}else{
cout << "fix the bug in find" << endl;
}
*/
/**
* Process this Pattern block...
* Search for its open bracket...
*/
while((*ptn) != OPEN_BRACKET) {
ptn++;
} // Open curly bracket is found...
/**
* Open bracket is not added to simplify the processing of the block
* Just check if the list of parentheses is empty, instead of its size (1)
* and its content (open curly bracket)
*/
cout << "!@#$%^&*()_+Str found is:::" << (*ptn) << endl;
/**
* While the next token isn't a close bracket that ends this block...
* Process the contents of the pattern block
* The second condition of having the pointer not assigned to the begining
* of the list of tokens is an important terminating condition for this
* iterative procedure, since it had been found to loop back to the initial
* token of the list
*/
while((ptn != list_tokens.end()) && (ptn != list_tokens.begin())) {
// while(ptn != list_tokens.end()) {
cout<<"My\tCurrent\tToken\tis=="<<(*ptn)<<"::::############"<<endl;
// If this token is a close bracket that closes this block...
if(search_key_found(CLOSE_BRACKET,(*ptn)) && (list_blocks.empty()) ) {
cout<<"CLOSE BRACKET#################################"<<endl;
cout << "Close Bracket Token is found===" << (*ptn) << endl;
cout<<"\t\tTOKEN\t\tFOUND\t\tTOKEN\t\tFOUND"<<endl;
// End of Pattern block...
break;
}else if((*ptn)==MACRO) {
cout<<"MACRO#################################"<<endl;
// Macro keyword is found... Process it
// Get the pointer to the name of the macro...
ptn++;
cout << "Macro Token is found===" << (*ptn)<<"><"<< endl;
str_list sl = delimit_string(*ptn);
cout << "Macro TokenIZED===" << sl.front()<<"><"<< endl;
// Process this macro definition
// ptn=process_macro_blk(sl.front());
process_macro_blk(sl.front());
cout<<"\t\tMACRO\t\tFOUND\t\tMACRO\t\tMACRO"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"--Macro has been processed --"<<endl;
cout<<"--Macro has been processed --"<<endl;
cout<<"--Macro has been processed --"<<endl;
cout<<"--Macro has been processed --"<<endl;
cout<<"--Macro has been processed --"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
// BEGIN DEBUG HERE
// Skip to the next valid token; skip 3 tokens
//break;
}else if(truncate_semicolon(*ptn)==SCANLOAD) {
cout<<"SCAN LOAD#################################"<<endl;
// RESUME DEBUGGING HERE... till the end of the function
// scanProc keyword is found... Process it
num_tkns=process_scanproc_blk(*ptn);
// num_tkns++;
// num_tkns++;
cout<<"NUm Tokens is:::"<<num_tkns<<endl;
cout<<"\t\tSCANLOAD\t\tFOUND\t\tSCANLOAD\t\tFOUND"<<endl;
cout<<"((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("<<endl;
//check_scan_block();
}else if(truncate_semicolon(*ptn)==SCANUNLOAD) {
cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
cout<<"SCAN UNLOAD#################################"<<endl;
// RESUME DEBUGGING HERE... till the end of the function
// scanProc keyword is found... Process it
num_tkns=process_scanproc_blk(*ptn);
num_tkns++;
num_tkns++;
cout<<"NUm Tokens is:::"<<num_tkns<<endl;
cout<<"\t\tSCANUNLOAD\t\tFOUND\t\tSCANUNLOAD\t\tFOUND"<<endl;
//check_scan_block();
}else if((*ptn)==V) {
cout<<"VVVVVVV#####################::::"<<(*ptn)<<"::::############"<<endl;
// V keyword is found... Process it
num_tkns=process_v_blk(ptn,V);
num_tkns=num_tkns*2;
num_tkns--;
num_tkns--;
//ptn--;
cout<<"\t\tVVV\t\tFOUND\t\tVVV\t\tFOUND"<<endl;
check_signal_condition();
check_signal_value();
}
// Skip the required number of tokens to process the next subpattern
while(num_tkns>0) {
num_tkns--;
cout<<"<<<\t<<<\t<<<\t<<< CURRENT TOKEN"<<(*ptn)<<"><"<<endl;
ptn++;
}
// If all the tokens have been processed...
if(ptn == list_tokens.end()) {
// Exit...
break;
}
cout<<"<<<\t<<<\t<<<\t<<< NEXT TOKEN"<<(*ptn)<<"><"<<endl;
// Else, process the next token...
ptn++;
} // Pattern block has been processed
cout << "-------->>>>PATTERN BLOCK HAS BEEN PROCESSED" << endl;
cout<<"<<<<<<<<<<<<<<<<<<<<<<void file_analyzer::process_pattern_blk()"<<endl;
}
/**
* Function to process the macro block
* Since a call to process the macro definition is made, I do not have to
* keep track of where did the macro definition end
* That is, I also do not need to keep track of how many tokens have been
* traversed in my macro definition
* Consequently, I do not need to return a pointer to the last traversed
* element
* @return nothing
*/
void file_analyzer::process_macro_blk(string macro_name) {
cout<<">>>>>>>>>void file_analyzer::process_macro_blk(string macro_name)"<<endl;
/**
* Counter to indicate the number of tokens being processed
* Hence, they indicate the number of tokens that shall be skipped
* after a method/function call
* This avoids the need to keep track of the pointer location, upon the
* return of the method/function call
*/
int num_tkns=0;
cout << "\t MARCRONAME" << macro_name <<"*************************"<< endl;
// Search for this macro definition
str_l_p m_p = find_token(macro_name);
// Assertion...
if(m_p == list_tokens.end()) {
cerr<<"Keyword "<<macro_name<<" is not found!"<<endl;
throw ViolatedAssertion("Wrong keyword is used.");
}
// Determine the initial number of parentheses encasing the blocks...
int num_brackets = list_blocks.size();
// Proceed to the first token after the open curly bracket
cout << "1TOKEN IS@@@" << (*m_p) << endl;
m_p++;
cout << "2TOKEN IS@@@" << (*m_p) << endl;
m_p++;
cout << "3TOKEN IS@@@" << (*m_p) << endl;
// Process this macro definition...
while(m_p != list_tokens.end()) {
// If this token is a close bracket that closes this block...
if(search_key_found(CLOSE_BRACKET,(*m_p)) && (list_blocks.size()==num_brackets) ) {
//if(search_key_found(CLOSE_BRACKET,(*m_p))) {
cout<<"END OF PATTERN BLOCK------>>>>>>>END OF PATTERN BLOCK"<<endl;
cout<<"<<<<<<<<<void file_analyzer::process_macro_blk(string macro_name)"<<endl;
// End of Pattern block...
return;
// }else if((*m_p)==W) {
}else if(search_key_found(W,(*m_p)) ) {
// THE SIGNAL W is found... Process it
m_p++;
// Get the name of the macro...
str_list sl = delimit_string(*m_p);
cout << "W !!TokenIZED===------>>>>>>------>>>>>>" << sl.front() << endl;
// Process this macro definition
num_tkns=process_waveform_blk(sl.front());
num_tkns=0;
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
// BEGIN DEBUG HERE
//==================================================================
//==================================================================
//==================================================================
// UNcomment this when the function process_v_blk has been defined
//break;
// }else if((*m_p)==V) {
// $DISPLAY Waveform properties...
check_waveform();
cout<<"************************COMPLETE waVeFrOm prOcEsSInG"<<endl;
}else if(search_key_found(V,(*m_p)) ) {
// scanProc keyword is found... Process it
cout<<"~~~~~~~~~~~~~~~~~~~~~~V block is found"<<endl;
num_tkns=process_v_blk(m_p,V);
// Number of tokens exceeded count by 1
cout << "V !!TokenIZED===------>>>>>>------>>>>>>" << endl;
check_signal_condition();
check_signal_value();
// }else if((*m_p)==C) {
}else if(search_key_found(C,(*m_p)) ) {
// V keyword is found... Process it
cout<<"~~~~~~~~~~~~~~~~~~~~~~C block is found"<<endl;
num_tkns=process_v_blk(m_p,C);
cout << "C !!TokenIZED===------>>>>>>------>>>>>>" << endl;
num_tkns--;
check_signal_condition();
check_signal_value();
}
// Handle the blocks here...
if(search_key_found(OPEN_BRACKET,(*m_p))) {
list_blocks.push_back(*m_p);
cout<<"~~~~~~~~~~~~~~~~~~~~~~OPEN bracket is found"<<endl;
}else if(search_key_found(CLOSE_BRACKET,(*m_p))) {
list_blocks.pop_back();
cout<<"~~~~~~~~~~~~~~~~~~~~~~CLOSE bracket is found"<<endl;
}
cout<<"\t\t\t\t\t Process next waveform tokeee"<<endl;
cout<<"THE NUMBER OF TOKENS that are skipped in this loop are<>"<<num_tkns<<"<>"<<endl;
// Skip the processed tokens... move to the next unprocessed token
while(num_tkns > 0) {
num_tkns--;
m_p++;
cout<<"SKIPPED TOKEN IS:::::::::::::::::::::::::::"<<(*m_p)<<"<>"<<endl;
}
// Else, process the next token...
m_p++;
if(search_key_found(PATTERN,(*m_p))) {
cout<<"END OF PATTERN BLOCK------>>>>>>>END OF PATTERN BLOCK"<<endl;
cout<<"<<<<<<<<<void file_analyzer::process_macro_blk(string macro_name)"<<endl;
// End of Pattern block...
return;
}
cout<<"\t\t\t\t\t Processed next "<<(*m_p)<<" waveform tokeee"<<endl;
cout<<"\t\t\t\t\t xxxxxxxxxxxxxxxxxxxxx\tNext Token\tDOnE"<<endl;
} // macro block has been processed
cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<process macro blk"<<endl;
string err_msg="Close bracket for macro definition CANNOT BE FOUND!!!";
// UNCOMMENT THIS AFTER THE METHOD DEFINTIONS FOR C AND V
// throw ViolatedAssertion(err_msg);
}
/**
* Function to delimit a string from non-alphanumeric characters
*
* When processing the structure for the waveforms, do not process the signal
* values... Only create its triggering and wave properties.
*
* @param delimit_str is the string to be delimited
* @return the delimited string
* O(n) computational time complexity; COMPLETED
*/
int file_analyzer::process_waveform_blk(string wave) {
cout<<">>>>>>>>>>>>int file_analyzer::process_waveform_blk(string wave)"<<endl;
/**
* Counter to indicate the number of tokens being processed by another
* method call
* Hence, they indicate the number of tokens that shall be skipped
* after a method/function call
* This avoids the need to keep track of the pointer location, upon the
* return of the method/function call
*/
int num_tokens_traversed=0;
// Number of tokens traverse by this function...
int num_tkns=0;
// Search for the pointer to the keyword
str_l_p w = find_token(wave);
// Assertion...
if(w == list_tokens.end()) {
cerr<<"Keyword "<<wave<<" is not found!"<<endl;
throw ViolatedAssertion("Wrong keyword is used.");
}
// Determine the initial number of parentheses encasing the blocks...
int num_brackets = list_blocks.size();
// Proceed to the first token after the open curly bracket
cout << "1TOKEN" << (*w) << endl;
w++;
num_tkns++;
cout << "2TOKEN" << (*w) << endl;
w++;
num_tkns++;
cout << "3TOKEN" << (*w) << endl;
// Process this macro definition...
while(w != list_tokens.end()) {
// If this token is a close bracket that closes this block...
if(search_key_found(CLOSE_BRACKET,(*w)) && (list_blocks.size()==num_brackets) ) {
cout<<"<<<<<<<<<<<<int file_analyzer::process_waveform_blk(string wave)"<<endl;
// End of Pattern block...
return num_tkns;
}else if(search_key_found(CLOSE_BRACKET,(*w))) {
cout<<"Reached definition of next set of waveform properties"<<endl;
cout<<"<<<<<<<<<<<<int file_analyzer::process_waveform_blk(string wave)"<<endl;
// End of Pattern block...
return num_tkns;
// }else if((*w)==PERIOD) {
}else if(search_key_found(PERIOD,(*w)) ) {
// The period of the waveform is found... Process it
w++;
num_tkns++;
// Get the value of the period...
str_list sl = delimit_string(*w);
string cycle_time = sl.front();
cycle_time=chop_ns(cycle_time);
cout << "Cycle time is&&&" << cycle_time << endl;
// Assign the period of the waveform...
period_t = atoi(cycle_time.c_str());
update_sig_period(period_t);
cout << "\t\t\tNEW Cycle time is&&&" << period_t << endl;
// Skip 2 tokens to deal with signal values
w++;
num_tkns++;
cout << "single&&incre" << (*w) << endl;
w++;
num_tkns++;
cout << "double&&incre" << (*w) << endl;
//cout << "\t\t\t Uh Oh!!!"<<endl;
// Completed...
// }else if((*w)==PIPINS) {
}else if(search_key_found(PIPINS,(*w)) ) {
// PIPINS keyword is found... Process it
cout<<"\t\t\tProcess INPUT signal waveform properties"<<endl;
num_tokens_traversed=process_pipins(w);
num_tokens_traversed++;
cout<<"\t\t\tProcessED INput signal waveform properties"<<endl;
//break;
// }else if((*w)==POPINS) {
}else if(search_key_found(POPINS,(*w)) ) {
// POPINS keyword is found... Process it
cout<<"\t\t\tProcess output signal waveform properties"<<endl;
num_tokens_traversed=process_popins(w);
num_tokens_traversed++;
cout<<"\t\t\t!!!Processed output signal waveform properties"<<endl;
// process_v_blk();
//break;
// }else if((*w)==MASTERCLK) {
}else if(search_key_found(MASTERCLK,(*w)) ) {
// MASTERCLK keyword is found... Process it
// process_v_blk();
cout<<"\t\t\t\t\t Get dEtAIls of tHE mAsTEr cLoCK"<<endl;
num_tokens_traversed=process_clk(w,MASTERCLK);
num_tokens_traversed++;
num_tokens_traversed++;
num_tokens_traversed++;
cout<<"\t\t\t\t\t mAsTEr cLoCK hAs BeEN pRoCeSSeD"<<endl;
//break;
// }else if((*w)==SCANCLK) {
}else if(search_key_found(SCANCLK,(*w)) ) {
// SCANCLK keyword is found... Process it
// process_v_blk();
cout<<"\t\t\t\t\t Get dEtAIls of tHE SCAN cLoCK"<<endl;
num_tokens_traversed=process_clk(w,SCANCLK);
cout<<"\t\t\t\t\t SCAN cLoCK hAs BeEN pRoCeSSeD"<<endl;
//break;
num_tokens_traversed++;
num_tokens_traversed++;
num_tokens_traversed++;
}
if(search_key_found(OPEN_BRACKET,(*w))) {
list_blocks.push_back(*w);
}else if(search_key_found(CLOSE_BRACKET,(*w))) {
list_blocks.pop_back();
}
// Skip all tokens that have already been processed
while(num_tokens_traversed>0) {
num_tokens_traversed--;
w++;
num_tkns++;
cout<<"Token skipped:"<< (*w) <<"><=="<<endl;
}
// w++;
// Else, process the next token...
cout<<"\t\t\t\tyet to crash dump"<<endl;
w++;
num_tkns++;
cout<<"Tokie WWWis:"<<(*w)<<endl;
cout<<"\t\t\t\t crash dump???"<<endl;
} // macro block has been processed
cout<<"ENDmacroBlK"<<endl;
string err_str;
err_str="Macro definition is not properly defined: missing close brackets";
throw ViolatedAssertion(err_str);
}
/**
* Function to delimit a string from non-alphanumeric characters
* @param delimit_str is the string to be delimited
* @return the delimited string as a list of string tokens
* O(n); COMPLETED
*/
str_list file_analyzer::delimit_string(string delimit_str) {
cout<<">>>>>>>>>>>>>>>str_list file_analyzer::delimit_string(string delimit_str)"<<endl;
// Storage of delimited strings containing values to be processed
str_list list_str;
// Temporary string to process current token...
string temp;
// Pointer to initial character of current string
int initial_char=0;
/**
* Flag to indicate that a string commencing with a non-alphanumeric
* character can process its first substring/token with only alphanumeric
* characters
*/
bool initial_invalid_token=false;
// Flag indicating if subsequent valid tokens can be processed
bool process_tokens = false;
// Indicator of whether matching apostrophes are found
int num_apostrophes=0;
// For each character in the string...
for (int i=0; i < delimit_str.size(); i++) {
// Are there any alphanumeric characters?
if (!isalnum(delimit_str[i])) {
// This current character is not alphanumeric
// If this substring only contains alphanumeric characters...
if((initial_char != INVALID_CHAR_INDEX) && (i>0) ) {
// Obtain current substring...
temp = delimit_str.substr(initial_char,(i-initial_char));
// Reassign the initial string for the next string token later...
initial_char = INVALID_CHAR_INDEX;
// Process substrings containing only alphanumeric characters?
if(initial_invalid_token) {
process_tokens=true;
}
/**
* Has the substring containing only non-alphanumeric characters
* that commence the string been processed?
*/
if((!isalnum(delimit_str[0])) && (list_str.empty())
&& (!initial_invalid_token)) {
// No...
initial_invalid_token=true;
}
// Is this a valid alphanumeric token to be added to the set?
if(process_tokens || (isalnum(delimit_str[0]))) {
// Yes. Add this string to the list of string tokens
list_str.push_back(temp);
}
}
}else{
// Else, this is an alphanumeric character
/**
* Is this part of a substring that only contains alphanumeric
* characters?
*/
if(initial_char==INVALID_CHAR_INDEX) {
/**
* No.
* Reassign initial character for next substring that only
* contains alphanumeric characters...
*/
initial_char=i;
}
}
// Delete apostrophes from the string...
if(delimit_str[i] == '\'') {
num_apostrophes++;
delimit_str.erase(i,1);
i--;
}
}
// Process substrings that have an alphanumeric last character...
// Obtain current substring
if(isalnum(delimit_str[(delimit_str.size()-1)])
&& (initial_char != INVALID_CHAR_INDEX)) {
temp = delimit_str.substr(initial_char,(delimit_str.size()-initial_char));
// Add this string to the list of string tokens
list_str.push_back(temp);
}
// Do the apostrophes match?
if((num_apostrophes%2) != 0) {
throw ViolatedAssertion("Matching apostrophes NOT found!!!");
}
cout<<"<<<<<<<<<<<<<<<str_list file_analyzer::delimit_string(string delimit_str)"<<endl;
// Return the list of delimited tokens...
return list_str;
}
/**
* Function to convert the signal value that's "duration" long (in time units)
* @param duration is the length in time that this phase of the signal last
* @param logic_value is the boolean logic value that a signal should take
* @return a string indicating a sequence of quantized values for this signal
* i.e., a signal of 30ns duration is broken up into a sequence of values in
* the defined quantized units of time... "MEASURE_OF_TIME" amount of time in
* UNIT_OF_TIME units of time
* O(n) computational time complexity; COMPLETED
*/
string file_analyzer::time_to_string(int duration, int logic_value) {
// Can the duration be represented as quantized units of time
if((duration%MEASURE_OF_TIME) != 0) {
string err="The duration cannot be measured in quantized units of time";
throw ViolatedPrecondition(err);
}
// String indicating the logic values of the signal for the duration
string signal_values="";
// Logic value during a selected 5ns interval
string logic_v=int_to_str(logic_value);
for(int i=0; i<duration; i=i+MEASURE_OF_TIME) {
//signal_values=signal_values+""+logic_value;
signal_values=signal_values.insert(signal_values.size(),logic_v);
}
return signal_values;
}
/**
* Function to convert an integer into a string
* @param num is an integer to be converted into a string
* @return a string representation of the integer
* O(n) computational time complexity; COMPLETED
*/
string file_analyzer::int_to_str(int num) {
// String representing this integer, num
string i_to_s = "";
// Remainder from the modulo of 10
int modulus;
// If this number is greater than the modulus 10
if(num>9) {
// Obtain the remainder...
modulus = num%10;
// Add its remainder as the most significant digit
i_to_s=i_to_s.insert(0,int_to_str(modulus));
// Get the next most significant digit
return i_to_s.insert(0,int_to_str(num/10));
}else{
// The remainder is equal to the number...
modulus = num;
// Insert the lowest order digits...
switch(modulus) {
case 0:
return i_to_s.insert(0,"0");
break;
case 1:
return i_to_s.insert(0,"1");
break;
case 2:
return i_to_s.insert(0,"2");
break;
case 3:
return i_to_s.insert(0,"3");
break;
case 4:
return i_to_s.insert(0,"4");
break;
case 5:
return i_to_s.insert(0,"5");
break;
case 6:
return i_to_s.insert(0,"6");
break;
case 7:
return i_to_s.insert(0,"7");
break;
case 8:
return i_to_s.insert(0,"8");
break;
case 9:
return i_to_s.insert(0,"9");