void sc_report_handler::default_handler(const sc_report& rep, const sc_actions& actions) { if ( actions & SC_DISPLAY ) ::std::cout << ::std::endl << sc_report_compose_message(rep) << ::std::endl; if ( (actions & SC_LOG) && get_log_file_name() ) { if ( !log_stream ) log_stream = new ::std::ofstream(get_log_file_name()); // ios::trunc *log_stream << rep.get_time() << ": " << sc_report_compose_message(rep) << ::std::endl; } if ( actions & SC_STOP ) { sc_stop_here(rep.get_msg_type(), rep.get_severity()); sc_stop(); } if ( actions & SC_INTERRUPT ) sc_interrupt_here(rep.get_msg_type(), rep.get_severity()); if ( actions & SC_ABORT ) abort(); if ( actions & SC_THROW ) throw rep; }
// not documented, but available const std::string sc_report_compose_message(const sc_report& rep) { static const char * severity_names[] = { "Info", "Warning", "Error", "Fatal" }; std::string str; str += severity_names[rep.get_severity()]; str += ": "; if ( rep.get_id() >= 0 ) // backward compatibility with 2.0+ { char idstr[64]; std::sprintf(idstr, "(%c%d) ", "IWEF"[rep.get_severity()], rep.get_id()); str += idstr; } str += rep.get_msg_type(); if ( *rep.get_msg() ) { str += ": "; str += rep.get_msg(); } if ( rep.get_severity() > SC_INFO ) { char line_number_str[16]; str += "\nIn file: "; str += rep.get_file_name(); str += ":"; std::sprintf(line_number_str, "%d", rep.get_line_number()); str += line_number_str; sc_simcontext* simc = sc_get_curr_simcontext(); if ( simc && sc_is_running() ) { const char* proc_name = rep.get_process_name(); if ( proc_name ) { str += "\nIn process: "; str += proc_name; str += " @ "; str += rep.get_time().to_string(); } } } return str; }
// custom handler which is used to dump out reports and actions void dump_all_handler( const sc_report& report, const sc_actions& actions) { // dump out report cout << "report: " << report.get_msg_type() << " " << severity2str[ report.get_severity() ]; cout << " --> "; for (int n=0; n<32; n++) { sc_actions action = actions & 1<<n; if (action) { cout << " "; switch(action) { case SC_UNSPECIFIED: cout << "unspecified"; break; case SC_DO_NOTHING: cout << "do-nothing"; break; case SC_THROW: cout << "throw"; break; case SC_LOG: cout << "log"; break; case SC_DISPLAY: cout << "display"; break; case SC_CACHE_REPORT: cout << "cache-report"; break; case SC_INTERRUPT: cout << "interrupt"; break; case SC_STOP: cout << "stop"; break; case SC_ABORT: cout << "abort"; break; default: bool found=false; for (unsigned int u=0; u<num_usr_actions; u++) if (action == usr_actions[u]) { cout << "usr" << u+1; found=true; break; } if (!found) cout << "UNKNOWN"; } } } cout << endl; cout << " msg=" << report.get_msg() << " file=" << report.get_file_name() << " line " << report.get_line_number() << " time=" << report.get_time(); const char* name = report.get_process_name(); cout << " process=" << (name ? name : "<none>") << endl; }