00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #include "sysc/kernel/sc_process.h"
00067 #include "sysc/kernel/sc_simcontext_int.h"
00068 #include "sysc/utils/sc_stop_here.h"
00069 #include "sysc/utils/sc_report.h"
00070 #include "sysc/utils/sc_utils_ids.h"
00071
00072 namespace sc_core {
00073
00074
00075 static void sc_deprecated_report_ids(const char* method)
00076 {
00077 static bool warn_report_ids_deprecated=true;
00078 if ( warn_report_ids_deprecated )
00079 {
00080 std::string message;
00081 message = "integer report ids are deprecated, use string values: ";
00082 message += method;
00083 warn_report_ids_deprecated=false;
00084 SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_, message.c_str());
00085 }
00086 }
00087
00088 static char empty_str[] = "";
00089 static inline char * empty_dup(const char * p)
00090 {
00091 return p && *p ? strdup(p): empty_str;
00092 }
00093
00094 sc_report::sc_report()
00095 : severity(SC_INFO),
00096 md(0),
00097 msg(empty_dup(0)),
00098 file(empty_dup(0)),
00099 line(0),
00100 timestamp(new sc_time(sc_time_stamp())),
00101 process(0),
00102 m_what(empty_dup(0))
00103 {
00104 }
00105
00106 sc_report::sc_report(sc_severity severity_,
00107 const sc_msg_def* md_,
00108 const char* msg_,
00109 const char* file_,
00110 int line_)
00111 : severity(severity_),
00112 md(md_),
00113 msg(empty_dup(msg_)),
00114 file(empty_dup(file_)),
00115 line(line_),
00116 timestamp(new sc_time(sc_time_stamp())),
00117 process(sc_get_current_process_b()),
00118 m_what(strdup(sc_report_compose_message(*this).c_str()))
00119 {
00120 }
00121
00122 sc_report::sc_report(const sc_report& other)
00123 : severity(other.severity),
00124 md(other.md),
00125 msg(empty_dup(other.msg)),
00126 file(empty_dup(other.file)),
00127 line(other.line),
00128 timestamp(new sc_time(*other.timestamp)),
00129 process(other.process),
00130 m_what(empty_dup(other.m_what))
00131 {
00132 }
00133
00134 sc_report & sc_report::operator=(const sc_report& other)
00135 {
00136 severity = other.severity;
00137 md = other.md;
00138
00139 if ( msg != empty_str ) free(msg);
00140 msg = empty_dup(other.msg);
00141
00142 if ( file != empty_str ) free(file);
00143 file = empty_dup(other.file);
00144
00145 line = other.line;
00146 delete timestamp;
00147 timestamp = new sc_time(*other.timestamp);
00148 process = other.process;
00149
00150 if ( m_what != empty_str ) free(m_what);
00151 m_what = empty_dup(other.m_what);
00152
00153 return *this;
00154 }
00155
00156 sc_report::~sc_report() throw()
00157 {
00158 if ( file != empty_str )
00159 free(file);
00160 if ( msg != empty_str )
00161 free(msg);
00162 delete timestamp;
00163 if ( m_what != empty_str )
00164 free(m_what);
00165 }
00166
00167 const char * sc_report::get_msg_type() const
00168 {
00169 return md->msg_type;
00170 }
00171
00172
00173
00174
00175
00176 static bool warnings_are_errors = false;
00177 static const char unknown_id[] = "unknown id";
00178
00179 void sc_report_handler::report(sc_severity severity_,
00180 int id_,
00181 const char* msg_,
00182 const char* file_,
00183 int line_ )
00184 {
00185 sc_msg_def * md = sc_report_handler::mdlookup(id_);
00186
00187 if ( !md )
00188 {
00189 md = sc_report_handler::add_msg_type(unknown_id);
00190 md->id = id_;
00191 }
00192
00193 if ( severity_ == SC_WARNING && warnings_are_errors )
00194 severity_ = SC_ERROR;
00195
00196 sc_actions actions = execute(md, severity_);
00197 sc_report rep(severity_, md, msg_, file_, line_);
00198
00199 if ( actions & SC_CACHE_REPORT )
00200 cache_report(rep);
00201
00202 if ( severity_ == SC_ERROR )
00203 actions |= SC_THROW;
00204 else if ( severity_ == SC_FATAL )
00205 actions |= SC_ABORT;
00206
00207 handler(rep, actions);
00208 }
00209
00210 void sc_report::register_id( int id, const char* msg )
00211 {
00212 sc_deprecated_report_ids("sc_report::register_id()");
00213 if( id < 0 ) {
00214 SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
00215 "invalid report id" );
00216 }
00217 if( msg == 0 ) {
00218 SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
00219 "invalid report message" );
00220 }
00221 sc_msg_def * md = sc_report_handler::mdlookup(id);
00222
00223 if ( !md )
00224 md = sc_report_handler::add_msg_type(msg);
00225
00226 if ( !md ) {
00227 SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
00228 "report_map insertion error" );
00229 }
00230
00231 if( md->id != -1 ) {
00232 if( strcmp( msg, md->msg_type ) != 0 ) {
00233 SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
00234 "report id already exists" );
00235 }
00236 return;
00237 }
00238 md->id = id;
00239 }
00240
00241 const char* sc_report::get_message( int id )
00242 {
00243 sc_deprecated_report_ids("sc_report::get_message()");
00244 sc_msg_def* md = sc_report_handler::mdlookup(id);
00245
00246 return md ? md->msg_type: unknown_id;
00247 }
00248
00249 bool sc_report::is_suppressed( int id )
00250 {
00251 sc_deprecated_report_ids("sc_report::is_suppressed()");
00252 sc_msg_def* md = sc_report_handler::mdlookup(id);
00253
00254 return md ? md->actions == SC_DO_NOTHING: false;
00255 }
00256
00257 void sc_report::suppress_id(int id_, bool suppress)
00258 {
00259 sc_deprecated_report_ids("sc_report::suppress_id()");
00260 sc_msg_def* md = sc_report_handler::mdlookup(id_);
00261
00262 if ( md )
00263 md->actions = suppress ? SC_DO_NOTHING: SC_UNSPECIFIED;
00264 }
00265
00266 void sc_report::suppress_infos(bool suppress)
00267 {
00268 sc_deprecated_report_ids("sc_report::supress_infos");
00269 sc_report_handler::sev_actions[SC_INFO] =
00270 suppress ? SC_DO_NOTHING: SC_DEFAULT_INFO_ACTIONS;
00271 }
00272
00273 void sc_report::suppress_warnings(bool suppress)
00274 {
00275 sc_deprecated_report_ids("sc_report::suppress_warnings");
00276 sc_report_handler::sev_actions[SC_WARNING] =
00277 suppress ? SC_DO_NOTHING: SC_DEFAULT_WARNING_ACTIONS;
00278 }
00279
00280 void sc_report::make_warnings_errors(bool flag)
00281 {
00282 sc_deprecated_report_ids("sc_report::make_warnings_errors");
00283 warnings_are_errors = flag;
00284 }
00285
00286 int sc_report::get_id() const
00287 {
00288 return md->id;
00289 }
00290
00291 }
00292