Changeset 52 for sources/src/global_functions.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/global_functions.cc
r47 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : global_functions.cc |6 | |7 | Author : Buchmann Richard |8 | Nicolas Pouillon |9 | |10 | Date : 21_09_2005 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : global_functions.cc | 6 | | 7 | Author : Buchmann Richard | 8 | Nicolas Pouillon | 9 | | 10 | Date : 21_09_2005 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 38 38 #include <iostream> 39 39 #include <dlfcn.h> 40 #include "schedulers.h" // get_scheduling & run_schedule_editor 41 #include "sc_module.h" // check_all_method_process 42 #include "gen_code.h" // gen_scheduling_code_for_dynamic_link & gen_scheduling_code_for_static_func 40 41 #include "schedulers.h" // get_scheduling & run_schedule_editor 42 #include "sc_module.h" // check_all_method_process 43 #include "gen_code.h" // gen_scheduling_code_for_dynamic_link & gen_scheduling_code_for_static_func 43 44 #include "sc_clock_ext.h" // clock list 44 45 #include "usage.h" 45 46 #include "module_hierarchy2dot.h" 46 47 #include "assert.h" 48 47 49 #ifdef HAVE_CONFIG_H 48 50 #include "config.h" … … 53 55 namespace sc_core { 54 56 55 const char * temporary_dir = "/tmp";56 const char * generated_files_dir = "./generated_by_systemcass";57 const char * temporary_dir = "/tmp"; 58 const char * generated_files_dir = "./generated_by_systemcass"; 57 59 58 60 static usage_t usage; … … 62 64 /* ***************************** */ 63 65 64 template <typename T> 65 ostream& operator << (ostream &o, const vector<T*> &v) 66 { 67 typename vector<T*>::const_iterator i; 68 for (i = v.begin(); i != v.end(); ++i) { 69 o << **i << " "; 70 } 71 return o; 66 template < typename T > ostream & operator <<(ostream & o, const vector < T * > & v) { 67 typename vector < T * >::const_iterator i; 68 for (i = v.begin(); i != v.end(); ++i) { 69 o << **i << " "; 70 } return o; 72 71 } 73 72 … … 76 75 /****************/ 77 76 78 typedef std::set<const sc_clock*> clock_list_t; 79 80 ostream& 81 operator << (ostream &o, 82 const clock_list_t &cl) 83 { 84 clock_list_t::const_iterator i; 85 for (i = cl.begin(); i != cl.end(); ++i) { 86 o << (*i)->name () << " "; 87 } 88 return o; 89 } 77 typedef std::set<const sc_clock *> clock_list_t; 78 79 ostream & operator <<(ostream & o, const clock_list_t & cl) { 80 clock_list_t::const_iterator i; 81 for (i = cl.begin(); i != cl.end(); ++i) { 82 o << (*i)->name() << " "; 83 } 84 return o; 85 } 86 90 87 91 88 // clock list 92 void 93 create_clock_list (clock_list_t &c, 94 const equi_list_t &el) 95 { 96 equi_list_t::const_iterator i; 97 for (i = el.begin (); i != el.end(); ++i) { 98 equi_t::const_iterator j; 99 for (j = i->begin (); j != i->end (); ++j) { 100 if (j->kind () == sc_clock::kind_string) 101 c.insert ((const sc_clock*)j->object); 102 } 103 } 89 void create_clock_list(clock_list_t & c, const equi_list_t & el) { 90 equi_list_t::const_iterator i; 91 for (i = el.begin(); i != el.end(); ++i) { 92 equi_t::const_iterator j; 93 for (j = i->begin(); j != i->end(); ++j) { 94 if (j->kind() == sc_clock::kind_string) 95 c.insert((const sc_clock *) j->object); 96 } 97 } 104 98 } 105 99 … … 116 110 /* ************ */ 117 111 118 static void *handle = NULL; 119 120 static 121 void 122 link (const char *lib) 123 { 124 // chargement du code de simulate_1_cycle 125 handle = dlopen(lib, RTLD_GLOBAL | RTLD_NOW); 126 //handle = dlopen(lib, RTLD_LAZY | RTLD_GLOBAL | RTLD_NOW); 127 128 if (handle == NULL) { 129 const char *error = dlerror (); 130 if (error) 131 fprintf (stderr, "dlopen: %s\n",error); 132 fprintf (stderr, 133 "Is there -rdynamic option into your command line ? " 134 "If not, please do it.\n"); 135 exit(18); 136 } 137 138 union uni_fct_t { 139 evaluation_fct_t fct_type; 140 void *dl_pointer_type; 141 }; 142 uni_fct_t temp; 143 temp.dl_pointer_type = dlsym (handle,"initialize"); 144 if (temp.dl_pointer_type == NULL) { 145 const char *error = dlerror (); 146 if (error) 147 fprintf (stderr, "dlsym: %s\n",error); 148 exit(19); 149 } 150 evaluation_fct_t func_initialize; 151 func_initialize = temp.fct_type; 152 func_initialize (); 153 154 temp.dl_pointer_type = dlsym (handle,"simulate_1_cycle"); 155 if (temp.dl_pointer_type == NULL) { 156 const char *error = dlerror (); 157 if (error) 158 fprintf (stderr, "dlsym: %s\n",error); 159 exit(20); 160 } 161 func_simulate_1_cycle = temp.fct_type; 162 163 temp.dl_pointer_type = dlsym (handle,"mealy_generation"); 164 if (temp.dl_pointer_type == NULL) { 165 const char *error = dlerror (); 166 if (error) 167 fprintf (stderr, "dlsym: %s\n",error); 168 exit(21); 169 } 170 func_combinationals = temp.fct_type; 171 172 /* 173 * 174 */ 175 if (dump_stage) 176 cerr << "dynamic link done\n"; 177 } 178 179 static 180 void 181 unlink () 182 { 183 if (handle) 184 { 185 if (dlclose (handle) != 0) 186 cerr << "Warning : dlclose returns an error.\n" 187 << dlerror () << endl; 188 handle = NULL; 189 } 112 static void * handle = NULL; 113 114 static void link(const char * lib) { 115 // chargement du code de simulate_1_cycle 116 handle = dlopen(lib, RTLD_GLOBAL | RTLD_NOW); 117 //handle = dlopen(lib, RTLD_LAZY | RTLD_GLOBAL | RTLD_NOW); 118 119 if (handle == NULL) { 120 const char * error = dlerror(); 121 if (error) { 122 fprintf(stderr, "dlopen: %s\n", error); 123 } 124 fprintf(stderr, "Is there -rdynamic option into your command line ? If not, please do it.\n"); 125 exit(18); 126 } 127 128 union uni_fct_t { 129 evaluation_fct_t fct_type; 130 void * dl_pointer_type; 131 }; 132 uni_fct_t temp; 133 temp.dl_pointer_type = dlsym(handle, "initialize"); 134 if (temp.dl_pointer_type == NULL) { 135 const char * error = dlerror(); 136 if (error) { 137 fprintf(stderr, "dlsym: %s\n", error); 138 } 139 exit(19); 140 } 141 evaluation_fct_t func_initialize; 142 func_initialize = temp.fct_type; 143 func_initialize(); 144 145 temp.dl_pointer_type = dlsym(handle, "simulate_1_cycle"); 146 if (temp.dl_pointer_type == NULL) { 147 const char * error = dlerror(); 148 if (error) { 149 fprintf(stderr, "dlsym: %s\n", error); 150 exit(20); 151 } 152 func_simulate_1_cycle = temp.fct_type; 153 154 temp.dl_pointer_type = dlsym(handle, "mealy_generation"); 155 if (temp.dl_pointer_type == NULL) { 156 const char * error = dlerror(); 157 if (error) { 158 fprintf(stderr, "dlsym: %s\n", error); 159 } 160 exit(21); 161 } 162 func_combinationals = temp.fct_type; 163 164 /* 165 * 166 */ 167 if (dump_stage) { 168 cerr << "dynamic link done\n"; 169 } 170 } 171 } 172 173 174 static void unlink() { 175 if (handle) { 176 if (dlclose(handle) != 0) { 177 cerr << "Warning : dlclose returns an error.\n" << dlerror() << endl; 178 } 179 handle = NULL; 180 } 190 181 } 191 182 … … 194 185 /* ************ */ 195 186 196 bool already_initialized = false; 197 198 static 199 void 200 use_static_func () 201 { 202 if (dump_stage) 203 cerr << "Using static functions to schedule SystemC processes.\n"; 204 if (scheduling_method == CASS_SCHEDULING) 205 { 206 func_simulate_1_cycle = (evaluation_fct_t)sc_core::quasistatic_simulate_1_cycle; 207 func_combinationals = (evaluation_fct_t)sc_core::quasistatic_mealy_generation; 208 } else { 209 func_simulate_1_cycle = (evaluation_fct_t)sc_core::static_simulate_1_cycle; 210 func_combinationals = (evaluation_fct_t)sc_core::static_mealy_generation; 211 } 212 } 213 214 static 215 void 216 compile_and_link (const char *base_name) 217 { 218 if (dump_stage) 219 cerr << "Using dynamically loaded functions to schedule SystemC processes.\n"; 220 // compilation du code de simulate_1_cycle 221 compile_code(base_name); 222 223 char lib_absolutepath[256]; 187 bool already_initialized = false; 188 189 static void use_static_func() { 190 if (dump_stage) { 191 cerr << "Using static functions to schedule SystemC processes.\n"; 192 } 193 if (scheduling_method == CASS_SCHEDULING) { 194 func_simulate_1_cycle = (evaluation_fct_t) sc_core::quasistatic_simulate_1_cycle; 195 func_combinationals = (evaluation_fct_t) sc_core::quasistatic_mealy_generation; 196 } 197 else { 198 func_simulate_1_cycle = (evaluation_fct_t) sc_core::static_simulate_1_cycle; 199 func_combinationals = (evaluation_fct_t) sc_core::static_mealy_generation; 200 } 201 } 202 203 204 static void compile_and_link(const char *base_name) { 205 if (dump_stage) { 206 cerr << "Using dynamically loaded functions to schedule SystemC processes.\n"; 207 } 208 // compilation du code de simulate_1_cycle 209 compile_code(base_name); 210 211 char lib_absolutepath[256]; 224 212 #if defined(CONFIG_OS_DARWIN) 225 sprintf(lib_absolutepath, "/tmp/%s.so", base_name);213 sprintf(lib_absolutepath, "/tmp/%s.so", base_name); 226 214 #elif defined(CONFIG_OS_LINUX) 227 sprintf(lib_absolutepath, "/tmp/.libs/%s.so.0", base_name);215 sprintf(lib_absolutepath, "/tmp/.libs/%s.so.0", base_name); 228 216 #else 229 cerr << "ERROR\n"; exit (126); 230 #endif 231 232 link (lib_absolutepath); 233 } 234 235 static 236 void 237 internal_sc_initialize (void) 238 { 239 sort_equi_list (); 240 241 check_all_method_process (); 242 243 if (dump_netlist_info) 244 cerr << "Module instance list\n" 245 << "--------------------\n" 246 << instances_set << endl; 247 248 /* 249 * Initialize the signals table 250 */ 251 create_signals_table (); 252 bind_to_table (); 253 if (dump_netlist_info) 254 { 255 print_table (cerr); 256 cerr << endl; 257 print_table_stats (cerr); 258 cerr << endl; 259 } 260 261 // Init variables to be able to run combinational functions 262 pending_write_vector_capacity = get_signal_table_size (); 263 264 if (pending_write_vector_capacity == 0) 265 pending_write_vector = NULL; 266 else 267 pending_write_vector = (pending_write_vector_t) realloc (pending_write_vector, sizeof (pending_write_t) * pending_write_vector_capacity); 268 269 // create the clock list 270 clock_list_t clock_list; 271 create_clock_list (clock_list, get_equi_list ()); 272 if (dump_netlist_info) 273 cerr << "Clock list\n" 274 << "----------\n" 275 << clock_list << "\n\n"; 276 277 // Check if a clock exists in the system 278 if (clock_list.empty ()) { 279 cerr << "System need a clock.\n" 280 << "Please define system clock using special type \"sc_clock\".\n"; 281 exit (22); 282 } 283 284 // Check if any constructor wrote into registers 285 if (pending_write_vector_nb != 0) 286 { 287 cerr << "Error : Register/Signal writing is not allowed before sc_initialize.\n" 288 "Move initializations from constructors/sc_main to module reset sequences.\n"; 289 // we are unable to dump register(s) name(s) 290 // because the table binding is not yet completed. 291 exit (24); 292 } 293 294 string base_name = get_scheduling (scheduling_method); 295 296 if (dynamic_link_of_scheduling_code) 297 compile_and_link (base_name.c_str()); 298 else 299 use_static_func (); 300 301 pending_write_vector_nb = 0; 302 303 check_all_ports (); 304 usage.start (); 305 306 if (dump_stage) 307 cerr << "sc_initialize () done.\n"; 308 309 already_initialized = true; 310 } 311 312 inline 313 void 314 check_and_initialize () 315 { 316 if (already_initialized == false) { 217 cerr << "ERROR\n"; 218 exit(126); 219 #endif 220 link(lib_absolutepath); 221 } 222 223 224 static void internal_sc_initialize(void) { 225 sort_equi_list(); 226 227 check_all_method_process(); 228 229 if (dump_netlist_info) { 230 cerr << "Module instance list\n--------------------\n" << instances_set << endl; 231 } 232 233 /* 234 * Initialize the signals table 235 */ 236 create_signals_table(); 237 bind_to_table(); 238 if (dump_netlist_info) { 239 print_table(cerr); 240 cerr << endl; 241 print_table_stats(cerr); 242 cerr << endl; 243 } 244 // Init variables to be able to run combinational functions 245 pending_write_vector_capacity = get_signal_table_size(); 246 247 if (pending_write_vector_capacity == 0) { 248 pending_write_vector = NULL; 249 } 250 else { 251 pending_write_vector = (pending_write_vector_t) realloc(pending_write_vector, sizeof(pending_write_t) * pending_write_vector_capacity); 252 } 253 254 // create the clock list 255 clock_list_t clock_list; 256 create_clock_list(clock_list, get_equi_list()); 257 if (dump_netlist_info) { 258 cerr << "Clock list\n" << "----------\n" << clock_list << "\n\n"; 259 } 260 261 // Check if a clock exists in the system 262 if (clock_list.empty()) { 263 cerr << "System need a clock.\n" << 264 "Please define system clock using special type \"sc_clock\".\n"; 265 exit(22); 266 } 267 // Check if any constructor wrote into registers 268 if (pending_write_vector_nb != 0) { 269 cerr << 270 "Error : Register/Signal writing is not allowed before sc_initialize.\n" 271 "Move initializations from constructors/sc_main to module reset sequences.\n"; 272 // we are unable to dump register(s) name(s) 273 // because the table binding is not yet completed. 274 exit(24); 275 } 276 277 string base_name = get_scheduling(scheduling_method); 278 279 if (dynamic_link_of_scheduling_code) { 280 compile_and_link(base_name.c_str()); 281 } 282 else { 283 use_static_func(); 284 } 285 286 pending_write_vector_nb = 0; 287 288 check_all_ports(); 289 usage.start(); 290 291 if (dump_stage) { 292 cerr << "sc_initialize () done.\n"; 293 } 294 295 already_initialized = true; 296 } 297 298 299 inline void check_and_initialize() { 300 if (already_initialized == false) { 317 301 #if defined(SYSTEMC_VERSION_1_0) 318 std::cerr << "Warning : call sc_initialize before executiong simulation.\n";319 #endif 320 internal_sc_initialize();321 if (dump_module_hierarchy)322 module_hierarchy2dot(dump_module_hierarchy);323 if (nosimulation)324 {325 exit(0);326 }327 }328 } 329 330 void sc_initialize(void) 331 {332 cerr << "Warning : 'sc_initialize' function is deprecated since SystemC 2.1.\n";333 cerr << "Use 'sc_start(0)' instead.\n";334 check_and_initialize();302 cerr << "Warning : call sc_initialize before executiong simulation.\n"; 303 #endif 304 internal_sc_initialize(); 305 if (dump_module_hierarchy) { 306 module_hierarchy2dot(dump_module_hierarchy); 307 } 308 if (nosimulation) { 309 exit(0); 310 } 311 } 312 } 313 314 315 void sc_initialize(void) { 316 cerr << "Warning : 'sc_initialize' function is deprecated since SystemC 2.1.\n"; 317 cerr << "Use 'sc_start(0)' instead.\n"; 318 check_and_initialize(); 335 319 } 336 320 … … 339 323 /* ********** */ 340 324 341 inline 342 void 343 sc_cycle( double duration) 344 { 345 check_and_initialize (); 346 sc_core::internal_sc_cycle0(duration); 347 } 348 349 inline 350 void 351 sc_cycle( double duration, 352 sc_time_unit time_unit ) 353 { 354 check_and_initialize (); 355 sc_core::internal_sc_cycle0(duration); 356 } 357 358 void 359 sc_start(double d_val) 360 { 361 sc_cycle (d_val); 325 inline void sc_cycle(double duration) { 326 check_and_initialize(); 327 sc_core::internal_sc_cycle0(duration); 328 } 329 330 331 inline void sc_cycle(double duration, sc_time_unit time_unit) { 332 check_and_initialize(); 333 sc_core::internal_sc_cycle0(duration); 334 } 335 336 337 void sc_start(double d_val) { 338 sc_cycle(d_val); 362 339 #ifdef DUMP_SIGNAL_STATS 363 print_registers_writing_stats(cerr);340 print_registers_writing_stats(cerr); 364 341 #endif 365 342 #ifdef DUMP_SCHEDULE_STATS 366 print_schedule_stats (cerr); 367 #endif 368 } 369 370 void 371 sc_start() 372 { 373 sc_cycle (-1); 343 print_schedule_stats(cerr); 344 #endif 345 } 346 347 348 void sc_start() { 349 sc_cycle(-1); 374 350 #ifdef DUMP_SIGNAL_STATS 375 print_registers_writing_stats(cerr);351 print_registers_writing_stats(cerr); 376 352 #endif 377 353 #ifdef DUMP_SCHEDULE_STATS 378 print_schedule_stats (cerr); 379 #endif 380 } 381 382 void 383 sc_start (double d_val, 384 sc_time_unit d_tu) 385 { 386 sc_start (sc_time (d_val, d_tu)); 387 } 388 389 void 390 sc_start( const sc_time& duration ) 391 { 392 sc_cycle ((double)duration); 354 print_schedule_stats(cerr); 355 #endif 356 } 357 358 359 void sc_start(double d_val, sc_time_unit d_tu) { 360 sc_start(sc_time(d_val, d_tu)); 361 } 362 363 364 void sc_start(const sc_time & duration) { 365 sc_cycle((double) duration); 393 366 #ifdef DUMP_SIGNAL_STATS 394 print_registers_writing_stats(cerr);367 print_registers_writing_stats(cerr); 395 368 #endif 396 369 #ifdef DUMP_SCHEDULE_STATS 397 print_schedule_stats (cerr); 398 #endif 399 } 370 print_schedule_stats(cerr); 371 #endif 372 } 373 400 374 401 375 /* ****************** */ … … 403 377 /* ****************** */ 404 378 405 bool have_to_stop = false; 406 sc_stop_mode stop_mode = SC_STOP_FINISH_DELTA; 407 408 void 409 sc_stop () 410 { 411 switch (stop_mode) 412 { 413 case SC_STOP_IMMEDIATE : 414 exit (54); 415 break; 416 case SC_STOP_FINISH_DELTA : 417 default : 418 have_to_stop = true; 419 break; 420 } 421 } 422 423 void 424 sc_set_stop_mode (sc_stop_mode new_mode) 425 { 426 if (new_mode == SC_STOP_IMMEDIATE) 427 stop_mode = SC_STOP_IMMEDIATE; 428 } 429 430 sc_stop_mode 431 sc_get_stop_mode () 432 { 433 return stop_mode; 434 } 435 436 void 437 close_systemcass () 438 { 439 unlink (); 440 if (print_user_resources) 441 { 442 usage.stop (); 443 unsigned int d = usage; 444 cerr << "Performances\n" 445 "------------\n"; 446 cerr << "Time elapsed (sec) : " << d << endl; 447 cerr << "Cycles done : " << nb_cycles << endl; 448 //sc_simulation_time () << endl; 449 if (d == 0) 450 cerr << "Performance (c/s) : N/A" << endl; 451 else 452 cerr << "Performance (c/s) : " << nb_cycles / d << endl; 453 // cerr << "Memory used : " << usage.get_memory_size () << endl; 454 } 455 } 456 457 ///////////////////////// 379 bool have_to_stop = false; 380 sc_stop_mode stop_mode = SC_STOP_FINISH_DELTA; 381 382 void sc_stop() { 383 switch (stop_mode) { 384 case SC_STOP_IMMEDIATE: 385 exit(54); 386 break; 387 case SC_STOP_FINISH_DELTA: 388 default: 389 have_to_stop = true; 390 break; 391 } 392 } 393 394 395 void sc_set_stop_mode(sc_stop_mode new_mode) { 396 if (new_mode == SC_STOP_IMMEDIATE) { 397 stop_mode = SC_STOP_IMMEDIATE; 398 } 399 } 400 401 402 sc_stop_mode sc_get_stop_mode() { 403 return stop_mode; 404 } 405 406 407 void close_systemcass() { 408 unlink(); 409 if (print_user_resources) { 410 usage.stop(); 411 unsigned int d = usage; 412 cerr << "Performances\n" "------------\n"; 413 cerr << "Time elapsed (sec) : " << d << endl; 414 cerr << "Cycles done : " << nb_cycles << endl; 415 if (d == 0) { 416 cerr << "Performance (c/s) : N/A" << endl; 417 } 418 else { 419 cerr << "Performance (c/s) : " << nb_cycles / d << endl; 420 } 421 // cerr << "Memory used : " << usage.get_memory_size () << endl; 422 } 423 } 458 424 459 425 } // end of sc_core namespace 460 426 427 /* 428 # Local Variables: 429 # tab-width: 4; 430 # c-basic-offset: 4; 431 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 432 # indent-tabs-mode: nil; 433 # End: 434 # 435 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 436 */ 437
Note: See TracChangeset
for help on using the changeset viewer.