source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Parser/src/Parse_save.cpp @ 32

Last change on this file since 32 was 32, checked in by chou, 17 years ago

Morpheo Viewer Release 5.0
Réalisation des étapes 3 (fin) et 4.

File size: 5.1 KB
Line 
1/*save configuration file
2 * name: file name
3 * type: 0 ->user save a file
4 *       1 ->function apply() temporary save
5 */
6#include "Tools/Viewer/Parser/include/parser.h"
7#include "qmessagebox.h"
8namespace morpheo{
9namespace tools{
10namespace viewer{
11namespace parser{
12
13//   QDomElement Parse::createXMLNode( QDomDocument &d , morpheo::tools::viewer::bdd::Group &grp)
14//   {
15//     QDomElement cn;
16//     cn= d.createElement( QString::fromStdString(grp.getName()));
17     
18//     QList<morpheo::tools::viewer::bdd::Param> p=grp.getParam();
19//     if(p.size()!=0)
20//       {
21//      for(QList<morpheo::tools::viewer::bdd::Param>::iterator it2=p.begin();it2!=p.end();++it2)
22//        {
23//          cn.setAttribute( QString::fromStdString(it2->getName()) ,it2->getValue() );
24//        }
25//       }
26   
27       
28//     return cn;
29//   }
30
31 
32  int Parse::save_file(string name,int type){
33 //    int level=0;
34//     QDomDocument doc( "Viewercfg" );
35//     QDomElement root = doc.createElement("cpu");
36//     QDomNode child=root.setAttribute("name",toplevel);
37//     doc.appendChild(root);
38   
39   
40//     QList<morpheo::tools::viewer::bdd::Group> g=base->getGroups();
41//    for( QList<morpheo::tools::viewer::bdd::Group>::iterator it = g.begin(); it != g.end(); ++it )
42//       {
43//      //3 cas
44//      if(it->getLevel()==0)
45//        save=root.appendChild(createXMLNode( doc , it));
46//      if(it->getLevel()>level){
47//        child=root.appendChild(createXMLNode( doc , it));
48//        root=(QDomElement)child;
49//      }
50//      if(it->getLevel()==level){
51//        root= createXMLNode( doc , it);
52//        save=root;
53//      }
54//      if(it->getLevel()<level){
55//        root.appendChild(createXMLNode( doc , it));
56         
57//      }
58//      root.appendChild(createXMLNode( doc , it));
59   
60//     }
61
62   
63   
64    QString s; 
65    if (type==0)
66      s.append(QString::fromStdString(name));
67    else {
68      s.append(QString::fromStdString(name));
69      s.append("~");
70    }
71
72    QFile file(s);
73    if (!file.open(QIODevice::WriteOnly))
74      {
75        //QMessageBox::warning( this, "Saving", "Failed to save file." );
76        cerr <<"Failed to save file. " <<endl;
77        return -1;
78      }
79    QString ecart;
80    QTextStream ts( &file );
81    ts << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" <<endl<<endl;
82    ts << "<cpu name=\"" << QString::fromStdString(toplevel) << "\" >" <<endl<<endl;
83   
84   
85    QList<morpheo::tools::viewer::bdd::Group> *g=base->getGroups();
86    for( QList<morpheo::tools::viewer::bdd::Group>::iterator it = g->begin(); it != g->end(); ++it )
87      {
88
89        ecart = "  ";
90        if(it->getLevel() == 1)
91          ecart.append("     ");
92        if(it->getLevel() == 2)
93          ecart.append("        ");
94        if(it->getLevel() == 3)
95          ecart.append("          ");
96        if(it->getLevel() == 4)
97          ecart.append("            ");
98        if(it->getLevel() == 5)
99          ecart.append("              ");
100
101        ts << ecart << "<" << QString::fromStdString(it->getName()) ;
102        QList<morpheo::tools::viewer::bdd::Param> p=it->getParam();
103        if(p.size()!=0)
104          {
105            for(QList<morpheo::tools::viewer::bdd::Param>::iterator it2=p.begin();it2!=p.end();++it2)
106              {
107                ts<< " " << QString::fromStdString(it2->getName()) << "=\"" << it2->getValue() << "\" " ;
108              }
109            if (it->getLevel()==0 ||it->getName()=="front_end" ||it->getName()=="prediction_unit"||\
110                it->getName()=="out_of_order_engine"||it->getName()=="execution_loop"||it->getName()=="reservation_station"||\
111                it->getName()=="writeback"||it->getName()=="memory_unit")
112              ts  << "> " <<endl <<endl;
113            else
114              ts  << "/> " <<endl <<endl;
115          }
116        else
117          {
118            ts << ">" <<endl <<endl;
119          }
120
121       
122        if((it+1)!=g->end() && (it+1)->getName()=="front_end" && (it)->getName()=="dcache")
123          ts << "     </cache_unit>" <<endl <<endl;
124         
125        if((it+1)!=g->end() && (it+1)->getName()=="prediction_unit" && (it)->getName()=="ifetch")
126          ts << "        </fetch_unit>" <<endl <<endl;
127        if((it+1)!=g->end() && (it+1)->getName()=="decod_unit" && (it)->getName()=="meta_predictor")
128          ts << "        </prediction_unit>" <<endl <<endl;
129         
130        if((it+1)!=g->end() && (it+1)->getName()=="out_of_order_engine" && (it)->getName()=="decod")
131          {
132            ts << "        </decod_unit>" <<endl <<endl;
133            ts << "     </front_end>" <<endl <<endl;
134          }
135        if((it+1)!=g->end() && (it+1)->getName()=="execution_loop" && (it)->getName()=="commit")
136          ts << "       </out_of_order_engine>" <<endl <<endl;
137        if((it+1)!=g->end() && (it+1)->getName()=="memory_unit" && (it)->getName()=="link")
138          {
139            ts << "          </reservation_station>" <<endl <<endl;
140            ts << "        </read_unit>" <<endl <<endl;
141          }
142       
143        if((it+1)!=g->end() && (it+1)->getName()=="execution_unit" && (it)->getName()=="link")
144            ts << "        </memory_unit>" <<endl <<endl;
145
146        if((it+1)!=g->end() && (it+1)->getName()=="write_unit" && (it)->getName()=="execution")
147            ts << "        </execution_unit>" <<endl <<endl;
148
149        if((it+1)!=g->end() && (it+1)->getName()=="writeback" && (it)->getName()=="link")
150            ts << "        </writeback>" <<endl <<endl;
151       
152       
153      }
154
155    ts << "         </writeback>" <<endl <<endl;
156    ts << "      </write_unit>" <<endl<<endl;
157    ts << "    </execution_loop>" <<endl<<endl;
158    ts << "  </core>" <<endl<<endl;
159    ts << "</cpu>" <<endl<<endl;
160    file.close();
161    return 0;
162
163
164  }
165
166
167};//end parser
168};//end viewer
169};//end tools
170};//end morpheo
171
Note: See TracBrowser for help on using the repository browser.