Changeset 52 for sources/src/entity.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/entity.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : entity.cc |6 | |7 | Author : Buchmann Richard |8 | Taktak Sami |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : entity.cc | 6 | | 7 | Author : Buchmann Richard | 8 | Taktak Sami | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 40 40 #include <map> 41 41 #include <vector> 42 43 42 #include <cassert> 43 44 44 #include "entity.h" 45 45 #include "sc_port.h" 46 46 #include "sc_signal.h" 47 47 #include "sc_module.h" 48 48 49 #ifdef HAVE_CONFIG_H 49 50 #include "config.h" … … 53 54 54 55 namespace sc_core { 55 equi_list_t equi_list; 56 equi_table_t equi_table = NULL; 57 58 ostream& operator << (ostream &, const entity &); 59 ostream& operator << (ostream &, const equi_t &); 60 61 struct predic4entity2equi_t_t 62 { 63 bool operator()(const entity &e1, const entity &e2) const 64 { 65 return e1.interface < e2.interface; 66 } 67 }; 68 69 typedef std::map<entity,equi_list_t::iterator,predic4entity2equi_t_t> entity2equi_it_t; 70 71 ostream& operator << (ostream& o, const entity2equi_it_t &m) 72 { 56 57 equi_list_t equi_list; 58 equi_table_t equi_table = NULL; 59 60 ostream & operator << (ostream &, const entity &); 61 ostream & operator << (ostream &, const equi_t &); 62 63 struct predic4entity2equi_t_t { 64 bool operator() (const entity & e1, const entity & e2) const { 65 return e1.interface < e2.interface; 66 } 67 }; 68 69 typedef std::map <entity, equi_list_t::iterator, predic4entity2equi_t_t> entity2equi_it_t; 70 71 72 ostream & operator << (ostream & o, const entity2equi_it_t & m) { 73 73 entity2equi_it_t::const_iterator i; 74 for (i = m.begin(); i != m.end(); ++i) 75 { 76 o << (i->first) << " : " << *(i->second) << "\n"; 74 for (i = m.begin(); i != m.end(); ++i) { 75 o << (i->first) << " : " << *(i->second) << "\n"; 77 76 } 78 77 return o; 79 } 80 entity2equi_it_t equi_map; 81 82 const equi_list_t& get_equi_list () 83 { 78 } 79 80 entity2equi_it_t equi_map; 81 82 83 const equi_list_t & get_equi_list() { 84 84 return equi_list; 85 } 86 87 unsigned int 88 max (unsigned int a, unsigned int b) 89 { 90 return (a > b)?a:b; 91 } 92 93 static 94 int get_signal_table_size (const equi_list_t &e) 95 { 96 // bug fix : remove the 0x0 equi from the list 85 } 86 87 88 unsigned int max(unsigned int a, unsigned int b) { 89 return (a > b) ? a : b; 90 } 91 92 93 static int get_signal_table_size(const equi_list_t & e) { 94 // bug fix : remove the 0x0 equi from the list 97 95 equi_list_t::const_iterator i; 98 96 int capacity = 0; 99 for (i = e.begin (); i != e.end(); ++i) {100 //cerr << i->begin()->object->name ();101 const entity &ent = *(i->begin());102 intdata_size = ent.data_size_in_bytes();103 intnumber_of_part = ((data_size - 1) / sizeof(tab_t)) + 1;104 capacity += number_of_part;97 for (i = e.begin(); i != e.end(); ++i) { 98 //cerr << i->begin()->object->name (); 99 const entity & ent = *(i->begin()); 100 int data_size = ent.data_size_in_bytes(); 101 int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; 102 capacity += number_of_part; 105 103 } 106 104 return capacity; 107 } 108 109 int get_signal_table_size () 110 { 111 return get_signal_table_size (equi_list); 112 } 113 114 sc_port_base* 115 get_out_port (const equi_t &eq) 116 { 117 equi_t::const_iterator i; 118 for (i = eq.begin (); i != eq.end (); ++i) { 119 const char *type = i->kind (); 120 if ((type == sc_core::sc_out_string)||(type == sc_core::sc_inout_string)) 121 return i->port; 122 } 123 /* 124 cerr << "Internal error : can't find out port in " 125 << eq << ".\n"; 126 exit(32); 127 */ 128 return NULL; 129 } 130 131 static 132 sc_port_base* 133 get_localvar (equi_t &eq) 134 { 135 equi_t::iterator i; 136 for (i = eq.begin (); i != eq.end (); ++i) { 137 const char *type = i->kind (); 138 if (strcmp (type, "sc_localvar") == 0) 139 return i->port; 140 } 141 return NULL; 142 } 143 144 static 145 sc_port_base* 146 get_signal (equi_t &eq) 147 { 148 equi_t::iterator i; 149 for (i = eq.begin (); i != eq.end (); ++i) { 150 const char *type = i->kind (); 151 if (strcmp (type, "sc_signal") == 0) 152 return i->port; 153 } 154 return NULL; 155 } 156 157 equi_t& 158 get_equi (const sc_interface &i) 159 { 160 return get_equi (i.get_pointer ()); 161 } 162 163 struct predic4tab_t2equi_t_t 164 { 165 bool operator()(const tab_t *t1, const tab_t *t2) const 166 { 167 return t1 < t2; 168 } 169 }; 105 } 106 107 108 int get_signal_table_size() { 109 return get_signal_table_size(equi_list); 110 } 111 112 113 sc_port_base * get_out_port(const equi_t & eq) { 114 equi_t::const_iterator i; 115 for (i = eq.begin(); i != eq.end(); ++i) { 116 const char * type = i->kind(); 117 if ((type == sc_core::sc_out_string) || (type == sc_core::sc_inout_string)) { 118 return i->port; 119 } 120 } 121 return NULL; 122 } 123 124 static sc_port_base *get_localvar(equi_t & eq) { 125 equi_t::iterator i; 126 for (i = eq.begin(); i != eq.end(); ++i) { 127 const char *type = i->kind(); 128 if (strcmp(type, "sc_localvar") == 0) { 129 return i->port; 130 } 131 } 132 return NULL; 133 } 134 135 136 static sc_port_base *get_signal(equi_t & eq) { 137 equi_t::iterator i; 138 for (i = eq.begin(); i != eq.end(); ++i) { 139 const char * type = i->kind(); 140 if (strcmp(type, "sc_signal") == 0) { 141 return i->port; 142 } 143 } 144 return NULL; 145 } 146 147 148 equi_t & get_equi(const sc_interface & i) { 149 return get_equi(i.get_pointer()); 150 } 151 152 153 struct predic4tab_t2equi_t_t { 154 bool operator() (const tab_t * t1, const tab_t * t2) const { 155 return t1 < t2; 156 } 157 }; 158 170 159 171 160 #define get_equi_SPEEDUP 172 equi_t& 173 get_equi (const tab_t *pointer) 174 { 161 equi_t & get_equi(const tab_t * pointer) { 175 162 // result variable 176 163 equi_list_t::iterator i; 177 164 #if defined(get_equi_SPEEDUP) 178 typedef std::map <const tab_t *,equi_list_t::iterator,predic4tab_t2equi_t_t> tab_t2equi_it_t;165 typedef std::map <const tab_t *, equi_list_t::iterator, predic4tab_t2equi_t_t> tab_t2equi_it_t; 179 166 static tab_t2equi_it_t tab2equi_map; 180 167 assert(pointer != NULL); 181 168 182 169 // boost 183 tab_t2equi_it_t::/*const_*/iterator it = tab2equi_map.find (pointer); 184 if (it != tab2equi_map.end ()) 185 { 186 i = it->second; 187 return *i; 188 } 189 #endif 190 // 191 for (i = equi_list.begin (); i != equi_list.end (); ++i) { 192 const equi_t::iterator &j = i->begin(); 193 const entity &e = *j; 194 const sc_interface *f = e.interface; 195 const tab_t *p = f->get_pointer (); 196 if (p == pointer) 197 { 170 tab_t2equi_it_t:: /*const_ */ iterator it = tab2equi_map.find(pointer); 171 if (it != tab2equi_map.end()) { 172 i = it->second; 173 return *i; 174 } 175 #endif 176 177 178 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 179 const equi_t::iterator & j = i->begin(); 180 const entity & e = *j; 181 const sc_interface * f = e.interface; 182 const tab_t * p = f->get_pointer(); 183 if (p == pointer) { 198 184 #if defined(get_equi_SPEEDUP) 199 tab2equi_map[pointer] = i;200 #endif 201 202 }203 204 cerr << "Internal error : get_equi(" << pointer << ")\n"; 205 exit(11);206 185 tab2equi_map[pointer] = i; 186 #endif 187 return *i; 188 } 189 } 190 cerr << "Internal error : get_equi(" << pointer << ")\n"; 191 exit(11); 192 } 207 193 #undef get_equi_SPEEDUP 208 194 209 bool 210 has_equi (/*const*/ sc_port_base &port) 211 { 195 196 bool has_equi( /*const */ sc_port_base & port) { 212 197 entity e(port); 213 entity2equi_it_t::/*const_*/iterator it = equi_map.find (e); 214 if (it == equi_map.end ()) 215 { 216 return false; 198 entity2equi_it_t::/*const_ */iterator it = equi_map.find(e); 199 if (it == equi_map.end()) { 200 return false; 217 201 } 218 202 return true; 219 } 220 221 static 222 bool 223 is_register (const equi_t &eq) 224 { 225 return eq.size () == 1; 226 } 227 228 static 229 int 230 count_level (const char *s, char c) 231 { 232 int i; 233 int counter = 0; 234 for (i = 0; s[i] != '\0'; ++i) { 235 if (s[i] == c) 236 ++counter; 237 } 238 return counter; 239 } 240 241 const char* 242 get_name (const equi_t& e) 243 { 244 equi_t::const_iterator top_iter = e.begin (); 203 } 204 205 206 static bool is_register(const equi_t & eq) { 207 return eq.size() == 1; 208 } 209 210 static int count_level(const char * s, char c) { 211 int i; 212 int counter = 0; 213 for (i = 0; s[i] != '\0'; ++i) { 214 if (s[i] == c) { 215 ++counter; 216 } 217 } 218 return counter; 219 } 220 221 222 const char * get_name(const equi_t & e) { 223 equi_t::const_iterator top_iter = e.begin(); 245 224 #ifdef CONFIG_DEBUG 246 if (top_iter == e.end()) {247 248 exit(25);249 250 251 252 253 254 exit(26);255 256 if (top_iter->object->name() == NULL) {257 258 259 260 261 #endif 262 int top_level = count_level (top_iter->object->name (),'.');263 264 for (i = ++(e.begin ()); i != e.end(); ++i) {265 int current_level = count_level (i->object->name (),'.');266 267 268 269 270 225 if (top_iter == e.end()) { 226 cerr << "Internal error : no signal in " << e << endl; 227 exit(25); 228 } 229 if (top_iter->object == NULL) { 230 cerr << "Internal error : no object bound to "; 231 cerr << *top_iter; 232 cerr << endl; 233 exit(26); 234 } 235 if (top_iter->object->name() == NULL) { 236 cerr << "Internal error : signal has no name.\n"; 237 cerr << *top_iter; 238 cerr << endl; 239 } 240 #endif 241 int top_level = count_level(top_iter->object->name(), '.'); 242 equi_t::const_iterator i; 243 for (i = ++(e.begin()); i != e.end(); ++i) { 244 int current_level = count_level(i->object->name(), '.'); 245 if (current_level < top_level) { 246 top_iter = i; 247 top_level = current_level; 248 } 249 } 271 250 #if 0 272 cerr << "get_name of " << e; 273 cerr << " return " << top_iter->object->name () << endl; 274 #endif 275 return top_iter->object->name (); 276 } 277 278 const char* 279 get_name (const tab_t *pointer) 280 { 281 return get_name (get_equi (pointer)); 282 } 283 284 static 285 const sc_module& 286 get_module (const string &s) 287 { 288 instances_set_t::iterator i; 289 for (i = instances_set.begin (); i != instances_set.end (); ++i) { 290 if (strcmp ((*i)->name (), s.c_str ()) == 0) 291 return **i; 292 } 293 cerr << "Internal error : get_module\n"; 294 exit (27); 295 } 296 297 template<typename T> static 298 equi_list_t::iterator get_equi (T &e) 299 { 300 entity2equi_it_t::iterator it = equi_map.find (entity(e)); 301 if (it == equi_map.end()) 302 { 303 // cerr << "Internal error : get_equi (T &)"; 304 return equi_list.end (); 251 cerr << "get_name of " << e; 252 cerr << " return " << top_iter->object->name() << endl; 253 #endif 254 return top_iter->object->name(); 255 } 256 257 258 const char *get_name(const tab_t * pointer) { 259 return get_name(get_equi(pointer)); 260 } 261 262 263 static const sc_module & get_module(const string & s) { 264 instances_set_t::iterator i; 265 for (i = instances_set.begin(); i != instances_set.end(); ++i) { 266 if (strcmp((*i)->name(), s.c_str()) == 0) { 267 return **i; 268 } 269 } 270 cerr << "Internal error : get_module\n"; 271 exit(27); 272 } 273 274 275 template < typename T > static equi_list_t::iterator get_equi(T & e) { 276 entity2equi_it_t::iterator it = equi_map.find(entity(e)); 277 if (it == equi_map.end()) { 278 return equi_list.end(); 305 279 } 306 280 return it->second; 307 } 308 309 template<typename T> static 310 void 311 add_equi (equi_list_t::iterator &x, T &y) 312 { 281 } 282 283 284 template < typename T > static void add_equi(equi_list_t::iterator & x, T & y) { 313 285 entity e(y); 314 x->push_back 286 x->push_back(e); 315 287 equi_map[e] = x; 316 } 317 318 template<typename T> static 319 equi_list_t::iterator 320 new_equi (T &x) /* parameter is not 'const' because we need to modify pointer port/signal at end of elaboration step */ 321 { 322 equi_list_t::iterator it = equi_list.insert (equi_list.begin (),equi_t(1,entity(x))); 288 } 289 290 291 template < typename T > static 292 equi_list_t::iterator new_equi(T & x) { /* parameter is not 'const' because we need to modify pointer port/signal at end of elaboration step */ 293 equi_list_t::iterator it = equi_list.insert(equi_list.begin(), equi_t(1, entity(x))); 323 294 equi_map[entity(x)] = it; 324 295 return it; 325 } 326 327 // sort by number of connected ports bound to the signal 328 static 329 int 330 operator<(const equi_t &e1, const equi_t &e2) 331 { 332 return (e1.size() < e2.size ()); 333 } 334 335 // sort by data size 336 /* 337 int operator<(const equi_t &e1, const equi_t &e2) 338 { 339 return (e1.begin()->data_size () < e2.begin()->data_size ()); 340 } 341 */ 342 // random sort 343 /* 344 int operator<(const equi_t &e1, const equi_t &e2) 345 { 346 typedef std::map<const equi_t*,int> m_t; 347 static m_t m; 348 if (m[&e1] == 0) 349 m[&e1] = rand (); 350 if (m[&e2] == 0) 351 m[&e2] = rand (); 352 return m[&e1] < m[&e2]; 353 } 354 */ 355 void sort_equi_list () 356 { 357 //load (); 358 equi_list.sort (); 296 } 297 298 299 // sort by number of connected ports bound to the signal 300 static int operator <(const equi_t & e1, const equi_t & e2) { 301 return (e1.size() < e2.size()); 302 } 303 304 // sort by data size 305 /* 306 int operator<(const equi_t &e1, const equi_t &e2) 307 { 308 return (e1.begin()->data_size () < e2.begin()->data_size ()); 309 } 310 */ 311 // random sort 312 /* 313 int operator<(const equi_t &e1, const equi_t &e2) 314 { 315 typedef std::map<const equi_t*,int> m_t; 316 static m_t m; 317 if (m[&e1] == 0) 318 m[&e1] = rand (); 319 if (m[&e2] == 0) 320 m[&e2] = rand (); 321 return m[&e1] < m[&e2]; 322 } 323 */ 324 325 void sort_equi_list() { 326 //load (); 327 equi_list.sort(); 359 328 //equi_list.reverse (); 360 } 361 329 } 330 331 362 332 #if defined(DUMP_SIGNAL_STATS) 363 static unsigned int equi_real_size; 364 #endif 365 366 unsigned int 367 get_sizeof_signals_table () 368 { 333 static unsigned int equi_real_size; 334 #endif 335 336 unsigned int get_sizeof_signals_table() { 369 337 equi_list_t::iterator i; 370 338 int table_size = 0; 371 //cerr << "external table includes :\n"; 372 for (i = equi_list.begin (); i != equi_list.end (); ++i) { 373 if (get_out_port (*i)) 374 continue; 375 if (get_signal (*i)) 376 continue; 377 //cerr << get_name (*i) << " "; 378 const entity &ent = *(i->begin()); 379 int data_size = ent.data_size_in_bytes(); 380 int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; 381 table_size += number_of_part; 382 } 339 //cerr << "external table includes :\n"; 340 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 341 if (get_out_port(*i)) { 342 continue; 343 } 344 if (get_signal(*i)) { 345 continue; 346 } 347 //cerr << get_name (*i) << " "; 348 const entity & ent = *(i->begin()); 349 int data_size = ent.data_size_in_bytes(); 350 int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; 351 table_size += number_of_part; 352 } 383 353 return table_size; 384 } 385 386 void 387 create_signals_table () 388 { 389 if (dump_stage) 390 cerr << "Allocating signals table.\n"; 391 //cerr << "\n"; 392 unsigned int table_size = get_sizeof_signals_table (); 393 equi_table = new tab_t[table_size]; //(0xCD); 354 } 355 356 357 void create_signals_table() { 358 if (dump_stage) { 359 cerr << "Allocating signals table.\n"; 360 } 361 unsigned int table_size = get_sizeof_signals_table(); 362 equi_table = new tab_t[table_size]; //(0xCD); 394 363 #if defined(DUMP_SIGNAL_STATS) 395 364 equi_real_size = table_size; 396 365 #endif 397 366 #if defined(INIT_SIGNALS_TO_ZERO) 398 memset (equi_table, 0, sizeof(tab_t) * table_size);367 memset(equi_table, 0, sizeof(tab_t) * table_size); 399 368 #else 400 memset (equi_table, 0xCD, sizeof (tab_t) * table_size); 401 #endif 402 } 403 404 static 405 void 406 bind_equi_to_table (equi_t &e, tab_t * const pointer) 407 { 369 memset(equi_table, 0xCD, sizeof(tab_t) * table_size); 370 #endif 371 } 372 373 374 static void bind_equi_to_table(equi_t & e, tab_t * const pointer) { 408 375 assert(pointer != NULL); 409 376 equi_t::iterator i; 410 for (i = e.begin (); i != e.end(); ++i) {411 sc_interface *const inter = i->interface;412 inter->set_pointer(pointer);413 // We can't initialize data to zero there414 // because we can't write the right amount of bits.415 // It may produce some segmentation fault errors.416 // The pointer is aligned to 32 bits.417 } 418 419 420 void 421 bind_to_table () 422 {423 if (dump_stage)424 cerr << "Binding ports/signals to the table.\n";377 for (i = e.begin(); i != e.end(); ++i) { 378 sc_interface *const inter = i->interface; 379 inter->set_pointer(pointer); 380 // We can't initialize data to zero there 381 // because we can't write the right amount of bits. 382 // It may produce some segmentation fault errors. 383 // The pointer is aligned to 32 bits. 384 } 385 } 386 387 388 void bind_to_table() { 389 if (dump_stage) { 390 cerr << "Binding ports/signals to the table.\n"; 391 } 425 392 equi_list_t::iterator i; 426 393 int index = 0; 427 for (i = equi_list.begin (); i != equi_list.end (); ++i) { 428 sc_interface *out = get_out_port (*i); 429 if (out) { 430 bind_equi_to_table (*i, out->get_pointer ()); 431 } else { 432 sc_interface *reg = get_signal (*i); 433 if (reg == NULL) 434 reg = get_localvar (*i); 435 if (reg) { 436 bind_equi_to_table (*i, reg->get_pointer ()); 437 } else { 438 bind_equi_to_table (*i, &(equi_table[index])); 439 index += (i->begin()->data_size_in_bytes() - 1) / sizeof(tab_t) + 1; 440 } 441 } 442 } 443 } 444 445 ostream& 446 operator << (ostream &o, const entity &e) 447 { 394 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 395 sc_interface *out = get_out_port(*i); 396 if (out) { 397 bind_equi_to_table(*i, out->get_pointer()); 398 } 399 else { 400 sc_interface * reg = get_signal(*i); 401 if (reg == NULL) { 402 reg = get_localvar(*i); 403 } 404 if (reg) { 405 bind_equi_to_table(*i, reg->get_pointer()); 406 } 407 else { 408 bind_equi_to_table(*i, &(equi_table[index])); 409 index += (i->begin()->data_size_in_bytes() - 1) / sizeof(tab_t) + 1; 410 } 411 } 412 } 413 } 414 415 416 ostream & operator <<(ostream & o, const entity & e) { 448 417 #if 0 449 418 o << "entity ("; 450 419 if (e.object) 451 o << e.object->name();420 o << e.object->name(); 452 421 else 453 o << "no object";422 o << "no object"; 454 423 if (e.interface) 455 o << ", pointer = 0x" << hex << e.interface->get_pointer();424 o << ", pointer = 0x" << hex << e.interface->get_pointer(); 456 425 else 457 o << ", no interface";426 o << ", no interface"; 458 427 o << ")"; 459 428 #else 460 assert(e.object != NULL);461 o << e.object->name();429 assert(e.object != NULL); 430 o << e.object->name(); 462 431 #endif 463 432 return o; 464 } 465 466 ostream& 467 operator << (ostream &o, const equi_t &e) 468 { 433 } 434 435 ostream & operator <<(ostream & o, const equi_t & e) { 469 436 bool nb = 0; 470 437 equi_t::const_iterator i; 471 for (i = e.begin (); i != e.end(); ++i) {472 const entity &ity = *i;473 o << ((nb++)?" = ":"") << ity;474 } 438 for (i = e.begin(); i != e.end(); ++i) { 439 const entity & ity = *i; 440 o << ((nb++) ? " = " : "") << ity; 441 } 475 442 return o; 476 } 477 478 void 479 print_table (ostream &o) 480 { 481 o << "Signal list\n" 482 << "-----------\n"; 443 } 444 445 446 void print_table(ostream & o) { 447 o << "Signal list\n" << "-----------\n"; 483 448 equi_list_t::const_iterator i; 484 for (i = equi_list.begin (); i != equi_list.end(); ++i) {485 const equi_t &eq = *i;449 for (i = equi_list.begin(); i != equi_list.end(); ++i) { 450 const equi_t & eq = *i; 486 451 #if 0 487 o << i->begin()->interface->get_pointer() << " : ";488 489 452 o << i->begin()->interface->get_pointer() << " : "; 453 o << (*i); 454 o << "\n"; 490 455 #else 491 o << "(" << get_name (eq) << ") <=> " << eq << ".\n"; 492 #endif 493 } 494 } 495 496 void 497 print_table_stats (ostream &o) 498 { 456 o << "(" << get_name(eq) << ") <=> " << eq << ".\n"; 457 #endif 458 } 459 } 460 461 void print_table_stats(ostream & o) { 499 462 #if defined(DUMP_SIGNAL_STATS) 500 501 502 503 504 463 int nb_reg = 0; 464 int nb_sig = 0; 465 int real_size = 0; 466 467 // count 505 468 equi_list_t::const_iterator i; 506 int num; 507 for (num = 0, i = equi_list.begin (); i != equi_list.end (); ++num, ++i) { 508 if (is_register (*i)) 509 ++nb_reg; 510 else 511 ++nb_sig; 512 } 513 514 // print results 515 o << "Statistics :\n"; 516 o << "#registers : " << nb_reg << endl; 517 o << "#signals : " << nb_sig << endl; 518 o << "current table size : " << equi_real_size << endl; 519 #endif 520 } 469 int num; 470 for (num = 0, i = equi_list.begin(); i != equi_list.end(); ++num, ++i) { 471 if (is_register(*i)) { 472 ++nb_reg; 473 } 474 else { 475 ++nb_sig; 476 } 477 } 478 479 // print results 480 o << "Statistics :\n"; 481 o << "#registers : " << nb_reg << endl; 482 o << "#signals : " << nb_sig << endl; 483 o << "current table size : " << equi_real_size << endl; 484 #endif 485 } 486 521 487 522 488 #ifdef DUMP_SIGNAL_STATS 523 typedef map <tab_t*,long long int> counter_t;524 static counter_t 489 typedef map < tab_t *, long long int > counter_t; 490 static counter_t counter; 525 491 long long int unnecessary = 0; 526 492 long long int total_assig = 0; 527 493 #endif 528 494 529 const char* 530 get_module_name (const equi_t &eq) 531 { 532 if (!is_register (eq)) { 533 /* 534 cerr << "get_module_name doesn't work yet upon non-register.\n"; 535 536 const sc_port_base &port = *(i->port); 537 const sc_module &module = port.get_module (); 538 */ 539 return "top_level"; 540 } 541 const entity &ent = *(eq.begin ()); 495 const char * get_module_name(const equi_t & eq) { 496 if (!is_register(eq)) { 497 /* 498 cerr << "get_module_name doesn't work yet upon non-register.\n"; 499 */ 500 return "top_level"; 501 } 502 const entity & ent = *(eq.begin()); 503 542 504 #ifdef CONFIG_DEBUG 543 if (ent.type != sc_core::entity::SIGNAL) 544 exit(28); 545 #endif 546 // get module name from sc_signal used like a register 547 const char *sig_name = ent.object->name (); 548 const char *sep = strchr (sig_name,'.'); 505 if (ent.type != sc_core::entity::SIGNAL) { 506 exit(28); 507 } 508 #endif 509 510 // get module name from sc_signal used like a register 511 const char * sig_name = ent.object->name(); 512 const char * sep = strchr(sig_name, '.'); 513 549 514 #ifdef CONFIG_DEBUG 550 if (sep == NULL) { 551 exit (30); 552 } 553 #endif 554 int end_pos = sep - sig_name; 555 string module_name (sig_name, end_pos); 556 // can't return the char* pointer from string since it will be invalid. 557 return get_module (module_name).name (); 558 } 559 560 static 561 void 562 merge_equi (equi_list_t::iterator &x, equi_list_t::iterator &y) 563 { 564 equi_t::iterator i; 565 equi_t &y2 = *y; 566 for (i = y2.begin(); i != y2.end(); ++i) 567 { 568 entity &e = *i; 569 equi_map[e] = x; 570 } 571 572 x->merge (*y); 573 equi_list.erase (y); 574 } 575 515 if (sep == NULL) { 516 exit(30); 517 } 518 #endif 519 520 int end_pos = sep - sig_name; 521 string module_name(sig_name, end_pos); 522 // can't return the char* pointer from string since it will be invalid. 523 return get_module(module_name).name(); 524 } 525 526 527 static void merge_equi(equi_list_t::iterator & x, equi_list_t::iterator & y) { 528 equi_t::iterator i; 529 equi_t & y2 = *y; 530 for (i = y2.begin(); i != y2.end(); ++i) { 531 entity & e = *i; 532 equi_map[e] = x; 533 } 534 535 x->merge(*y); 536 equi_list.erase(y); 537 } 538 539 576 540 // sort by data size 577 541 #ifdef DATASIZE_SORT 578 int 579 operator<(const equi_t &e1, const equi_t &e2) 580 { 581 return (e1.begin()->data_size () < e2.begin()->data_size ()); 582 } 583 #endif 542 int operator< (const equi_t & e1, const equi_t & e2) { 543 return (e1.begin()->data_size() < e2.begin()->data_size()); 544 } 545 #endif 546 584 547 585 548 // random sort 586 549 #ifdef RANDOM_SORT 587 int 588 operator<(const equi_t &e1, const equi_t &e2) 589 { 590 typedef std::map<const equi_t*,int> m_t; 591 static m_t m; 592 if (m[&e1] == 0) 593 m[&e1] = rand (); 594 if (m[&e2] == 0) 595 m[&e2] = rand (); 596 return m[&e1] < m[&e2]; 597 } 598 #endif 550 int operator< (const equi_t & e1, const equi_t & e2) { 551 typedef std::map < const equi_t *, int > m_t; 552 static m_t m; 553 if (m[&e1] == 0) { 554 m[&e1] = rand(); 555 } 556 if (m[&e2] == 0) { 557 m[&e2] = rand(); 558 } 559 return m[&e1] < m[&e2]; 560 } 561 #endif 562 599 563 600 564 #if defined(DUMP_SIGNAL_STATS) … … 602 566 #endif 603 567 604 void 605 bind (sc_signal_base &x) 606 { 607 #if 0 608 //defined(CONFIG_DEBUG) 609 equi_list_t::iterator x_equi = get_equi (x); 610 if ((x_equi != equi_list.end())) { 611 cerr << "Internal error : Signal already in the table\n"; 612 return; 613 } 614 #endif 615 new_equi (x); 616 } 617 618 void 619 bind (sc_port_base &x) 620 { 621 new_equi (x); 622 } 623 624 template <typename T> static 625 void 626 test_before_bind (sc_port_base& p1,T& p2) 627 { 628 bool t1 = (p1.kind () != NULL); 629 bool t2 = (p2.kind () != NULL); 630 if (t1 && t2) 631 return; 632 if (t1 == true) 633 cerr << "Trying to bind '" << p1.name() << "' to an unknown type.\n"; 634 else if (t2 == true) 635 cerr << "Trying to bind '" << p2.name() << "' to an unknown type.\n"; 636 else 637 cerr << "Binding failed. Please check the netlist description.\n"; 638 exit (20040525); 639 } 640 641 template <typename T> static 642 void 643 tbind (sc_port_base &x,T &y) 644 { 645 // assert(x.get_pointer () != NULL); // x pointer may be NULL 646 // assert(y.get_pointer () != NULL); // y pointer may be NULL 647 equi_list_t::iterator x_equi = get_equi (x); 648 equi_list_t::iterator y_equi = get_equi (y); 649 if ((x_equi != equi_list.end()) && (y_equi != equi_list.end())) { 650 // 2 equipotentials are equals 651 merge_equi (x_equi, y_equi); 652 } else if ((x_equi != equi_list.end())) { 653 // add y 654 add_equi (x_equi,y); 655 } else if ((y_equi != equi_list.end())) { 656 // add y 657 add_equi (y_equi,x); 658 } else { 659 // add a new equi 660 x_equi = new_equi (x); 661 add_equi (x_equi, y); 662 } 663 } 664 665 void 666 bind (sc_port_base& p1,sc_port_base& p2) 667 { test_before_bind (p1, p2); tbind (p1, p2); } 668 669 void 670 bind (sc_port_base& p1,sc_signal_base& s1) 671 { test_before_bind (p1, s1); tbind (p1, s1); } 568 569 void bind(sc_signal_base & x) { 570 #if 0 571 //defined(CONFIG_DEBUG) 572 equi_list_t::iterator x_equi = get_equi(x); 573 if ((x_equi != equi_list.end())) { 574 cerr << "Internal error : Signal already in the table\n"; 575 return; 576 } 577 #endif 578 new_equi(x); 579 } 580 581 582 void bind(sc_port_base & x) { 583 new_equi(x); 584 } 585 586 587 template < typename T > static void test_before_bind(sc_port_base & p1, T & p2) { 588 bool t1 = (p1.kind() != NULL); 589 bool t2 = (p2.kind() != NULL); 590 if (t1 && t2) { 591 return; 592 } 593 if (t1 == true) { 594 cerr << "Trying to bind '" << p1.name() << "' to an unknown type.\n"; 595 } 596 else if (t2 == true) { 597 cerr << "Trying to bind '" << p2.name() << "' to an unknown type.\n"; 598 } 599 else { 600 cerr << "Binding failed. Please check the netlist description.\n"; 601 } 602 exit(20040525); 603 } 604 605 606 template < typename T > static void tbind(sc_port_base & x, T & y) { 607 // assert(x.get_pointer () != NULL); // x pointer may be NULL 608 // assert(y.get_pointer () != NULL); // y pointer may be NULL 609 equi_list_t::iterator x_equi = get_equi(x); 610 equi_list_t::iterator y_equi = get_equi(y); 611 if ((x_equi != equi_list.end()) && (y_equi != equi_list.end())) { 612 // 2 equipotentials are equals 613 merge_equi(x_equi, y_equi); 614 } 615 else if ((x_equi != equi_list.end())) { 616 // add y 617 add_equi(x_equi, y); 618 } 619 else if ((y_equi != equi_list.end())) { 620 // add y 621 add_equi(y_equi, x); 622 } 623 else { 624 // add a new equi 625 x_equi = new_equi(x); 626 add_equi(x_equi, y); 627 } 628 } 629 630 631 void bind(sc_port_base & p1, sc_port_base & p2) { 632 test_before_bind(p1, p2); 633 tbind(p1, p2); 634 } 635 636 637 void bind(sc_port_base & p1, sc_signal_base & s1) { 638 test_before_bind(p1, s1); 639 tbind(p1, s1); 640 } 672 641 673 642 674 643 } // end of sc_core namespace 675 644 645 /* 646 # Local Variables: 647 # tab-width: 4; 648 # c-basic-offset: 4; 649 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 650 # indent-tabs-mode: nil; 651 # End: 652 # 653 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 654 */ 655
Note: See TracChangeset
for help on using the changeset viewer.