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