[1] | 1 | /*------------------------------------------------------------\ |
---|
[52] | 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 | \------------------------------------------------------------*/ |
---|
[1] | 13 | |
---|
| 14 | /* |
---|
| 15 | * This file is part of the Disydent Project |
---|
| 16 | * Copyright (C) Laboratoire LIP6 - Département ASIM |
---|
| 17 | * Universite Pierre et Marie Curie |
---|
| 18 | * |
---|
| 19 | * Home page : http://www-asim.lip6.fr/disydent |
---|
| 20 | * E-mail : mailto:richard.buchmann@lip6.fr |
---|
| 21 | * |
---|
| 22 | * This library is free software; you can redistribute it and/or modify it |
---|
| 23 | * under the terms of the GNU Library General Public License as published |
---|
| 24 | * by the Free Software Foundation; either version 2 of the License, or (at |
---|
| 25 | * your option) any later version. |
---|
| 26 | * |
---|
| 27 | * Disydent is distributed in the hope that it will be |
---|
| 28 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 30 | * Public License for more details. |
---|
| 31 | * |
---|
| 32 | * You should have received a copy of the GNU General Public License along |
---|
| 33 | * with the GNU C Library; see the file COPYING. If not, write to the Free |
---|
| 34 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 35 | */ |
---|
| 36 | |
---|
[27] | 37 | #include <cstring> |
---|
| 38 | #include <iomanip> |
---|
| 39 | #include <list> |
---|
| 40 | #include <map> |
---|
| 41 | #include <vector> |
---|
[52] | 42 | #include <cassert> |
---|
[1] | 43 | |
---|
[27] | 44 | #include "entity.h" |
---|
| 45 | #include "sc_port.h" |
---|
| 46 | #include "sc_signal.h" |
---|
| 47 | #include "sc_module.h" |
---|
[52] | 48 | |
---|
[27] | 49 | #ifdef HAVE_CONFIG_H |
---|
| 50 | #include "config.h" |
---|
| 51 | #endif |
---|
[1] | 52 | |
---|
| 53 | using namespace std; |
---|
| 54 | |
---|
| 55 | namespace sc_core { |
---|
| 56 | |
---|
[52] | 57 | equi_list_t equi_list; |
---|
| 58 | equi_table_t equi_table = NULL; |
---|
[1] | 59 | |
---|
[52] | 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; |
---|
[1] | 66 | } |
---|
[52] | 67 | }; |
---|
[1] | 68 | |
---|
[52] | 69 | typedef std::map <entity, equi_list_t::iterator, predic4entity2equi_t_t> entity2equi_it_t; |
---|
[1] | 70 | |
---|
[52] | 71 | |
---|
| 72 | ostream & operator << (ostream & o, const entity2equi_it_t & m) { |
---|
[1] | 73 | entity2equi_it_t::const_iterator i; |
---|
[52] | 74 | for (i = m.begin(); i != m.end(); ++i) { |
---|
| 75 | o << (i->first) << " : " << *(i->second) << "\n"; |
---|
[1] | 76 | } |
---|
| 77 | return o; |
---|
[52] | 78 | } |
---|
| 79 | |
---|
| 80 | entity2equi_it_t equi_map; |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | const equi_list_t & get_equi_list() { |
---|
[1] | 84 | return equi_list; |
---|
[52] | 85 | } |
---|
[1] | 86 | |
---|
| 87 | |
---|
[52] | 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 |
---|
[1] | 95 | equi_list_t::const_iterator i; |
---|
| 96 | int capacity = 0; |
---|
[52] | 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; |
---|
[1] | 103 | } |
---|
| 104 | return capacity; |
---|
[52] | 105 | } |
---|
[1] | 106 | |
---|
| 107 | |
---|
[52] | 108 | int get_signal_table_size() { |
---|
| 109 | return get_signal_table_size(equi_list); |
---|
| 110 | } |
---|
[1] | 111 | |
---|
| 112 | |
---|
[52] | 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 | } |
---|
[1] | 123 | |
---|
[59] | 124 | static sc_port_base * get_localvar(equi_t & eq) { |
---|
[52] | 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 | } |
---|
[1] | 131 | } |
---|
[52] | 132 | return NULL; |
---|
| 133 | } |
---|
[1] | 134 | |
---|
[52] | 135 | |
---|
[59] | 136 | static sc_port_base * get_signal(equi_t & eq) { |
---|
[52] | 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 | |
---|
| 159 | |
---|
[1] | 160 | #define get_equi_SPEEDUP |
---|
[52] | 161 | equi_t & get_equi(const tab_t * pointer) { |
---|
[1] | 162 | // result variable |
---|
[52] | 163 | equi_list_t::iterator i; |
---|
[1] | 164 | #if defined(get_equi_SPEEDUP) |
---|
[52] | 165 | typedef std::map <const tab_t *, equi_list_t::iterator, predic4tab_t2equi_t_t> tab_t2equi_it_t; |
---|
[1] | 166 | static tab_t2equi_it_t tab2equi_map; |
---|
[27] | 167 | assert(pointer != NULL); |
---|
[1] | 168 | |
---|
[52] | 169 | tab_t2equi_it_t:: /*const_ */ iterator it = tab2equi_map.find(pointer); |
---|
| 170 | if (it != tab2equi_map.end()) { |
---|
| 171 | i = it->second; |
---|
| 172 | return *i; |
---|
[1] | 173 | } |
---|
| 174 | #endif |
---|
[52] | 175 | |
---|
| 176 | |
---|
| 177 | for (i = equi_list.begin(); i != equi_list.end(); ++i) { |
---|
| 178 | const equi_t::iterator & j = i->begin(); |
---|
| 179 | const entity & e = *j; |
---|
| 180 | const sc_interface * f = e.interface; |
---|
| 181 | const tab_t * p = f->get_pointer(); |
---|
| 182 | if (p == pointer) { |
---|
[1] | 183 | #if defined(get_equi_SPEEDUP) |
---|
[52] | 184 | tab2equi_map[pointer] = i; |
---|
[1] | 185 | #endif |
---|
[52] | 186 | return *i; |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | cerr << "Internal error : get_equi(" << pointer << ")\n"; |
---|
[60] | 190 | abort(); |
---|
[52] | 191 | exit(11); |
---|
| 192 | } |
---|
[1] | 193 | #undef get_equi_SPEEDUP |
---|
| 194 | |
---|
[52] | 195 | |
---|
| 196 | bool has_equi( /*const */ sc_port_base & port) { |
---|
[1] | 197 | entity e(port); |
---|
[52] | 198 | entity2equi_it_t::/*const_ */iterator it = equi_map.find(e); |
---|
| 199 | if (it == equi_map.end()) { |
---|
| 200 | return false; |
---|
[1] | 201 | } |
---|
| 202 | return true; |
---|
[52] | 203 | } |
---|
[1] | 204 | |
---|
[52] | 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(); |
---|
[27] | 224 | #ifdef CONFIG_DEBUG |
---|
[52] | 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 | } |
---|
[1] | 240 | #endif |
---|
[52] | 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 | } |
---|
[1] | 250 | #if 0 |
---|
[52] | 251 | cerr << "get_name of " << e; |
---|
| 252 | cerr << " return " << top_iter->object->name() << endl; |
---|
[1] | 253 | #endif |
---|
[52] | 254 | return top_iter->object->name(); |
---|
| 255 | } |
---|
[1] | 256 | |
---|
[52] | 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 | } |
---|
[1] | 269 | } |
---|
[52] | 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) { |
---|
[59] | 276 | // QM debug |
---|
| 277 | //cout << "equi_map : " << equi_map << endl; |
---|
| 278 | |
---|
[52] | 279 | entity2equi_it_t::iterator it = equi_map.find(entity(e)); |
---|
| 280 | if (it == equi_map.end()) { |
---|
| 281 | return equi_list.end(); |
---|
| 282 | } |
---|
[1] | 283 | return it->second; |
---|
[52] | 284 | } |
---|
[1] | 285 | |
---|
[52] | 286 | |
---|
| 287 | template < typename T > static void add_equi(equi_list_t::iterator & x, T & y) { |
---|
[1] | 288 | entity e(y); |
---|
[52] | 289 | x->push_back(e); |
---|
[1] | 290 | equi_map[e] = x; |
---|
[52] | 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | template < typename T > static |
---|
| 295 | 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 */ |
---|
| 296 | equi_list_t::iterator it = equi_list.insert(equi_list.begin(), equi_t(1, entity(x))); |
---|
[1] | 297 | equi_map[entity(x)] = it; |
---|
| 298 | return it; |
---|
[52] | 299 | } |
---|
[1] | 300 | |
---|
| 301 | |
---|
[52] | 302 | // sort by number of connected ports bound to the signal |
---|
| 303 | static int operator <(const equi_t & e1, const equi_t & e2) { |
---|
| 304 | return (e1.size() < e2.size()); |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | // sort by data size |
---|
| 308 | /* |
---|
| 309 | int operator<(const equi_t &e1, const equi_t &e2) |
---|
| 310 | { |
---|
| 311 | return (e1.begin()->data_size () < e2.begin()->data_size ()); |
---|
| 312 | } |
---|
| 313 | */ |
---|
| 314 | // random sort |
---|
| 315 | /* |
---|
| 316 | int operator<(const equi_t &e1, const equi_t &e2) |
---|
| 317 | { |
---|
| 318 | typedef std::map<const equi_t*,int> m_t; |
---|
| 319 | static m_t m; |
---|
| 320 | if (m[&e1] == 0) |
---|
| 321 | m[&e1] = rand (); |
---|
| 322 | if (m[&e2] == 0) |
---|
| 323 | m[&e2] = rand (); |
---|
| 324 | return m[&e1] < m[&e2]; |
---|
| 325 | } |
---|
| 326 | */ |
---|
| 327 | |
---|
| 328 | void sort_equi_list() { |
---|
| 329 | //load (); |
---|
| 330 | equi_list.sort(); |
---|
[1] | 331 | //equi_list.reverse (); |
---|
[52] | 332 | } |
---|
| 333 | |
---|
| 334 | |
---|
[27] | 335 | #if defined(DUMP_SIGNAL_STATS) |
---|
[52] | 336 | static unsigned int equi_real_size; |
---|
[1] | 337 | #endif |
---|
| 338 | |
---|
[52] | 339 | unsigned int get_sizeof_signals_table() { |
---|
[1] | 340 | equi_list_t::iterator i; |
---|
| 341 | int table_size = 0; |
---|
[52] | 342 | //cerr << "external table includes :\n"; |
---|
| 343 | for (i = equi_list.begin(); i != equi_list.end(); ++i) { |
---|
| 344 | if (get_out_port(*i)) { |
---|
| 345 | continue; |
---|
| 346 | } |
---|
| 347 | if (get_signal(*i)) { |
---|
| 348 | continue; |
---|
| 349 | } |
---|
| 350 | //cerr << get_name (*i) << " "; |
---|
| 351 | const entity & ent = *(i->begin()); |
---|
| 352 | int data_size = ent.data_size_in_bytes(); |
---|
| 353 | int number_of_part = ((data_size - 1) / sizeof(tab_t)) + 1; |
---|
| 354 | table_size += number_of_part; |
---|
| 355 | } |
---|
[1] | 356 | return table_size; |
---|
[52] | 357 | } |
---|
[1] | 358 | |
---|
[52] | 359 | |
---|
| 360 | void create_signals_table() { |
---|
| 361 | if (dump_stage) { |
---|
| 362 | cerr << "Allocating signals table.\n"; |
---|
| 363 | } |
---|
| 364 | unsigned int table_size = get_sizeof_signals_table(); |
---|
| 365 | equi_table = new tab_t[table_size]; //(0xCD); |
---|
[27] | 366 | #if defined(DUMP_SIGNAL_STATS) |
---|
[52] | 367 | equi_real_size = table_size; |
---|
[1] | 368 | #endif |
---|
| 369 | #if defined(INIT_SIGNALS_TO_ZERO) |
---|
[52] | 370 | memset(equi_table, 0, sizeof(tab_t) * table_size); |
---|
[1] | 371 | #else |
---|
[52] | 372 | memset(equi_table, 0xCD, sizeof(tab_t) * table_size); |
---|
[1] | 373 | #endif |
---|
[52] | 374 | } |
---|
[1] | 375 | |
---|
[52] | 376 | |
---|
| 377 | static void bind_equi_to_table(equi_t & e, tab_t * const pointer) { |
---|
[27] | 378 | assert(pointer != NULL); |
---|
[1] | 379 | equi_t::iterator i; |
---|
[52] | 380 | for (i = e.begin(); i != e.end(); ++i) { |
---|
| 381 | sc_interface *const inter = i->interface; |
---|
| 382 | inter->set_pointer(pointer); |
---|
| 383 | // We can't initialize data to zero there |
---|
| 384 | // because we can't write the right amount of bits. |
---|
| 385 | // It may produce some segmentation fault errors. |
---|
| 386 | // The pointer is aligned to 32 bits. |
---|
[1] | 387 | } |
---|
[52] | 388 | } |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | void bind_to_table() { |
---|
| 392 | if (dump_stage) { |
---|
| 393 | cerr << "Binding ports/signals to the table.\n"; |
---|
| 394 | } |
---|
[1] | 395 | equi_list_t::iterator i; |
---|
| 396 | int index = 0; |
---|
[65] | 397 | for (i = equi_list.begin (); i != equi_list.end (); ++i) { |
---|
| 398 | #if 1 |
---|
| 399 | sc_interface *out = get_out_port (*i); |
---|
| 400 | if (out) { |
---|
| 401 | bind_equi_to_table (*i, out->get_pointer ()); |
---|
| 402 | } else { |
---|
| 403 | sc_interface *reg = get_signal (*i); |
---|
| 404 | if (reg == NULL) |
---|
| 405 | reg = get_localvar (*i); |
---|
| 406 | if (reg) { |
---|
| 407 | bind_equi_to_table (*i, reg->get_pointer ()); |
---|
| 408 | } else { |
---|
| 409 | bind_equi_to_table (*i, &(equi_table[index])); |
---|
| 410 | index += (i->begin()->data_size_in_bytes() - 1) / sizeof(tab_t) + 1; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | #else |
---|
| 414 | sc_interface *reg = get_signal (*i); |
---|
| 415 | sc_interface *out = get_out_port (*i); |
---|
| 416 | if (reg) { |
---|
| 417 | std::cerr << "binding " << *i << " to reg " |
---|
| 418 | << reg << std::endl; |
---|
| 419 | bind_equi_to_table (*i, reg->get_pointer ()); |
---|
| 420 | } else if (out) { |
---|
| 421 | std::cerr << "binding " << *i << " to out " |
---|
| 422 | << out << std::endl; |
---|
| 423 | bind_equi_to_table (*i, out->get_pointer ()); |
---|
| 424 | } else { |
---|
| 425 | reg = get_localvar (*i); |
---|
| 426 | if (reg) { |
---|
| 427 | std::cerr << "binding " << *i << " to localvar " |
---|
| 428 | << reg << std::endl; |
---|
| 429 | bind_equi_to_table (*i, reg->get_pointer ()); |
---|
| 430 | } else { |
---|
| 431 | std::cerr << "binding " << *i << " to index " |
---|
| 432 | << index << std::endl; |
---|
| 433 | bind_equi_to_table (*i, &(equi_table[index])); |
---|
| 434 | index += (i->begin()->data_size_in_bytes() - 1) / sizeof(tab_t) + 1; |
---|
| 435 | } |
---|
| 436 | } |
---|
[60] | 437 | #endif |
---|
[1] | 438 | } |
---|
[52] | 439 | } |
---|
[1] | 440 | |
---|
[52] | 441 | |
---|
| 442 | ostream & operator <<(ostream & o, const entity & e) { |
---|
[1] | 443 | #if 0 |
---|
| 444 | o << "entity ("; |
---|
| 445 | if (e.object) |
---|
[52] | 446 | o << e.object->name(); |
---|
[1] | 447 | else |
---|
[52] | 448 | o << "no object"; |
---|
[1] | 449 | if (e.interface) |
---|
[52] | 450 | o << ", pointer = 0x" << hex << e.interface->get_pointer(); |
---|
[1] | 451 | else |
---|
[52] | 452 | o << ", no interface"; |
---|
[1] | 453 | o << ")"; |
---|
| 454 | #else |
---|
[52] | 455 | assert(e.object != NULL); |
---|
| 456 | o << e.object->name(); |
---|
[1] | 457 | #endif |
---|
| 458 | return o; |
---|
[52] | 459 | } |
---|
| 460 | |
---|
| 461 | ostream & operator <<(ostream & o, const equi_t & e) { |
---|
[1] | 462 | bool nb = 0; |
---|
| 463 | equi_t::const_iterator i; |
---|
[52] | 464 | for (i = e.begin(); i != e.end(); ++i) { |
---|
| 465 | const entity & ity = *i; |
---|
| 466 | o << ((nb++) ? " = " : "") << ity; |
---|
| 467 | } |
---|
[1] | 468 | return o; |
---|
[52] | 469 | } |
---|
| 470 | |
---|
| 471 | |
---|
| 472 | void print_table(ostream & o) { |
---|
| 473 | o << "Signal list\n" << "-----------\n"; |
---|
[1] | 474 | equi_list_t::const_iterator i; |
---|
[52] | 475 | for (i = equi_list.begin(); i != equi_list.end(); ++i) { |
---|
| 476 | const equi_t & eq = *i; |
---|
[1] | 477 | #if 0 |
---|
[52] | 478 | o << i->begin()->interface->get_pointer() << " : "; |
---|
| 479 | o << (*i); |
---|
| 480 | o << "\n"; |
---|
[1] | 481 | #else |
---|
[52] | 482 | o << "(" << get_name(eq) << ") <=> " << eq << ".\n"; |
---|
[1] | 483 | #endif |
---|
| 484 | } |
---|
[52] | 485 | } |
---|
[1] | 486 | |
---|
[52] | 487 | void print_table_stats(ostream & o) { |
---|
[27] | 488 | #if defined(DUMP_SIGNAL_STATS) |
---|
[52] | 489 | int nb_reg = 0; |
---|
| 490 | int nb_sig = 0; |
---|
| 491 | int real_size = 0; |
---|
| 492 | |
---|
| 493 | // count |
---|
[1] | 494 | equi_list_t::const_iterator i; |
---|
[52] | 495 | int num; |
---|
| 496 | for (num = 0, i = equi_list.begin(); i != equi_list.end(); ++num, ++i) { |
---|
| 497 | if (is_register(*i)) { |
---|
| 498 | ++nb_reg; |
---|
| 499 | } |
---|
| 500 | else { |
---|
| 501 | ++nb_sig; |
---|
| 502 | } |
---|
[1] | 503 | } |
---|
[52] | 504 | |
---|
| 505 | // print results |
---|
| 506 | o << "Statistics :\n"; |
---|
| 507 | o << "#registers : " << nb_reg << endl; |
---|
| 508 | o << "#signals : " << nb_sig << endl; |
---|
| 509 | o << "current table size : " << equi_real_size << endl; |
---|
[1] | 510 | #endif |
---|
[52] | 511 | } |
---|
[1] | 512 | |
---|
[52] | 513 | |
---|
[1] | 514 | #ifdef DUMP_SIGNAL_STATS |
---|
[52] | 515 | typedef map < tab_t *, long long int > counter_t; |
---|
| 516 | static counter_t counter; |
---|
[1] | 517 | long long int unnecessary = 0; |
---|
| 518 | long long int total_assig = 0; |
---|
| 519 | #endif |
---|
| 520 | |
---|
[52] | 521 | const char * get_module_name(const equi_t & eq) { |
---|
| 522 | if (!is_register(eq)) { |
---|
| 523 | /* |
---|
| 524 | cerr << "get_module_name doesn't work yet upon non-register.\n"; |
---|
| 525 | */ |
---|
| 526 | return "top_level"; |
---|
| 527 | } |
---|
| 528 | const entity & ent = *(eq.begin()); |
---|
| 529 | |
---|
[27] | 530 | #ifdef CONFIG_DEBUG |
---|
[52] | 531 | if (ent.type != sc_core::entity::SIGNAL) { |
---|
| 532 | exit(28); |
---|
| 533 | } |
---|
[1] | 534 | #endif |
---|
[52] | 535 | |
---|
| 536 | // get module name from sc_signal used like a register |
---|
| 537 | const char * sig_name = ent.object->name(); |
---|
| 538 | const char * sep = strchr(sig_name, '.'); |
---|
| 539 | |
---|
[27] | 540 | #ifdef CONFIG_DEBUG |
---|
[52] | 541 | if (sep == NULL) { |
---|
| 542 | exit(30); |
---|
| 543 | } |
---|
[1] | 544 | #endif |
---|
[52] | 545 | |
---|
| 546 | int end_pos = sep - sig_name; |
---|
| 547 | string module_name(sig_name, end_pos); |
---|
| 548 | // can't return the char* pointer from string since it will be invalid. |
---|
| 549 | return get_module(module_name).name(); |
---|
[1] | 550 | } |
---|
| 551 | |
---|
| 552 | |
---|
[52] | 553 | static void merge_equi(equi_list_t::iterator & x, equi_list_t::iterator & y) { |
---|
| 554 | equi_t::iterator i; |
---|
| 555 | equi_t & y2 = *y; |
---|
| 556 | for (i = y2.begin(); i != y2.end(); ++i) { |
---|
| 557 | entity & e = *i; |
---|
| 558 | equi_map[e] = x; |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | x->merge(*y); |
---|
| 562 | equi_list.erase(y); |
---|
[1] | 563 | } |
---|
[52] | 564 | |
---|
| 565 | |
---|
[1] | 566 | // sort by data size |
---|
| 567 | #ifdef DATASIZE_SORT |
---|
[52] | 568 | int operator< (const equi_t & e1, const equi_t & e2) { |
---|
| 569 | return (e1.begin()->data_size() < e2.begin()->data_size()); |
---|
[1] | 570 | } |
---|
| 571 | #endif |
---|
| 572 | |
---|
[52] | 573 | |
---|
[1] | 574 | // random sort |
---|
| 575 | #ifdef RANDOM_SORT |
---|
[52] | 576 | int operator< (const equi_t & e1, const equi_t & e2) { |
---|
| 577 | typedef std::map < const equi_t *, int > m_t; |
---|
| 578 | static m_t m; |
---|
| 579 | if (m[&e1] == 0) { |
---|
| 580 | m[&e1] = rand(); |
---|
| 581 | } |
---|
| 582 | if (m[&e2] == 0) { |
---|
| 583 | m[&e2] = rand(); |
---|
| 584 | } |
---|
| 585 | return m[&e1] < m[&e2]; |
---|
[1] | 586 | } |
---|
| 587 | #endif |
---|
| 588 | |
---|
[52] | 589 | |
---|
[27] | 590 | #if defined(DUMP_SIGNAL_STATS) |
---|
[1] | 591 | static unsigned int equi_real_size; |
---|
| 592 | #endif |
---|
| 593 | |
---|
[52] | 594 | |
---|
| 595 | void bind(sc_signal_base & x) { |
---|
| 596 | #if 0 |
---|
| 597 | //defined(CONFIG_DEBUG) |
---|
| 598 | equi_list_t::iterator x_equi = get_equi(x); |
---|
| 599 | if ((x_equi != equi_list.end())) { |
---|
| 600 | cerr << "Internal error : Signal already in the table\n"; |
---|
| 601 | return; |
---|
| 602 | } |
---|
[1] | 603 | #endif |
---|
[52] | 604 | new_equi(x); |
---|
[1] | 605 | } |
---|
| 606 | |
---|
[52] | 607 | |
---|
| 608 | void bind(sc_port_base & x) { |
---|
| 609 | new_equi(x); |
---|
[1] | 610 | } |
---|
| 611 | |
---|
[52] | 612 | |
---|
| 613 | template < typename T > static void test_before_bind(sc_port_base & p1, T & p2) { |
---|
| 614 | bool t1 = (p1.kind() != NULL); |
---|
| 615 | bool t2 = (p2.kind() != NULL); |
---|
| 616 | if (t1 && t2) { |
---|
| 617 | return; |
---|
| 618 | } |
---|
| 619 | if (t1 == true) { |
---|
| 620 | cerr << "Trying to bind '" << p1.name() << "' to an unknown type.\n"; |
---|
| 621 | } |
---|
| 622 | else if (t2 == true) { |
---|
| 623 | cerr << "Trying to bind '" << p2.name() << "' to an unknown type.\n"; |
---|
| 624 | } |
---|
| 625 | else { |
---|
| 626 | cerr << "Binding failed. Please check the netlist description.\n"; |
---|
| 627 | } |
---|
| 628 | exit(20040525); |
---|
[1] | 629 | } |
---|
| 630 | |
---|
[52] | 631 | |
---|
| 632 | template < typename T > static void tbind(sc_port_base & x, T & y) { |
---|
| 633 | // assert(x.get_pointer () != NULL); // x pointer may be NULL |
---|
| 634 | // assert(y.get_pointer () != NULL); // y pointer may be NULL |
---|
| 635 | equi_list_t::iterator x_equi = get_equi(x); |
---|
| 636 | equi_list_t::iterator y_equi = get_equi(y); |
---|
| 637 | if ((x_equi != equi_list.end()) && (y_equi != equi_list.end())) { |
---|
| 638 | // 2 equipotentials are equals |
---|
| 639 | merge_equi(x_equi, y_equi); |
---|
| 640 | } |
---|
| 641 | else if ((x_equi != equi_list.end())) { |
---|
| 642 | // add y |
---|
| 643 | add_equi(x_equi, y); |
---|
| 644 | } |
---|
| 645 | else if ((y_equi != equi_list.end())) { |
---|
| 646 | // add y |
---|
| 647 | add_equi(y_equi, x); |
---|
| 648 | } |
---|
| 649 | else { |
---|
| 650 | // add a new equi |
---|
| 651 | x_equi = new_equi(x); |
---|
| 652 | add_equi(x_equi, y); |
---|
| 653 | } |
---|
[1] | 654 | } |
---|
| 655 | |
---|
| 656 | |
---|
[52] | 657 | void bind(sc_port_base & p1, sc_port_base & p2) { |
---|
| 658 | test_before_bind(p1, p2); |
---|
| 659 | tbind(p1, p2); |
---|
| 660 | } |
---|
[1] | 661 | |
---|
| 662 | |
---|
[52] | 663 | void bind(sc_port_base & p1, sc_signal_base & s1) { |
---|
| 664 | test_before_bind(p1, s1); |
---|
| 665 | tbind(p1, s1); |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | |
---|
[1] | 669 | } // end of sc_core namespace |
---|
| 670 | |
---|
[52] | 671 | /* |
---|
| 672 | # Local Variables: |
---|
| 673 | # tab-width: 4; |
---|
| 674 | # c-basic-offset: 4; |
---|
| 675 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 676 | # indent-tabs-mode: nil; |
---|
| 677 | # End: |
---|
| 678 | # |
---|
| 679 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 680 | */ |
---|
| 681 | |
---|