sc_report.cc revision 13313
112852Sgabeblack@google.com/* 212852Sgabeblack@google.com * Copyright 2018 Google, Inc. 312852Sgabeblack@google.com * 412852Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512852Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612852Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812852Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012852Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112852Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212852Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312852Sgabeblack@google.com * this software without specific prior written permission. 1412852Sgabeblack@google.com * 1512852Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612852Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712852Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812852Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912852Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012852Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112852Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212852Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312852Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412852Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512852Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612852Sgabeblack@google.com * 2712852Sgabeblack@google.com * Authors: Gabe Black 2812852Sgabeblack@google.com */ 2912852Sgabeblack@google.com 3013157Sgabeblack@google.com#include <cstring> 3113157Sgabeblack@google.com 3212852Sgabeblack@google.com#include "base/logging.hh" 3312852Sgabeblack@google.com#include "systemc/ext/utils/sc_report.hh" 3412997Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 3513313Sgabeblack@google.com#include "systemc/utils/report.hh" 3612852Sgabeblack@google.com 3712852Sgabeblack@google.comnamespace sc_core 3812852Sgabeblack@google.com{ 3912852Sgabeblack@google.com 4013157Sgabeblack@google.comsc_report::sc_report(sc_severity _severity, const char *msg_type, 4113157Sgabeblack@google.com const char *msg, int _verbosity, const char *_fileName, 4212997Sgabeblack@google.com int _lineNumber, sc_time _time, const char *_processName, int _id) : 4313157Sgabeblack@google.com _severity(_severity), _msgType(msg_type), _msg(msg), 4412997Sgabeblack@google.com _verbosity(_verbosity), _fileName(_fileName), _lineNumber(_lineNumber), 4512997Sgabeblack@google.com _time(_time), _processName(_processName), _id(_id) 4612852Sgabeblack@google.com{ 4713157Sgabeblack@google.com if (_msgType) 4813157Sgabeblack@google.com _msgType = strdup(_msgType); 4913157Sgabeblack@google.com if (_msg) 5013157Sgabeblack@google.com _msg = strdup(_msg); 5112997Sgabeblack@google.com _what = sc_report_compose_message(*this); 5212852Sgabeblack@google.com} 5312852Sgabeblack@google.com 5412997Sgabeblack@google.comsc_report::sc_report(const sc_report &r) : 5512997Sgabeblack@google.com sc_report(r._severity, r._msgType, r._msg, r._verbosity, r._fileName, 5612997Sgabeblack@google.com r._lineNumber, r._time, r._processName, r._id) 5712997Sgabeblack@google.com{} 5812997Sgabeblack@google.com 5912852Sgabeblack@google.comsc_report & 6012997Sgabeblack@google.comsc_report::operator = (const sc_report &r) 6112852Sgabeblack@google.com{ 6212997Sgabeblack@google.com _severity = r._severity; 6313157Sgabeblack@google.com free((void *)_msgType); 6413157Sgabeblack@google.com _msgType = r._msgType ? strdup(r._msgType) : nullptr; 6513157Sgabeblack@google.com free((void *)_msg); 6613157Sgabeblack@google.com _msg = r._msg ? strdup(r._msg) : nullptr; 6712997Sgabeblack@google.com _verbosity = r._verbosity; 6812997Sgabeblack@google.com _fileName = r._fileName; 6912997Sgabeblack@google.com _lineNumber = r._lineNumber; 7012997Sgabeblack@google.com _time = r._time; 7112997Sgabeblack@google.com _processName = r._processName; 7212997Sgabeblack@google.com _id = r._id; 7312852Sgabeblack@google.com return *this; 7412852Sgabeblack@google.com} 7512852Sgabeblack@google.com 7613157Sgabeblack@google.comsc_report::~sc_report() throw() 7713157Sgabeblack@google.com{ 7813157Sgabeblack@google.com free((void *)_msgType); 7913157Sgabeblack@google.com free((void *)_msg); 8013157Sgabeblack@google.com} 8112852Sgabeblack@google.com 8212852Sgabeblack@google.comconst char * 8312852Sgabeblack@google.comsc_report::what() const throw() 8412852Sgabeblack@google.com{ 8512997Sgabeblack@google.com return _what.c_str(); 8612852Sgabeblack@google.com} 8712852Sgabeblack@google.com 8812902Sgabeblack@google.comconst char * 8912902Sgabeblack@google.comsc_report::get_message(int id) 9012902Sgabeblack@google.com{ 9113313Sgabeblack@google.com auto it = sc_gem5::reportIdToMsgMap.find(id); 9213313Sgabeblack@google.com if (it == sc_gem5::reportIdToMsgMap.end()) 9313313Sgabeblack@google.com return "unknown id"; 9413313Sgabeblack@google.com else 9513313Sgabeblack@google.com return it->second.c_str(); 9612902Sgabeblack@google.com} 9712902Sgabeblack@google.com 9812902Sgabeblack@google.combool 9912902Sgabeblack@google.comsc_report::is_suppressed(int id) 10012902Sgabeblack@google.com{ 10113313Sgabeblack@google.com auto it = sc_gem5::reportIdToMsgMap.find(id); 10213313Sgabeblack@google.com if (it == sc_gem5::reportIdToMsgMap.end()) 10313313Sgabeblack@google.com return false; 10413313Sgabeblack@google.com 10513313Sgabeblack@google.com return sc_gem5::reportMsgInfoMap[it->second].actions == SC_DO_NOTHING; 10612902Sgabeblack@google.com} 10712902Sgabeblack@google.com 10812902Sgabeblack@google.comvoid 10913313Sgabeblack@google.comsc_report::make_warnings_errors(bool val) 11012902Sgabeblack@google.com{ 11113313Sgabeblack@google.com sc_gem5::reportWarningsAsErrors = val; 11212902Sgabeblack@google.com} 11312902Sgabeblack@google.com 11412902Sgabeblack@google.comvoid 11512902Sgabeblack@google.comsc_report::register_id(int id, const char *msg) 11612902Sgabeblack@google.com{ 11713313Sgabeblack@google.com if (id < 0) { 11813313Sgabeblack@google.com SC_REPORT_ERROR("(E800) register_id failed", "invalid report id"); 11913313Sgabeblack@google.com return; 12013313Sgabeblack@google.com } 12113313Sgabeblack@google.com if (!msg) { 12213313Sgabeblack@google.com SC_REPORT_ERROR("(E800) register_id failed", "invalid report message"); 12313313Sgabeblack@google.com return; 12413313Sgabeblack@google.com } 12513313Sgabeblack@google.com auto p = sc_gem5::reportIdToMsgMap.insert( 12613313Sgabeblack@google.com std::pair<int, std::string>(id, msg)); 12713313Sgabeblack@google.com if (!p.second) { 12813313Sgabeblack@google.com SC_REPORT_ERROR("(E800) register_id failed", 12913313Sgabeblack@google.com "report id already exists"); 13013313Sgabeblack@google.com } else { 13113313Sgabeblack@google.com sc_gem5::reportMsgInfoMap[msg].id = id; 13213313Sgabeblack@google.com } 13312902Sgabeblack@google.com} 13412902Sgabeblack@google.com 13512902Sgabeblack@google.comvoid 13613313Sgabeblack@google.comsc_report::suppress_id(int id, bool suppress) 13712902Sgabeblack@google.com{ 13813313Sgabeblack@google.com auto it = sc_gem5::reportIdToMsgMap.find(id); 13913313Sgabeblack@google.com if (it == sc_gem5::reportIdToMsgMap.end()) 14013313Sgabeblack@google.com return; 14113313Sgabeblack@google.com 14213313Sgabeblack@google.com if (suppress) 14313313Sgabeblack@google.com sc_gem5::reportMsgInfoMap[it->second].actions = SC_DO_NOTHING; 14413313Sgabeblack@google.com else 14513313Sgabeblack@google.com sc_gem5::reportMsgInfoMap[it->second].actions = SC_UNSPECIFIED; 14612902Sgabeblack@google.com} 14712902Sgabeblack@google.com 14812902Sgabeblack@google.comvoid 14913313Sgabeblack@google.comsc_report::suppress_infos(bool suppress) 15012902Sgabeblack@google.com{ 15113313Sgabeblack@google.com if (suppress) 15213313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_INFO].actions = SC_DO_NOTHING; 15313313Sgabeblack@google.com else 15413313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_INFO].actions = SC_DEFAULT_INFO_ACTIONS; 15512902Sgabeblack@google.com} 15612902Sgabeblack@google.com 15712902Sgabeblack@google.comvoid 15813313Sgabeblack@google.comsc_report::suppress_warnings(bool suppress) 15912902Sgabeblack@google.com{ 16013313Sgabeblack@google.com if (suppress) { 16113313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_WARNING].actions = SC_DO_NOTHING; 16213313Sgabeblack@google.com } else { 16313313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_WARNING].actions = 16413313Sgabeblack@google.com SC_DEFAULT_WARNING_ACTIONS; 16513313Sgabeblack@google.com } 16612902Sgabeblack@google.com} 16712902Sgabeblack@google.com 16812852Sgabeblack@google.comvoid 16912852Sgabeblack@google.comsc_abort() 17012852Sgabeblack@google.com{ 17112997Sgabeblack@google.com panic("simulation aborted"); 17212852Sgabeblack@google.com} 17312852Sgabeblack@google.com 17412852Sgabeblack@google.com} // namespace sc_core 175