sc_report_handler.cpp

来自「system C源码 一种替代verilog的语言」· C++ 代码 · 共 708 行 · 第 1/2 页

CPP
708
字号
/*****************************************************************************  The following code is derived, directly or indirectly, from the SystemC  source code Copyright (c) 1996-2006 by all Contributors.  All Rights reserved.  The contents of this file are subject to the restrictions and limitations  set forth in the SystemC Open Source License Version 2.4 (the "License");  You may not use this file except in compliance with such restrictions and  limitations. You may obtain instructions on how to receive a copy of the  License at http://www.systemc.org/. Software distributed by Contributors  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF  ANY KIND, either express or implied. See the License for the specific  language governing rights and limitations under the License. *****************************************************************************//*****************************************************************************  sc_report_handler.cpp -   Original Author: Alex Riesen, Synopsys, Inc.  see also sc_report.cpp *****************************************************************************//*****************************************************************************  MODIFICATION LOG - modifiers, enter your name, affiliation, date and  changes you are making here.      Name, Affiliation, Date:  Description of Modification: *****************************************************************************/// $Log: sc_report_handler.cpp,v $// Revision 1.1.1.1  2006/12/15 20:31:39  acg// SystemC 2.2//// Revision 1.6  2006/03/21 00:00:37  acg//   Andy Goodrich: changed name of sc_get_current_process_base() to be//   sc_get_current_process_b() since its returning an sc_process_b instance.//// Revision 1.5  2006/01/31 21:42:07  acg//  Andy Goodrich: Added checks for SC_DEPRECATED_WARNINGS being defined as//  DISABLED. If so, we turn off the /IEEE_Std_1666/deprecated message group.//// Revision 1.4  2006/01/26 21:08:17  acg//  Andy Goodrich: conversion to use sc_is_running instead of deprecated//  sc_simcontext::is_running()//// Revision 1.3  2006/01/13 18:53:11  acg// Andy Goodrich: Added $Log command so that CVS comments are reproduced in// the source.//#include "sysc/utils/sc_iostream.h"#include "sysc/kernel/sc_process.h"#include "sysc/kernel/sc_simcontext_int.h"#include "sysc/utils/sc_stop_here.h"#include "sysc/utils/sc_report_handler.h"#include "sysc/utils/sc_report.h"namespace std {}namespace sc_core {// not documented, but availableconst 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;}bool sc_report_close_default_log();static ::std::ofstream* log_stream = 0;staticstruct auto_close_log{    ~auto_close_log()    {	sc_report_close_default_log();    }} auto_close;const char* sc_report::get_process_name() const{	return process ? process->name() : 0;}//// The official handler of the exception reporting//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 availablebool sc_report_close_default_log(){    delete log_stream;    sc_report_handler::set_log_file_name(NULL);    if ( !log_stream )	return false;    log_stream = 0;    return true;}int sc_report_handler::get_count(sc_severity severity_) {    return sev_call_count[severity_]; } int sc_report_handler::get_count(const char* msg_type_) {     sc_msg_def * md = mdlookup(msg_type_);     if ( !md )         md = add_msg_type(msg_type_);     return md->call_count; } int sc_report_handler::get_count(const char* msg_type_, sc_severity severity_) {     sc_msg_def * md = mdlookup(msg_type_);     if ( !md )         md = add_msg_type(msg_type_);     return md->sev_call_count[severity_]; } //// CLASS: sc_report_handler// implementation//sc_msg_def * sc_report_handler::mdlookup(const char * msg_type_){    for ( msg_def_items * item = messages; item; item = item->next )    {	for ( int i = 0; i < item->count; ++i )	    if ( !strcmp(msg_type_, item->md[i].msg_type) )		return item->md + i;    }    return 0;}// The calculation of actions to be executedsc_actions sc_report_handler::execute(sc_msg_def* md, sc_severity severity_){    sc_actions actions = md->sev_actions[severity_]; // high prio    if ( SC_UNSPECIFIED == actions ) // middle prio	actions = md->actions;    if ( SC_UNSPECIFIED == actions ) // the lowest prio	actions = sev_actions[severity_];    actions &= ~suppress_mask; // higher than the high prio    actions |= force_mask; // higher than above, and the limit is the highest    unsigned * limit = 0;    unsigned * call_count = 0;    // just increment counters and check for overflow    if ( md->sev_call_count[severity_] < UINT_MAX )	md->sev_call_count[severity_]++;    if ( md->call_count < UINT_MAX )	md->call_count++;    if ( sev_call_count[severity_] < UINT_MAX )	sev_call_count[severity_]++;    if ( md->limit_mask & (1 << (severity_ + 1)) )    {	limit = md->sev_limit + severity_;	call_count = md->sev_call_count + severity_;    }    if ( !limit && (md->limit_mask & 1) )    {	limit = &md->limit;	call_count = &md->call_count;    }    if ( !limit )    {	limit = sev_limit + severity_;	call_count = sev_call_count + severity_;    }    if ( *limit == 0 )    {	// stop limit disabled    }    else if ( *limit != UINT_MAX )    {	if ( *call_count >= *limit )	    actions |= SC_STOP; // force sc_stop()    }    return actions;}void sc_report_handler::report(sc_severity severity_,			       const char * msg_type_,			       const char * msg_,			       const char * file_,			       int line_){    sc_msg_def * md = mdlookup(msg_type_);    if ( !md )	md = add_msg_type(msg_type_);    sc_actions actions = execute(md, severity_);    sc_report rep(severity_, md, msg_, file_, line_);    if ( actions & SC_CACHE_REPORT )	cache_report(rep);    handler(rep, actions);}// The following method is never called by the simulator.void sc_report_handler::initialize(){#if 0 // actually, i do not know whether we have to reset these.    suppress();    force();    set_actions(SC_INFO,    SC_DEFAULT_INFO_ACTIONS);    set_actions(SC_WARNING, SC_DEFAULT_WARNING_ACTIONS);    set_actions(SC_ERROR,   SC_DEFAULT_ERROR_ACTIONS);    set_actions(SC_FATAL,   SC_DEFAULT_FATAL_ACTIONS);#endif    sev_call_count[SC_INFO]    = 0;    sev_call_count[SC_WARNING] = 0;    sev_call_count[SC_ERROR]   = 0;    sev_call_count[SC_FATAL]   = 0;    msg_def_items * items = messages;    while ( items != &msg_terminator )    {	for ( int i = 0; i < items->count; ++i )	{	    items->md[i].call_count = 0;	    items->md[i].sev_call_count[SC_INFO]    = 0;	    items->md[i].sev_call_count[SC_WARNING] = 0;	    items->md[i].sev_call_count[SC_ERROR]   = 0;	    items->md[i].sev_call_count[SC_FATAL]   = 0;	}	items = items->next;    }    // PROCESS ANY ENVIRONMENTAL OVERRIDES:    const char* deprecation_warn = std::getenv("SC_DEPRECATION_WARNINGS");    if ( (deprecation_warn!=0) && !strcmp(deprecation_warn,"DISABLE") )    {        set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING);    }}// free the sc_msg_def's allocated by add_msg_type// (or implicit msg_type registration: set_actions, abort_after)// clear last_global_report.void sc_report_handler::release(){    if ( last_global_report )	delete last_global_report;    last_global_report = 0;    sc_report_close_default_log();    msg_def_items * items = messages, * newitems = &msg_terminator;    messages = &msg_terminator;    while ( items != &msg_terminator )

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?