sc_report.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_report.h -- Run-time logging and reporting facilities
00021 
00022   Interface design by SystemC Verification Working Group.
00023   Implementation by Alex Riesen, Synopsys Inc.
00024   Original implementation by Martin Janssen, Synopsys Inc.
00025   Reference implementation by Cadence Design Systems, Inc., 2002-09-23:
00026   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00027   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey.
00028 
00029  *****************************************************************************/
00030 
00031 /*****************************************************************************
00032 
00033   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00034   changes you are making here.
00035 
00036       Name, Affiliation, Date: Alex Riesen, Synopsys Inc., Jan 28, 2003
00037   Description of Modification: Implementation for SytemC 2.1
00038 
00039  *****************************************************************************/
00040 
00041 // $Log: sc_report.cpp,v $
00042 // Revision 1.1.1.1  2006/12/15 20:31:39  acg
00043 // SystemC 2.2
00044 //
00045 // Revision 1.7  2006/03/21 00:00:37  acg
00046 //   Andy Goodrich: changed name of sc_get_current_process_base() to be
00047 //   sc_get_current_process_b() since its returning an sc_process_b instance.
00048 //
00049 // Revision 1.6  2006/01/25 00:31:27  acg
00050 //  Andy Goodrich: Changed over to use a standard message id of
00051 //  SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
00052 //
00053 // Revision 1.5  2006/01/24 22:02:30  acg
00054 //  Andy Goodrich: switch deprecated features warnings to use a single message
00055 //  id, SC_ID_IEEE_1666_DEPRECATION_.
00056 //
00057 // Revision 1.4  2006/01/24 20:53:41  acg
00058 // Andy Goodrich: added warnings indicating that use of integer ids in reports
00059 // is deprecated. Added tracing/sc_trace_ids.h to message list.
00060 //
00061 // Revision 1.3  2006/01/13 18:53:11  acg
00062 // Andy Goodrich: Added $Log command so that CVS comments are reproduced in
00063 // the source.
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 // backward compatibility with 2.0+
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; // only do-nothing set
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 } // namespace sc_core
00292 // taf

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5