/*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*/
