Changeset 52 for sources/src/graph_cass.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/graph_cass.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : graph_cass.cc |6 | |7 | Author : Petrot Frédéric |8 | Taktak Sami |9 | Buchmann Richard |10 | |11 | Date : 09_07_2004 |12 | |13 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : graph_cass.cc | 6 | | 7 | Author : Petrot Frédéric | 8 | Taktak Sami | 9 | Buchmann Richard | 10 | | 11 | Date : 09_07_2004 | 12 | | 13 \------------------------------------------------------------*/ 14 14 15 15 /* … … 107 107 * bug fix : 108 108 * - allow the use of user-defined structs in sc_signal/sc_in/sc_out/sc_inout 109 110 111 112 113 114 115 116 109 * - use sc_dt namespace like official SystemC engine 110 * 111 * add : 112 * - dump the signal/port/module dependancy graph in dot format 113 * 114 * Graph library is now splitted from the SystemCASS specific code. 115 * 116 */ 117 117 118 118 #include <iostream> … … 129 129 #include "entity.h" 130 130 #include "simplify_string.h" // simplify_string 131 #include "sc_ver_ext.h" 131 #include "sc_ver_ext.h" // sc_version for dumping to DOT 132 132 #ifdef HAVE_CONFIG_H 133 133 #include "config.h" … … 138 138 namespace sc_core { 139 139 140 #if 0 141 static 142 ostream& operator << (ostream& o, 143 const Vertex & v) 144 { 145 #if 0 146 if (v.arcs == NULL) 147 o << v.name << "(" << v.module->ins_name << ")->(none)\n"; 148 Arc *a; 149 for (a = v.arcs; a; a = a->next) 150 o << v.name << "(" << v.module->ins_name << ")->" 151 << a->tip->name << "(" << a->tip->module << ")\n"; 152 return o; 153 #endif 154 method_process_t* m = (method_process_t*)(v.data); 155 if (v.arcs == NULL) 156 o << *m << "\n"; 157 Arc *a; 158 for (a = v.arcs; a; a = a->next) { 159 method_process_t* m2 = (method_process_t*)(a->tip->data); 160 o << *m << "->" 161 << *m2 << ")\n"; 162 } 163 return o; 164 165 } 166 #endif 167 168 #if 0 169 static 170 ostream& 171 operator << (ostream &o, 172 const Graph &g) 173 { 174 Vertex *v; 175 for (v = g.vertices; v < g.vertices + g.n; v++) { 176 o << *v; 177 } 178 return o; 179 } 180 #endif 181 182 std::map<const method_process_t*,Vertex*> m_v; 183 184 /* Ajoute un arc */ 185 void add_arcs(const method_process_t &mp, const sc_module &module) 186 { 187 std::map<const method_process_t*,Vertex*>::iterator i; 188 for (i = m_v.begin (); i != m_v.end (); ++i) { 189 if (i->first->module == &module) 190 new_arc (m_v[&mp],i->second); 191 } 192 } 193 194 /* Ajoute un arc */ 195 void add_arcs(const method_process_t &mp, 196 tab_t *signal_pointer) 197 { 198 equi_t &e = get_equi (signal_pointer); 199 equi_t::iterator i; 200 for (i = e.begin (); i != e.end (); ++i) { 201 const char *kind = i->kind (); 202 if (strstr (kind,"out")) { 203 const sc_port_base &port = *(i->port); 204 const sc_module &module = port.get_module (); 205 if (&module == mp.module) 206 continue; 207 add_arcs (mp, module); 208 break; 209 } 210 } 211 } 212 213 void 214 add_arcs(const method_process_t &mp) 215 { 216 sensitivity_list_t::const_iterator port_bound; 217 for (port_bound = mp.sensitivity_list.begin(); port_bound != mp.sensitivity_list.end(); ++port_bound) { 218 // pour tous les ports/signaux p associés à la fonction au couple m 219 /* si pp est un port de sortie d'une autre fonction de mealy, 220 crée un arc entre m et mm */ 221 /* on ne peut pas savoir si un port est la sortie d'une fonction de mealy. 222 on va donc chercher à savoir si c'est un port de sortie d'un automate de moore, 223 sinon on considère que c'est une sortie de mealy. 224 */ 225 226 add_arcs(mp, port_bound->get_interface().get_pointer ()); 227 } 228 } 140 std::map < const method_process_t *, Vertex * >m_v; 141 142 /* Ajoute un arc */ 143 void add_arcs(const method_process_t & mp, const sc_module & module) { 144 std::map < const method_process_t *, Vertex * >::iterator i; 145 for (i = m_v.begin(); i != m_v.end(); ++i) { 146 if (i->first->module == &module) 147 new_arc(m_v[&mp], i->second); 148 } 149 } 150 151 152 /* Ajoute un arc */ 153 void add_arcs(const method_process_t & mp, tab_t * signal_pointer) { 154 equi_t & e = get_equi(signal_pointer); 155 equi_t::iterator i; 156 for (i = e.begin(); i != e.end(); ++i) { 157 const char * kind = i->kind(); 158 if (strstr(kind, "out")) { 159 const sc_port_base & port = *(i->port); 160 const sc_module & module = port.get_module(); 161 if (&module == mp.module) { 162 continue; 163 } 164 add_arcs(mp, module); 165 break; 166 } 167 } 168 } 169 170 171 void add_arcs(const method_process_t & mp) { 172 sensitivity_list_t::const_iterator port_bound; 173 for (port_bound = mp.sensitivity_list.begin(); 174 port_bound != mp.sensitivity_list.end(); ++port_bound) { 175 // pour tous les ports/signaux p associés à la fonction au couple m 176 /* si pp est un port de sortie d'une autre fonction de mealy, 177 crée un arc entre m et mm */ 178 /* on ne peut pas savoir si un port est la sortie d'une fonction de mealy. 179 on va donc chercher à savoir si c'est un port de sortie d'un automate de moore, 180 sinon on considère que c'est une sortie de mealy. 181 */ 182 add_arcs(mp, port_bound->get_interface().get_pointer()); 183 } 184 } 185 229 186 230 187 /* Construit le graph de dépendance des signaux de Mealy */ … … 238 195 Vertex is an array of (method_process_t*) 239 196 Edge is a couple Vertex->Vertex. 197 */ 198 extern Graph * makegraph(const method_process_list_t * lm) { 199 method_process_list_t::const_iterator mp; 200 201 int n = 0; /* Number of vertices */ 202 Graph * g; 203 Vertex * v; 204 205 /* Compute the number of vertices in the graph: 206 * The vertices set is the method set. */ 207 208 /* for (m = lm->begin(); m != lm->end(); m++) 209 n++;*/ 210 n = lm->size(); 211 212 /* Create the graph */ 213 g = gb_new_graph(n); 214 215 /* Associate the netlist elements to the graph vertices, and vice-versa */ 216 v = g->vertices; 217 218 /* initialisation des vertices */ 219 for (mp = lm->begin(); mp != lm->end(); ++mp) { 220 v->data = *mp; 221 m_v[*mp] = v++; 222 } 223 224 for (mp = lm->begin(); mp != lm->end(); ++mp) { 225 // pour tous couples m, instance module/function de la liste lm 226 add_arcs(**mp); 227 } 228 229 return g; 230 } 231 232 233 static string & get_method_process_fullname(string & name, const method_process_t & mp) { 234 sc_module * module = mp.module; 235 name = module->name(); 236 name += "_"; 237 name += mp.name; 238 return name; 239 } 240 241 242 static bool dot_write(ofstream & o, const Graph & g) { 243 string name1, name2, s; 244 // Printing into dot file 245 for (int i = 0; i < g.n; ++i) { // Printing node list 246 Vertex * v = g.vertices + i; 247 method_process_t *mp = (method_process_t *) (v->data); 248 get_method_process_fullname(name1, *mp); 249 const char * pname1 = name1.c_str(); 250 o << "node [name="; 251 o.width(35); 252 o << simplify_name(pname1, s); 253 o << "];\n"; 254 } 255 for (int i = 0; i < g.n; ++i) { // Printing edge list 256 Vertex * v1 = g.vertices + i; 257 method_process_t *mp1 = (method_process_t *) (v1->data); 258 get_method_process_fullname(name1, *mp1); 259 const char * pname1 = name1.c_str(); 260 for (Arc * a = v1->arcs; a != NULL; a = a->next) { 261 Vertex *v2 = a->tip; 262 method_process_t * mp2 = (method_process_t *) (v2->data); 263 get_method_process_fullname(name2, *mp2); 264 const char * pname2 = name2.c_str(); 265 o.width(35); 266 o << simplify_name(pname2, s); 267 o << " -> "; 268 o.width(35); 269 o << simplify_name(pname1, s); 270 o << ";\n"; 271 } 272 } 273 return true; 274 } 275 276 extern bool graph2dot(const char * name, const Graph & g) { 277 if (!name) { 278 return false; 279 } 280 string filename; 281 filename = name; 282 filename += ".dot"; 283 ofstream o; 284 o.open(filename.c_str(), ios::out | ios::trunc); 285 if (o.is_open() == false) { 286 return false; 287 } 288 o << "// Module dependency graph\n// Generated by " << sc_version() << "\n"; 289 o << "strict digraph " << name << " {\n"; 290 o << "node [shape=box];\n"; 291 // "concentrate=true;\n"; 292 o << left; 293 dot_write(o, g); 294 // Closing dot file 295 o << "}\n"; 296 o.close(); 297 if (dump_stage) { 298 cerr << "Module dependency graph written into '" << filename << "'.\n"; 299 } 300 return true; 301 } 302 303 } // end of sc_core namespace 304 305 /* 306 # Local Variables: 307 # tab-width: 4; 308 # c-basic-offset: 4; 309 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 310 # indent-tabs-mode: nil; 311 # End: 312 # 313 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 240 314 */ 241 extern Graph* 242 makegraph (const method_process_list_t *lm) 243 { 244 method_process_list_t::const_iterator mp; 245 246 int n = 0; /* Number of vertices */ 247 Graph *g; 248 Vertex *v; 249 250 /* Compute the number of vertices in the graph: 251 * The vertices set is the method set. */ 252 253 /* for (m = lm->begin(); m != lm->end(); m++) 254 n++;*/ 255 n = lm->size (); 256 257 /* Create the graph */ 258 g = gb_new_graph(n); 259 260 /* Associate the netlist elements to the graph vertices, and vice-versa */ 261 v = g->vertices; 262 263 /* initialisation des vertices */ 264 for (mp = lm->begin(); mp != lm->end(); ++mp) { 265 v->data = *mp; 266 m_v[*mp] = v++; 267 } 268 269 for (mp = lm->begin(); mp != lm->end(); ++mp) { 270 // pour tous couples m, instance module/function de la liste lm 271 add_arcs (**mp); 272 } 273 274 return g; 275 } 276 277 /* 278 void 279 dot_write_edge (const method_process_t &mp, 280 tab_t *signal_pointer) 281 { 282 equi_t &e = get_equi (signal_pointer); 283 equi_t::iterator i; 284 for (i = e.begin (); i != e.end (); ++i) { 285 const char *kind = i->kind (); 286 if (strstr (kind,"out")) { 287 const sc_port_base &port = *(i->port); 288 const sc_module &module = port.get_module (); 289 if (&module == mp.module) 290 continue; 291 add_arcs (mp, module); 292 o << "edge [label=" 293 << "];\n"; 294 o << " -> "; 295 o << ";\n"; 296 } 297 } 298 } 299 300 static 301 bool 302 dot_write_edge (ofstream &o, 303 const method_process_t &mp) 304 { 305 sensitivity_list_t::const_iterator port_bound; 306 for (port_bound = mp.sensitivity_list.begin(); port_bound != mp.sensitivity_list.end(); ++port_bound) 307 dot_write_edge (o, mp, port_bound->get_interface().get_pointer ()); 308 } 309 310 static 311 bool 312 dot_write (ofstream &o, 313 const method_process_list_t &lm) 314 { 315 // Printing into dot file 316 string s; 317 method_process_list_t::const_iterator mp; 318 for (mp = lm.begin(); mp != lm.end(); ++mp) { 319 method_process_t *amp = *mp; 320 sc_module *module = amp->module; 321 o << "node [name=" 322 // << simplify_name(module.get_name().c_str(),s) 323 << "];\n"; 324 } 325 for (mp = lm->begin(); mp != lm->end(); ++mp) 326 dot_write (o, **mp); 327 } 328 */ 329 330 static 331 string& 332 get_method_process_fullname (string &name, 333 const method_process_t &mp) 334 { 335 sc_module *module = mp.module; 336 name = module->name (); 337 name += "_"; 338 name += mp.name; 339 return name; 340 } 341 342 static 343 bool 344 dot_write (ofstream &o, 345 const Graph &g) 346 { 347 string name1,name2,s; 348 // Printing into dot file 349 for (int i = 0; i < g.n; ++i) 350 { // Printing node list 351 Vertex *v = g.vertices + i; 352 method_process_t *mp = (method_process_t*) (v->data); 353 get_method_process_fullname (name1,*mp); 354 const char *pname1 = name1.c_str(); 355 o << "node [name="; 356 o.width (35); 357 o << simplify_name(pname1,s); 358 o << "];\n"; 359 } 360 for (int i = 0; i < g.n; ++i) 361 { // Printing edge list 362 Vertex *v1 = g.vertices + i; 363 method_process_t *mp1 = (method_process_t*) (v1->data); 364 get_method_process_fullname (name1,*mp1); 365 const char *pname1 = name1.c_str(); 366 for (Arc *a = v1->arcs; a != NULL; a = a->next) 367 { 368 Vertex *v2 = a->tip; 369 method_process_t *mp2 = (method_process_t*) (v2->data); 370 get_method_process_fullname (name2,*mp2); 371 const char *pname2 = name2.c_str(); 372 o.width (35); 373 o << simplify_name(pname2,s); 374 o << " -> "; 375 o.width (35); 376 o << simplify_name(pname1,s); 377 o << ";\n"; 378 } 379 } 380 381 return true; 382 } 383 384 extern bool 385 graph2dot (const char *name, 386 const Graph &g) 387 { 388 if (!name) 389 return false; 390 string filename; 391 filename = name; 392 filename += ".dot"; 393 ofstream o; 394 o.open (filename.c_str(),ios::out | ios::trunc); 395 if (o.is_open () == false) 396 return false; 397 o << "// Module dependency graph\n" 398 "// Generated by " 399 << sc_version () << "\n"; 400 o << "strict digraph " << name << " {\n"; 401 o << "node [shape=box];\n"; 402 // "concentrate=true;\n"; 403 o << left; 404 dot_write (o,g); 405 // Closing dot file 406 o << "}\n"; 407 o.close (); 408 if (dump_stage) 409 cerr << "Module dependency graph written into '" 410 << filename << "'.\n"; 411 return true; 412 } 413 414 } // end of sc_core namespace 415 315
Note: See TracChangeset
for help on using the changeset viewer.