summaryrefslogtreecommitdiff
path: root/web/yacco2/o2linker/o2linker.cpp
blob: d1c689d8e45ab25db2a2b53439e1108a84c2baaf (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
/*89:*/
//line 40 "/usr/local/yacco2/o2linker/includes.w"

/*87:*/
//line 23 "/usr/local/yacco2/o2linker/includes.w"

#include "o2linker.h"

/*:87*/
//line 41 "/usr/local/yacco2/o2linker/includes.w"

/*20:*/
//line 125 "/usr/local/yacco2/o2linker/prog.w"

void load_linkkw_into_tbl(yacco2::CAbs_lr1_sym*Kw){
using namespace yacco2_stbl;
T_sym_tbl_report_card report_card;
KCHARP kwkey= Kw->id();
if(*kwkey=='#')++kwkey;
kw_in_stbl*kw= new kw_in_stbl(Kw);
add_sym_to_stbl(report_card,*kwkey,*kw,table_entry::defed,table_entry::keyword);
kw->stbl_idx(report_card.pos_);
}

void load_linkkws_into_tbl()
{
cout<<"Load linker's keywords "<<endl;
load_linkkw_into_tbl(new T_transitive);
load_linkkw_into_tbl(new T_grammar_name);
load_linkkw_into_tbl(new T_name_space);
load_linkkw_into_tbl(new T_thread_name);
load_linkkw_into_tbl(new T_fsm_comments);
load_linkkw_into_tbl(new T_monolithic);
load_linkkw_into_tbl(new T_file_name);
load_linkkw_into_tbl(new T_no_of_T);
load_linkkw_into_tbl(new T_list_of_native_first_set_terminals);
load_linkkw_into_tbl(new T_end_list_of_native_first_set_terminals);
load_linkkw_into_tbl(new T_list_of_transitive_threads);
load_linkkw_into_tbl(new T_end_list_of_transitive_threads);
load_linkkw_into_tbl(new T_list_of_used_threads);
load_linkkw_into_tbl(new T_end_list_of_used_threads);
load_linkkw_into_tbl(new T_T_alphabet);
load_linkkw_into_tbl(new T_end_T_alphabet);
load_linkkw_into_tbl(new T_file_of_T_alphabet);
load_linkkw_into_tbl(new T_emitfile);
load_linkkw_into_tbl(new T_preamble);
load_linkkw_into_tbl(new T_end_preamble);
}


/*:20*//*22:*/
//line 208 "/usr/local/yacco2/o2linker/prog.w"

bool sort_threads_criteria(const table_entry*P1,const table_entry*P2){
th_in_stbl*th_tbl1= (th_in_stbl*)P1->symbol_;
th_in_stbl*th_tbl2= (th_in_stbl*)P2->symbol_;
thread_attributes*p1= th_tbl1->thread_in_stbl();
thread_attributes*p2= th_tbl2->thread_in_stbl();
int len_a= p1->thread_name_->c_string()->size();
int len_b= p2->thread_name_->c_string()->size();
string ucase_a;
for(int x= 0;x<len_a;++x){
ucase_a+= toupper((*p1->thread_name_->c_string())[x]);
}
string ucase_b;
for(int x= 0;x<len_b;++x){
ucase_b+= toupper((*p2->thread_name_->c_string())[x]);
}
if(len_a<len_b){
for(int x= len_a+1;x<=len_b;++x)ucase_a+= ' ';
}else{
for(int x= len_b+1;x<=len_a;++x)ucase_b+= ' ';
}
int result;
if(p1->monolithic_=='n'){
if(p2->monolithic_=='n'){
result= strcmp(ucase_a.c_str(),ucase_b.c_str());
if(result<0)return true;
return false;
}
return true;
}
if(p2->monolithic_=='n'){
return false;
}

int len_fqna= p1->thread_name_->c_string()->size();
int len_fqnb= p2->thread_name_->c_string()->size();
string ucase_fqna;
for(int x= 0;x<len_fqna;++x){
ucase_fqna+= toupper((*p1->thread_name_->c_string())[x]);
}
string ucase_fqnb;
for(int x= 0;x<len_fqnb;++x){
ucase_fqnb+= toupper((*p2->thread_name_->c_string())[x]);
}
if(len_fqna<len_fqnb){
for(int x= len_fqna+1;x<=len_fqnb;++x)ucase_fqna+= ' ';
}else{
for(int x= len_fqnb+1;x<=len_fqna;++x)ucase_fqnb+= ' ';
}
result= strcmp(ucase_fqna.c_str(),ucase_fqnb.c_str());
if(result<0)return true;
return false;
}

/*:22*//*33:*/
//line 434 "/usr/local/yacco2/o2linker/prog.w"

void crt_fset_of_thread
(thread_attributes&Visited_th
,int Root_thread_id,thread_attributes&Root_thread){
if(Visit_graph[Visited_th.th_enum_]=='y')return;
Visit_graph[Visited_th.th_enum_]= 'y';
/*31:*/
//line 396 "/usr/local/yacco2/o2linker/prog.w"

std::vector<int> ::iterator fi= Visited_th.list_of_Ts_.begin();
std::vector<int> ::iterator fie= Visited_th.list_of_Ts_.end();
for(;fi!=fie;++fi){
int t_enum= *fi;
if(t_enum==LR1_ALL_SHIFT_OPERATOR){
/*29:*/
//line 332 "/usr/local/yacco2/o2linker/prog.w"

INT_SET_ITER_type t_listi= Root_thread.fs_.find(LR1_EOLR);
if(t_listi==Root_thread.fs_.end()){
Root_thread.fs_.insert(LR1_EOLR);
}

int no_of_T= T_DICTIONARY.size();
for(int x= 0;x<no_of_T;++x){
switch(x){
case LR1_QUESTIONABLE_SHIFT_OPERATOR:break;
case LR1_EOG:break;
case LR1_EOLR:continue;
case LR1_PARALLEL_OPERATOR:continue;
case LR1_REDUCE_OPERATOR:continue;
case LR1_INVISIBLE_SHIFT_OPERATOR:continue;
case LR1_ALL_SHIFT_OPERATOR:continue;
case LR1_FSET_TRANSIENCE_OPERATOR:continue;
default:break;
}
if(Visited_th.monolithic_=='n'){
INT_SET_type&th_list= T_THREAD_ID_LIST[x];
if(th_list.find(Visited_th.th_enum_)==th_list.end()){
th_list.insert(Visited_th.th_enum_);
}
if(th_list.find(Root_thread_id)==th_list.end()){
th_list.insert(Root_thread_id);
}
}
}

/*:29*/
//line 402 "/usr/local/yacco2/o2linker/prog.w"

}
/*30:*/
//line 369 "/usr/local/yacco2/o2linker/prog.w"

INT_SET_ITER_type t_listi= Root_thread.fs_.find(t_enum);
if(t_listi==Root_thread.fs_.end()){
Root_thread.fs_.insert(t_enum);
}
if(Visited_th.monolithic_=='n'){
INT_SET_type&th_list= T_THREAD_ID_LIST[t_enum];
if(th_list.find(Visited_th.th_enum_)==th_list.end()){
th_list.insert(Visited_th.th_enum_);
}
if(th_list.find(Root_thread_id)==th_list.end()){
th_list.insert(Root_thread_id);
}
}

/*:30*/
//line 404 "/usr/local/yacco2/o2linker/prog.w"

}

/*:31*/
//line 440 "/usr/local/yacco2/o2linker/prog.w"

/*32:*/
//line 409 "/usr/local/yacco2/o2linker/prog.w"

std::vector<thread_attributes*> ::iterator li= Visited_th.list_of_transitive_threads_.begin();
std::vector<thread_attributes*> ::iterator lie= Visited_th.list_of_transitive_threads_.end();
for(;li!=lie;++li){
thread_attributes*th_att= *li;
lrclog<<"------->process called thread's list thd: "
<<th_att->thread_name_->c_string()->c_str()
<<" for root thd id: "<<Root_thread_id
<<endl;
crt_fset_of_thread(*th_att,Root_thread_id,Root_thread);
}

/*:32*/
//line 441 "/usr/local/yacco2/o2linker/prog.w"

}

/*:33*//*38:*/
//line 503 "/usr/local/yacco2/o2linker/prog.w"

void walk_called_thread_list(std::vector<thread_attributes*> &Thd_list,AST*Mother_thd_t){
if(Thd_list.begin()==Thd_list.end())return;
std::vector<thread_attributes*> ::iterator li= Thd_list.begin();
std::vector<thread_attributes*> ::iterator lie= Thd_list.end();
for(;li!=lie;++li){
thread_attributes*th_att= *li;
if(Visit_graph[th_att->th_enum_]=='y')continue;
Visit_graph[th_att->th_enum_]= 'y';
AST*called_t= new AST(*th_att);
AST::add_child_at_end(*Mother_thd_t,*called_t);
walk_called_thread_list(th_att->list_of_transitive_threads_,called_t);
}
}

/*:38*//*39:*/
//line 519 "/usr/local/yacco2/o2linker/prog.w"

void crt_called_thread_graph(thread_attributes&Visited_th){
if(Visit_graph[Visited_th.th_enum_]=='y')return;
Visit_graph[Visited_th.th_enum_]= 'y';
AST*mother_thd_t= new AST(Visited_th);
Visited_th.called_thread_graph_= mother_thd_t;
walk_called_thread_list(Visited_th.list_of_transitive_threads_,mother_thd_t);
}
/*:39*//*40:*/
//line 528 "/usr/local/yacco2/o2linker/prog.w"

void gen_each_grammar_s_referenced_threads(){
std::vector<table_entry*> ::iterator thi= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator thie= GRAMMAR_DICTIONARY.end();
for(;thi!=thie;++thi){
th_in_stbl*th_tbl= (th_in_stbl*)(*thi)->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
/*35:*/
//line 454 "/usr/local/yacco2/o2linker/prog.w"

for(int vi= 0;vi<NO_OF_THREADS;++vi){
Visit_graph[vi]= 'n';
}

/*:35*/
//line 535 "/usr/local/yacco2/o2linker/prog.w"

crt_called_thread_graph(*th_att);
}
}
/*:40*//*52:*/
//line 773 "/usr/local/yacco2/o2linker/prog.w"

void emit_no_threads(ofstream&ofile){
ofile<<"// There are NO THREADS emitted"<<endl;
ofile<<"void* yacco2::THDS_STABLE__ = 0;"<<endl;
ofile<<"void* yacco2::T_ARRAY_HAVING_THD_IDS__ = 0;"<<endl;
}

/*:52*//*53:*/
//line 781 "/usr/local/yacco2/o2linker/prog.w"

void emit_cpp_preamble(ofstream&ofile,const char*OFile,const char*Preamble){
ofile<<"//"<<endl;
ofile<<"// File: "<<OFile<<endl;
ofile<<"// Generated by linker.exe"<<endl;
ofile<<"// Date and Time: "<<DATE_AND_TIME()<<endl;
ofile<<"//"<<endl;
ofile<<endl;
ofile<<"// Preamble code"<<endl;
ofile<<Preamble<<endl;
}

/*:53*//*54:*/
//line 799 "/usr/local/yacco2/o2linker/prog.w"

void emit_global_thread_include_files(ofstream&ofile){
ofile<<"// thread include and namespace"<<std::endl;
char a[SMALL_BUFFER_4K];
KCHARP thread_include_ns= "#include \"%s.h\"";

std::vector<table_entry*> ::iterator thi= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator thie= GRAMMAR_DICTIONARY.end();
for(;thi!=thie;++thi){
th_in_stbl*th_tbl= (th_in_stbl*)(*thi)->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
if(th_att->monolithic_=='y')break;
int x= sprintf
(a
,thread_include_ns
,th_att->grammar_file_name_->c_string()->c_str()
);
ofile.write(a,x);
ofile<<std::endl;
}
}

/*:54*//*55:*/
//line 822 "/usr/local/yacco2/o2linker/prog.w"

void emit_global_bit_maps(ofstream&ofile){
ofile<<"// BIT MAPS"<<std::endl;
ofile<<"#define TOTAL_NO_BIT_WORDS 2*1024*50"<<std::endl;
ofile<<"int yacco2::TOTAL_NO_BIT_WORDS__(TOTAL_NO_BIT_WORDS);"<<std::endl;
ofile<<"yacco2::ULINT  bit_maps[TOTAL_NO_BIT_WORDS];"<<std::endl;
ofile<<"void* yacco2::BIT_MAPS_FOR_SALE__ = (void*)&bit_maps;"<<std::endl;
ofile<<"int yacco2::BIT_MAP_IDX__(0);"<<std::endl;
}

/*:55*//*56:*/
//line 844 "/usr/local/yacco2/o2linker/prog.w"

void emit_global_thread_stable(ofstream&ofile){
ofile<<"// THREAD STABLE"<<std::endl;
char a[BIG_BUFFER_32K];
KCHARP thread_entry= "yacco2::Thread_entry I%s = {%s,%s,%i,%s::PROC_%s};";
string quoted_name;
/*57:*/
//line 855 "/usr/local/yacco2/o2linker/prog.w"

std::vector<table_entry*> ::iterator thi= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator thie= GRAMMAR_DICTIONARY.end();
for(;thi!=thie;++thi){
th_in_stbl*th_tbl= (th_in_stbl*)(*thi)->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
if(th_att->monolithic_=='y')break;
quoted_name.clear();
const char*th_name= th_att->thread_name_->c_string()->c_str();
quoted_name+= '"';
quoted_name+= th_name;
quoted_name+= '"';

int x= sprintf(a,thread_entry,th_name,quoted_name.c_str()
,th_att->fully_qualified_th_name_.c_str(),th_att->th_enum_
,th_att->name_space_name_->c_string()->c_str()
,th_att->thread_name_->c_string()->c_str());
ofile.write(a,x);
ofile<<std::endl;
}

/*:57*/
//line 850 "/usr/local/yacco2/o2linker/prog.w"

/*58:*/
//line 878 "/usr/local/yacco2/o2linker/prog.w"

div_t c= div(NO_OF_THREADS,BITS_PER_WORD);
if(c.rem!=0)++c.quot;
NO_WORDS_FOR_BIT_MAP= c.quot;

KCHARP thread_array= 
"struct thd_array_type {\n"
"  yacco2::USINT no_entries__;\n"
"  yacco2::Thread_entry* first_entry__[%i];"
"};\n"
"thd_array_type thd_array = {\n"
" %i\n"
" ,\n"
"  {\n";
int x= sprintf(a,thread_array,NO_OF_THREADS,NO_OF_THREADS);

ofile.write(a,x);
ofile<<std::endl;
bool first_entry(true);
thi= GRAMMAR_DICTIONARY.begin();
thie= GRAMMAR_DICTIONARY.end();
KCHARP thread_entry_name= "&I%s";
for(;thi!=thie;++thi){
th_in_stbl*th_tbl= (th_in_stbl*)(*thi)->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
if(th_att->monolithic_=='y')break;
if(first_entry==true){
first_entry= false;
ofile<<"    ";
}else{
ofile<<"   ,";
}
int x= sprintf(a,thread_entry_name,th_att->thread_name_->c_string()->c_str());
ofile.write(a,x);
ofile<<std::endl;
}
ofile<<"  }\n};"<<endl;
/*59:*/
//line 918 "/usr/local/yacco2/o2linker/prog.w"

ofile<<"void* yacco2::THDS_STABLE__ = (void*)&thd_array;"<<endl;

/*:59*/
//line 915 "/usr/local/yacco2/o2linker/prog.w"


/*:58*/
//line 851 "/usr/local/yacco2/o2linker/prog.w"

}

/*:56*//*60:*/
//line 951 "/usr/local/yacco2/o2linker/prog.w"

void emit_T_fs_of_potential_threads(ofstream&ofile){
ofile<<"// Terminal thread sets"<<std::endl;
int no_of_T= T_DICTIONARY.size();
char a[SMALL_BUFFER_4K];
KCHARP T_list_to_thd_list_type= 
"struct T_%i_type{\n"
" yacco2::ULINT first_entry__[%i];\n"
"};\n";
KCHARP T_list_to_thd_list_var= "T_%i_type T_%i = {// for T: %s";
KCHARP thd_id_in_list= "//%i: %s";

INT_SET_LIST_ITER_type i= T_THREAD_ID_LIST.begin();
INT_SET_LIST_ITER_type ie= T_THREAD_ID_LIST.end();
int terminal_id(-1);
for(;i!=ie;++i){
++terminal_id;
INT_SET_type&th_list= *i;
if(th_list.empty()==true)continue;
int x= sprintf(a,T_list_to_thd_list_type,terminal_id,NO_WORDS_FOR_BIT_MAP);
ofile.write(a,x);
ofile<<std::endl;
/*61:*/
//line 984 "/usr/local/yacco2/o2linker/prog.w"

int no_thds_ids= th_list.size();
table_entry*t_entry= T_DICTIONARY[terminal_id];
tth_in_stbl*t_in_stbl= (tth_in_stbl*)t_entry->symbol_;
T_attributes*t_att= t_in_stbl->t_in_stbl();
x= sprintf(a
,T_list_to_thd_list_var
,terminal_id
,terminal_id
,t_att->fully_qualified_T_name_.c_str()
);
ofile.write(a,x);
ofile<<std::endl;
ULINT word_map[SPECULATIVE_NO_BIT_WORDS]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

INT_SET_ITER_type j= th_list.begin();
INT_SET_ITER_type je= th_list.end();

/*62:*/
//line 1007 "/usr/local/yacco2/o2linker/prog.w"

for(;j!=je;++j){
int th_id= *j;
table_entry*tbl_entry= GRAMMAR_DICTIONARY[th_id];
th_in_stbl*th_tbl= (th_in_stbl*)tbl_entry->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
div_t bb= div(th_id,BITS_PER_WORD);
ULINT bit_pos_value= 1<<bb.rem;
word_map[bb.quot]|= bit_pos_value;
int x= sprintf(a,thd_id_in_list,th_id,th_att->thread_name_->c_string()->c_str());
ofile.write(a,x);
ofile<<std::endl;
}

/*:62*/
//line 1002 "/usr/local/yacco2/o2linker/prog.w"

/*63:*/
//line 1022 "/usr/local/yacco2/o2linker/prog.w"

for(int dd= 1;dd<=NO_WORDS_FOR_BIT_MAP;++dd){
if(dd==1)ofile<<" {";
else ofile<<"  ,";
ofile<<word_map[dd-1]<<endl;
}
ofile<<" }"<<endl;
ofile<<"};"<<endl;

/*:63*/
//line 1003 "/usr/local/yacco2/o2linker/prog.w"


/*:61*/
//line 973 "/usr/local/yacco2/o2linker/prog.w"

}
/*64:*/
//line 1033 "/usr/local/yacco2/o2linker/prog.w"

KCHARP T_array_type= 
"struct t_array_type {\n"
"  yacco2::USINT no_entries__;\n"
"  yacco2::thd_ids_having_T* first_entry__[%i];\n"
"};";
int x= sprintf(a,T_array_type,no_of_T);
ofile.write(a,x);
ofile<<std::endl;

KCHARP T_array= 
"t_array_type t_array = {\n"
"  %i\n"
"  ,{";
x= sprintf
(a
,T_array
,no_of_T
);
ofile.write(a,x);
ofile<<std::endl;

i= T_THREAD_ID_LIST.begin();
ie= T_THREAD_ID_LIST.end();
/*65:*/
//line 1063 "/usr/local/yacco2/o2linker/prog.w"

bool first_item(true);
for(int t_id= -1;i!=ie;++i){
++t_id;
table_entry*t_entry= T_DICTIONARY[t_id];
tth_in_stbl*t_in_stbl= (tth_in_stbl*)t_entry->symbol_;
T_attributes*t_att= t_in_stbl->t_in_stbl();
INT_SET_type&th_list= *i;
if(th_list.empty()==true){
if(first_item==true)first_item= false;
else ofile<<"    ,";
KCHARP T_array_entries= "%s// %s";
int x= sprintf(a,T_array_entries,"0",t_att->fully_qualified_T_name_.c_str());
ofile.write(a,x);
ofile<<std::endl;
continue;
}else{
if(first_item==true)first_item= false;
else ofile<<"    ,";
KCHARP T_list_to_thd_list_var= "(yacco2::thd_ids_having_T*)&T_%i // %s";

int x= sprintf(a,T_list_to_thd_list_var,t_id,t_att->fully_qualified_T_name_.c_str());
ofile.write(a,x);
ofile<<std::endl;
}
}

/*:65*/
//line 1057 "/usr/local/yacco2/o2linker/prog.w"

ofile<<"   }\n};"<<endl;
ofile<<"void* yacco2::T_ARRAY_HAVING_THD_IDS__ = (void*)&t_array;"<<endl;

/*:64*/
//line 975 "/usr/local/yacco2/o2linker/prog.w"

}


/*:60*//*66:*/
//line 1091 "/usr/local/yacco2/o2linker/prog.w"

YACCO2_define_trace_variables();
yacco2::TOKEN_GAGGLE Error_queue;
STBL_T_ITEMS_type STBL_T_ITEMS;
std::vector<NS_yacco2_terminals::table_entry*> GRAMMAR_DICTIONARY;
std::map<std::string,std::vector<std::string> > USED_THREADS_LIST;
std::vector<NS_yacco2_terminals::table_entry*> T_DICTIONARY;
INT_SET_LIST_type T_THREAD_ID_LIST;

int NO_OF_THREADS(0);
int NO_WORDS_FOR_BIT_MAP(0);
char Visit_graph[RESERVE_FIXED_NO_THREADS];
extern void XLATE_SYMBOLS_FOR_cweave(const char*Sym_to_xlate,char*Xlated_sym);
extern void PRINT_CALLED_THREAD_LIST
(yacco2::AST*Node,std::ofstream*Ow_linker_file,int Recursion_level);
string cntl_file_name;
yacco2::CHAR PRT_SW('n');

int main(int argc,char*argv[])
{
cout<<yacco2::O2linker_VERSION<<std::endl;
using namespace yacco2;
using namespace std;
load_linkkws_into_tbl();
cout<<"Get command line and parse it "<<endl;
GET_CMD_LINE(argc,argv,Linker_holding_file,Error_queue);
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 1117 "/usr/local/yacco2/o2linker/prog.w"

LINKER_PARSE_CMD_LINE(Linker_holding_file,cntl_file_name,Error_queue);
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 1119 "/usr/local/yacco2/o2linker/prog.w"

lrclog<<yacco2::O2linker_VERSION<<std::endl;
/*17:*/
//line 45 "/usr/local/yacco2/o2linker/prog.w"

cout<<"Parse linker control file "<<endl;
using namespace NS_linker_pass3;
tok_can<std::ifstream> cntl_file_tokens(cntl_file_name.c_str());
TOKEN_GAGGLE P3_tokens;
Clinker_pass3 linker_cntl_file_fsm;
Parser linker_cntl_file(linker_cntl_file_fsm,&cntl_file_tokens,&P3_tokens,0,&Error_queue,0,0);
linker_cntl_file.parse();
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 53 "/usr/local/yacco2/o2linker/prog.w"


/*:17*/
//line 1121 "/usr/local/yacco2/o2linker/prog.w"

/*18:*/
//line 66 "/usr/local/yacco2/o2linker/prog.w"

cout<<"Parse alphabet"<<endl;
using namespace NS_link_cleanser;
tok_can<std::ifstream> T_file_tokens(linker_cntl_file_fsm.t_alphabet_filename_.c_str());
TOKEN_GAGGLE cleanser_tokens;
Clink_cleanser cleanser_fsm;
Parser cleanser(cleanser_fsm,&T_file_tokens,&cleanser_tokens,0,&Error_queue,0,0);
cleanser.parse();

using namespace NS_t_alphabet;
TOKEN_GAGGLE T_tokens;
Ct_alphabet T_fsm;
Parser T_pass3(T_fsm,&cleanser_tokens,&T_tokens,0,&Error_queue,0,0);
T_pass3.parse();
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 80 "/usr/local/yacco2/o2linker/prog.w"


/*:18*/
//line 1122 "/usr/local/yacco2/o2linker/prog.w"

/*19:*/
//line 88 "/usr/local/yacco2/o2linker/prog.w"

cout<<"Parse fsc files"<<endl;
TOKEN_GAGGLE cleanser_fsc_tokens;
TOKEN_GAGGLE fsc_file_output_tokens;
std::vector<std::string> ::iterator ii= linker_cntl_file_fsm.grammars_fsc_files_.begin();
std::vector<std::string> ::iterator iie= linker_cntl_file_fsm.grammars_fsc_files_.end();
for(;ii!=iie;++ii){
tok_can<std::ifstream> T_fsc_file_tokens(ii->c_str());
Clink_cleanser cleanser_fsc;
Parser fsc_cleanser(cleanser_fsc,&T_fsc_file_tokens
,&cleanser_fsc_tokens,0,&Error_queue,0,0);
fsc_cleanser.parse();
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 100 "/usr/local/yacco2/o2linker/prog.w"


using namespace NS_fsc_file;
Cfsc_file fsc_file_fsm;
Parser fsc_file_pass(fsc_file_fsm,&cleanser_fsc_tokens
,&fsc_file_output_tokens,0,&Error_queue,0,0);
fsc_file_pass.parse();
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 107 "/usr/local/yacco2/o2linker/prog.w"

cleanser_fsc_tokens.clear();
fsc_file_output_tokens.clear();
}
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 111 "/usr/local/yacco2/o2linker/prog.w"


/*:19*/
//line 1123 "/usr/local/yacco2/o2linker/prog.w"

/*21:*/
//line 173 "/usr/local/yacco2/o2linker/prog.w"

std::vector<table_entry*> ::iterator th_i= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator th_ie= GRAMMAR_DICTIONARY.end();
for(;th_i!=th_ie;++th_i){
table_entry*tbl_entry= *th_i;

if(tbl_entry->defined_==true)continue;
CAbs_lr1_sym*sym= new Err_bad_th_in_list;
sym->set_who_created("linker.w",__LINE__);

thread_attributes*th_goodies= ((th_in_stbl*)tbl_entry->symbol_)->thread_in_stbl();
sym->set_rc(*th_goodies);
Error_queue.push_back(*sym);
}
/*15:*/
//line 34 "/usr/local/yacco2/o2linker/prog.w"

if(Error_queue.empty()!=true){
DUMP_ERROR_QUEUE(Error_queue);
return 1;
}

/*:15*/
//line 187 "/usr/local/yacco2/o2linker/prog.w"


/*:21*/
//line 1124 "/usr/local/yacco2/o2linker/prog.w"

/*23:*/
//line 263 "/usr/local/yacco2/o2linker/prog.w"

cout<<"Sort thread dictionary"<<endl;
stable_sort(GRAMMAR_DICTIONARY.begin(),GRAMMAR_DICTIONARY.end(),sort_threads_criteria);

/*:23*/
//line 1125 "/usr/local/yacco2/o2linker/prog.w"

/*24:*/
//line 269 "/usr/local/yacco2/o2linker/prog.w"

yacco2::lrclog<<"Sorted thread dictionary"<<GRAMMAR_DICTIONARY.size()<<std::endl;
std::vector<table_entry*> ::iterator dth_i= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator dth_ie= GRAMMAR_DICTIONARY.end();
int pos(-1);
for(;dth_i!=dth_ie;++dth_i){
++pos;
table_entry*tbl_entry= *dth_i;
thread_attributes*th_goodies= ((th_in_stbl*)tbl_entry->symbol_)->thread_in_stbl();
yacco2::lrclog<<"tbl entry*: "
<<tbl_entry<<" th_goodies*: "<<th_goodies
<<" "<<pos<<":"<<th_goodies->th_enum_
<<" mono: "<<th_goodies->monolithic_
<<" thread name: "<<th_goodies->thread_name_->c_string()->c_str()
<<" FQN: "<<th_goodies->fully_qualified_th_name_.c_str()
<<" K: "<<th_goodies->fsm_comments_->c_string()->c_str()
<<std::endl;
}

/*:24*/
//line 1126 "/usr/local/yacco2/o2linker/prog.w"

/*25:*/
//line 291 "/usr/local/yacco2/o2linker/prog.w"

std::vector<table_entry*> ::iterator ri= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator rie= GRAMMAR_DICTIONARY.end();
for(int p= -1;ri!=rie;++ri){
++p;
table_entry*tbl_entry= *ri;
thread_attributes*th_goodies= ((th_in_stbl*)tbl_entry->symbol_)->thread_in_stbl();
th_goodies->th_enum_= p;
if(th_goodies->monolithic_=='n')++NO_OF_THREADS;
}

/*:25*/
//line 1127 "/usr/local/yacco2/o2linker/prog.w"

/*26:*/
//line 304 "/usr/local/yacco2/o2linker/prog.w"

int max_thds_supported= SPECULATIVE_NO_BIT_WORDS*BITS_PER_WORD;
if(NO_OF_THREADS> max_thds_supported){
char a[SMALL_BUFFER_4K];

KCHARP msg= 
"Error: not enough space for thread bit map manufacture!"
" # threads: %i, Linker's maximum no of threads supported: %i. \n"
" Please expand SPECULATIVE_NO_BIT_WORDS";
sprintf(a,msg,NO_OF_THREADS,max_thds_supported);
Yacco2_faulty_precondition(msg,__FILE__,__LINE__);
exit(1);
}

/*:26*/
//line 1128 "/usr/local/yacco2/o2linker/prog.w"

/*36:*/
//line 475 "/usr/local/yacco2/o2linker/prog.w"

/*34:*/
//line 447 "/usr/local/yacco2/o2linker/prog.w"

for(int vi= 0;vi<NO_OF_THREADS;++vi){
Visit_graph[vi]= 'n';
}

/*:34*/
//line 476 "/usr/local/yacco2/o2linker/prog.w"


std::vector<table_entry*> ::iterator thi= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator thie= GRAMMAR_DICTIONARY.end();
for(;thi!=thie;++thi){
th_in_stbl*th_tbl= (th_in_stbl*)(*thi)->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
if(th_att->monolithic_=='n'){
yacco2::lrclog<<"thread being walked: "
<<th_att->thread_name_->c_string()->c_str()<<" id: "
<<th_att->th_enum_<<std::endl;
/*35:*/
//line 454 "/usr/local/yacco2/o2linker/prog.w"

for(int vi= 0;vi<NO_OF_THREADS;++vi){
Visit_graph[vi]= 'n';
}

/*:35*/
//line 487 "/usr/local/yacco2/o2linker/prog.w"

crt_fset_of_thread(*th_att,th_att->th_enum_,*th_att);
}
}
thi= GRAMMAR_DICTIONARY.begin();
thie= GRAMMAR_DICTIONARY.end();
for(;thi!=thie;++thi){
th_in_stbl*th_tbl= (th_in_stbl*)(*thi)->symbol_;
thread_attributes*th_att= th_tbl->thread_in_stbl();
/*35:*/
//line 454 "/usr/local/yacco2/o2linker/prog.w"

for(int vi= 0;vi<NO_OF_THREADS;++vi){
Visit_graph[vi]= 'n';
}

/*:35*/
//line 496 "/usr/local/yacco2/o2linker/prog.w"

crt_called_thread_graph(*th_att);
}

/*:36*/
//line 1129 "/usr/local/yacco2/o2linker/prog.w"

/*51:*/
//line 748 "/usr/local/yacco2/o2linker/prog.w"

cout<<"Emit file name: "<<linker_cntl_file_fsm.emitfile_filename_.c_str()<<endl;
ofstream ofile(linker_cntl_file_fsm.emitfile_filename_.c_str(),ios::out);
if(!ofile){
cout<<"Error - can't open emit file: "
<<linker_cntl_file_fsm.emitfile_filename_.c_str()<<endl;
return 1;
}
emit_cpp_preamble(ofile
,linker_cntl_file_fsm.emitfile_filename_.c_str()
,linker_cntl_file_fsm.preamble_srce_->syntax_code()->c_str());
emit_global_thread_include_files(ofile);
emit_global_bit_maps(ofile);
if(NO_OF_THREADS==0){
emit_no_threads(ofile);
}else{
emit_global_thread_stable(ofile);
emit_T_fs_of_potential_threads(ofile);
}
ofile.close();

/*:51*/
//line 1130 "/usr/local/yacco2/o2linker/prog.w"

/*50:*/
//line 727 "/usr/local/yacco2/o2linker/prog.w"

gen_each_grammar_s_referenced_threads();
char big_buf_[BIG_BUFFER_32K];
std::string w_linker_filename_("o2linker_doc.w");
std::ofstream ow_linker_file_;
ow_linker_file_.open(w_linker_filename_.c_str(),ios_base::out|ios::trunc);
/*46:*/
//line 640 "/usr/local/yacco2/o2linker/prog.w"

KCHARP w_doc_index= 
"\\input \"supp-pdf\"\n"
"\\input \"/usr/local/yacco2/diagrams/o2mac.tex\"\n"
"\\IDXlinkerdoctitle{%s}{%s}{%s}";
char xlate_file[Max_cweb_item_size];xlate_file[0]= (char)0;
char xlate_fscfile[Max_cweb_item_size];xlate_fscfile[0]= (char)0;
XLATE_SYMBOLS_FOR_cweave(w_linker_filename_.c_str(),xlate_file);
XLATE_SYMBOLS_FOR_cweave(cntl_file_name.c_str(),xlate_fscfile);
int x= sprintf(big_buf_
,w_doc_index
,xlate_file
,xlate_file
,xlate_fscfile
);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;
KCHARP w_doc_comments= 
"@** O2linker Index of Grammars.\\fbreak\n"
"The grammars are sorted lexicographically into 2 parts:\n"
"threads followed by the stand alone grammars.\n"
"Each grammar's called threads graph is determined from their \n"
" ``list-of-transitive-threads''\n"
"derived from this construct.%s";
x= sprintf(big_buf_,w_doc_comments," ");
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;

/*:46*/
//line 733 "/usr/local/yacco2/o2linker/prog.w"

/*47:*/
//line 669 "/usr/local/yacco2/o2linker/prog.w"

KCHARP w_grammar= 
"@*2 %s";
KCHARP w_comments= 
"\\Linkeridxentryk{%s}";
KCHARP w_called_threads= 
"\\Linkercalledthreadstitle%s";
char xlate_gfile[Max_cweb_item_size];
char rebuild_comment[Max_cweb_item_size];
char fandk[Max_cweb_item_size];
char xlate_thnm[Max_cweb_item_size];
char xlate_tnm[Max_cweb_item_size];

std::vector<table_entry*> ::iterator ithi= GRAMMAR_DICTIONARY.begin();
std::vector<table_entry*> ::iterator ithie= GRAMMAR_DICTIONARY.end();
for(;ithi!=ithie;++ithi){
xlate_gfile[0]= (char)0;
rebuild_comment[0]= (char)0;
fandk[0]= (char)0;
xlate_thnm[0]= (char)0;
xlate_tnm[0]= (char)0;

table_entry*tbl_entry= *ithi;
thread_attributes*th_att= ((th_in_stbl*)tbl_entry->symbol_)->thread_in_stbl();
/*42:*/
//line 547 "/usr/local/yacco2/o2linker/prog.w"

XLATE_SYMBOLS_FOR_cweave(th_att->thread_name_->c_string()->c_str(),xlate_gfile);
XLATE_SYMBOLS_FOR_cweave(th_att->fsm_comments_->c_string()->c_str(),rebuild_comment);
strcat(fandk,xlate_gfile);
strcat(fandk," --- ");
strcat(fandk,rebuild_comment);
int fandk_len= strlen(fandk);
if(fandk_len<CWEAVE_TITLE_LIMIT){
if(fandk[fandk_len-1]!='.'){
strcat(fandk,".");
}
}else{
if(fandk_len==CWEAVE_TITLE_LIMIT){
if(fandk[CWEAVE_TITLE_LIMIT-1]!='.'){
strcat(fandk,".");
}
}else{
fandk[CWEAVE_TITLE_LIMIT]= (char)0;
strcat(fandk,"$\\ldots$ .");
}
}
int x= sprintf(big_buf_
,w_grammar
,fandk
);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;
x= sprintf(big_buf_
,w_comments
,rebuild_comment
);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;
x= sprintf(big_buf_
,w_called_threads," "
);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;

/*:42*/
//line 693 "/usr/local/yacco2/o2linker/prog.w"

/*43:*/
//line 587 "/usr/local/yacco2/o2linker/prog.w"

prt_called_thread_list_ast_functor prt_functr(&PRINT_CALLED_THREAD_LIST);
prt_functr.o_file(&ow_linker_file_);
ast_prefix pre(*th_att->called_thread_graph_,&prt_functr);
while(pre.base_stk_.cur_stk_rec()!=0){
pre.exec();
}

/*:43*/
//line 694 "/usr/local/yacco2/o2linker/prog.w"

/*45:*/
//line 619 "/usr/local/yacco2/o2linker/prog.w"

ow_linker_file_<<"{\\parindent=6pc"<<endl;
ow_linker_file_<<"\\item{First set:}"<<std::endl;
KCHARP fs= 
"%s\n"
"@.%s@>";
INT_SET_ITER_type fsi= th_att->fs_.begin();
INT_SET_ITER_type fsie= th_att->fs_.end();
char xlate_tnm[Max_cweb_item_size];
for(;fsi!=fsie;++fsi){
int tenum= *fsi;
table_entry*t_entry= T_DICTIONARY[tenum];
tth_in_stbl*t_in_stbl= (tth_in_stbl*)t_entry->symbol_;
T_attributes*t_att= t_in_stbl->t_in_stbl();
XLATE_SYMBOLS_FOR_cweave(t_att->fully_qualified_T_name_.c_str(),xlate_tnm);
int x= sprintf(big_buf_,fs,xlate_tnm,xlate_tnm);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;
}

/*:45*/
//line 695 "/usr/local/yacco2/o2linker/prog.w"

/*44:*/
//line 596 "/usr/local/yacco2/o2linker/prog.w"

std::map<std::string,std::vector<std::string> > ::iterator ti= 
USED_THREADS_LIST.find(th_att->thread_name_->c_string()->c_str());
ow_linker_file_<<"{\\parindent=6pc"<<endl;
ow_linker_file_<<"\\item{Used threads:}"<<std::endl;
KCHARP used_threads= 
"%s\n"
"@.%s@>";
std::vector<std::string> &tt= ti->second;
std::vector<std::string> ::iterator tti= tt.begin();
std::vector<std::string> ::iterator ttie= tt.end();
char xlate_thnm[Max_cweb_item_size];
for(;tti!=ttie;++tti){
XLATE_SYMBOLS_FOR_cweave(tti->c_str(),xlate_thnm);
int x= sprintf(big_buf_,used_threads,xlate_thnm,xlate_thnm);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;
}
if(ti->second.empty()==YES)ow_linker_file_<<" none"<<endl;
ow_linker_file_<<"}"<<endl;

/*:44*/
//line 696 "/usr/local/yacco2/o2linker/prog.w"

}

/*:47*/
//line 734 "/usr/local/yacco2/o2linker/prog.w"

/*48:*/
//line 700 "/usr/local/yacco2/o2linker/prog.w"

KCHARP w_fsc_file_listing= 
"@** First set control file (fsc) listing.\\fbreak\n"
"File : ``%s''\\fbreak\n"
"\\let\\setuplistinghook = \\relax\n"
"\\listing{\"%s\"}\n";
char xlated_filename[Max_cweb_item_size];

XLATE_SYMBOLS_FOR_cweave(cntl_file_name.c_str(),xlated_filename);
x= sprintf(big_buf_
,w_fsc_file_listing
,xlated_filename
,cntl_file_name.c_str()
);
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;

/*:48*/
//line 735 "/usr/local/yacco2/o2linker/prog.w"

/*49:*/
//line 718 "/usr/local/yacco2/o2linker/prog.w"

KCHARP w_index= 
"@** Index.%s";
x= sprintf(big_buf_,w_index," ");
ow_linker_file_.write(big_buf_,x);
ow_linker_file_<<std::endl;


/*:49*/
//line 736 "/usr/local/yacco2/o2linker/prog.w"

ow_linker_file_.close();

/*:50*/
//line 1131 "/usr/local/yacco2/o2linker/prog.w"


return 0;
}
//line 1 "/usr/local/yacco2/o2linker/o2linker_defs.w"







/*:66*/
//line 42 "/usr/local/yacco2/o2linker/includes.w"

//line 20 "./o2linker.w"
/*:89*/