void Program::in_file(string const filename){ Line* element = _head; ofstream monflux(filename.c_str()); if(monflux){ while(element != NULL) { if(element->type_line()==line_Instru || element->type_line()== line_Direct) monflux<<"\t"; monflux << element-> get_content(); if(element->get_next()==NULL) break; else { if(element->get_content().compare("nop")) monflux<<endl; element = element->get_next(); } } } else { cout<<"Error cannot open the file"<<endl; } monflux.close(); }
void Basic_block::restitution(string const filename){ Node* element = _head; ofstream monflux(filename.c_str(), ios::app); if(monflux){ monflux<<"Begin BB"<<endl; if(element == _end) monflux << _head->get_lineContent() <<endl; while(element != _end) { if(element->get_line()->isInst()) monflux<<"\t"; if(!element->get_line()->isDirective()) monflux << element->get_lineContent()<<endl ; if(element->get_next()==_end){ if(element->get_next()->get_line()->isInst()) monflux<<"\t"; if(!element->get_line()->isDirective()) monflux << element->get_next()->get_lineContent()<<endl; break; } else element = element->get_next(); } monflux<<"End BB\n\n"<<endl; } else { cout<<"Error cannot open the file"<<endl; } monflux.close(); }
void Function::restitution(string const filename){ Node* element = _head; ofstream monflux(filename.c_str(), ios::app); if(monflux){ monflux<<"Begin"<<endl; if(element == _end) monflux << _head->get_line()-> get_content() <<endl; while(element != _end) { if(element->get_line()->type_line()==line_Instru || element->get_line()->type_line()== line_Direct) monflux<<"\t"; monflux << element->get_line()-> get_content() ; if(element->get_line()->get_content().compare("nop")) monflux<<endl; if(element->get_next()==_end){ if(element->get_next()->get_line()->type_line()==line_Instru || element->get_next()->get_line()->type_line()==line_Direct) monflux<<"\t"; monflux << element->get_next()->get_line()-> get_content()<<endl; break; } else element = element->get_next(); } monflux<<"End\n\n"<<endl; } else { cout<<"Error cannot open the file"<<endl; } monflux.close(); }
//Donner Null pour le BB en parametre de la fonction lors de son appel void Cfg::restitution(Basic_block *BB, string const filename){ if (BB == NULL) remove(filename.c_str()); ofstream monflux(filename.c_str(), ios::app); int test=0, end=0; if(monflux){ if(BB == NULL) { BB = _head; for(int i=0; i<_length; i++) _read[i]=0; monflux<<"digraph G1 {"<<endl; } if(!_read[BB->get_index()]){ _read[BB->get_index()]=1; //ecriture des successeurs dans le fichier if(BB->get_nb_succ() >= 1){ monflux<<"BB"<<BB->get_index()<<" -> BB"<<BB->get_successor1()->get_index()<<";"<<endl; if(BB->get_nb_succ()==2){ monflux<<"BB"<<BB->get_index()<<" -> BB"<<BB->get_successor2()->get_index()<<";"<<endl; } monflux.close(); restitution(BB->get_successor1(), filename); if(BB->get_nb_succ()==2) restitution(BB->get_successor2(), filename); } //lecture du fichier pour savoir s'il y a d�j� un parenthese de fin ifstream fichier(filename.c_str()); if(fichier){ string ligne; //Une variable pour stocker les lignes lues while(getline(fichier, ligne)) //Tant qu'on n'est pas a la fin, on lit { end=0; if(!ligne.compare("}")) end=1; } } else { cout << "ERREUR: Impossible d'ouvrir le fichier en lecture." << endl; } //si pas de parenthese la rajouter if(!end){ monflux.open(filename.c_str(), ios::app); for(int i=0; i<_length; i++) if(_read[i]==0) { test=1; } if(!test) monflux<<"}"<<endl; monflux.close(); } } } }
//Pour générer le fichier .dot: dot -Tps graph.dot -o graph.ps void Dfg::restitute(Node_dfg * node, string const filename, bool first){ if(first) remove(filename.c_str()); ofstream monflux(filename.c_str(), ios::app); list<Node_dfg*>::iterator it; if(first && _length){ for(int i=0; i<_length; i++) _read[i]=0; it = _delayed_slot.begin(); int index_min = _length; for(unsigned int i=0; i < _delayed_slot.size(); i++){ _read[(*it)->get_instruction()->get_index()] = 1; if (index_min > (*it)->get_instruction()->get_index()) index_min = (*it)->get_instruction()->get_index(); it++; } monflux<<"digraph G1 {"<<endl; for(int i=0; i<index_min; i++){ monflux<<"i"<<i<< ";"<<endl; } } it=_roots.begin(); for (unsigned int j=0; j<_roots.size();j++ ){ if(first) node = *it; if(monflux){ //monflux.open(filename.c_str(), ios::app); if(!_read[node->get_instruction()->get_index()]){ _read[node->get_instruction()->get_index()]=1; //On affiche ses successeurs s'il en a for(int i=0; i<node->get_nb_arcs(); i++){ if (node->get_arc(i)){ monflux<<"i"<<node->get_instruction()->get_index(); monflux<<" -> i" << node->get_arc(i)->next->get_instruction()->get_index(); // monflux<<"i"<<node->get_instruction()->get_index()<<"_"<<node->get_weight(); // monflux<<" -> i" << node->get_arc(i)->next->get_instruction()->get_index(); // monflux<<"_"<<node->get_arc(i)->next->get_weight(); monflux<<" [label= \""<< DEP(node->get_arc(i)->dep) << node->get_arc(i)->delai<<"\"];"<<endl; } } monflux.close(); for(int i=0;i<node->get_nb_arcs();i++){ if (node->get_arc(i)) restitute(node->get_arc(i)->next,filename.c_str(),false); } } } if((j+1) < _roots.size()) monflux.open(filename.c_str(), ios::app); it++; } if (first && _length){ monflux.open(filename.c_str(), ios::app); monflux<<"}"<<endl; monflux.close(); } return; }