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" 3313322Sgabeblack@google.com#include "systemc/ext/utils/messages.hh" 3412852Sgabeblack@google.com#include "systemc/ext/utils/sc_report.hh" 3512997Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh" 3613313Sgabeblack@google.com#include "systemc/utils/report.hh" 3712852Sgabeblack@google.com 3812852Sgabeblack@google.comnamespace sc_core 3912852Sgabeblack@google.com{ 4012852Sgabeblack@google.com 4113157Sgabeblack@google.comsc_report::sc_report(sc_severity _severity, const char *msg_type, 4213157Sgabeblack@google.com const char *msg, int _verbosity, const char *_fileName, 4312997Sgabeblack@google.com int _lineNumber, sc_time _time, const char *_processName, int _id) : 4413157Sgabeblack@google.com _severity(_severity), _msgType(msg_type), _msg(msg), 4512997Sgabeblack@google.com _verbosity(_verbosity), _fileName(_fileName), _lineNumber(_lineNumber), 4612997Sgabeblack@google.com _time(_time), _processName(_processName), _id(_id) 4712852Sgabeblack@google.com{ 4813157Sgabeblack@google.com if (_msgType) 4913157Sgabeblack@google.com _msgType = strdup(_msgType); 5013157Sgabeblack@google.com if (_msg) 5113157Sgabeblack@google.com _msg = strdup(_msg); 5212997Sgabeblack@google.com _what = sc_report_compose_message(*this); 5312852Sgabeblack@google.com} 5412852Sgabeblack@google.com 5512997Sgabeblack@google.comsc_report::sc_report(const sc_report &r) : 5612997Sgabeblack@google.com sc_report(r._severity, r._msgType, r._msg, r._verbosity, r._fileName, 5712997Sgabeblack@google.com r._lineNumber, r._time, r._processName, r._id) 5812997Sgabeblack@google.com{} 5912997Sgabeblack@google.com 6012852Sgabeblack@google.comsc_report & 6112997Sgabeblack@google.comsc_report::operator = (const sc_report &r) 6212852Sgabeblack@google.com{ 6312997Sgabeblack@google.com _severity = r._severity; 6413157Sgabeblack@google.com free((void *)_msgType); 6513157Sgabeblack@google.com _msgType = r._msgType ? strdup(r._msgType) : nullptr; 6613157Sgabeblack@google.com free((void *)_msg); 6713157Sgabeblack@google.com _msg = r._msg ? strdup(r._msg) : nullptr; 6812997Sgabeblack@google.com _verbosity = r._verbosity; 6912997Sgabeblack@google.com _fileName = r._fileName; 7012997Sgabeblack@google.com _lineNumber = r._lineNumber; 7112997Sgabeblack@google.com _time = r._time; 7212997Sgabeblack@google.com _processName = r._processName; 7312997Sgabeblack@google.com _id = r._id; 7412852Sgabeblack@google.com return *this; 7512852Sgabeblack@google.com} 7612852Sgabeblack@google.com 7713157Sgabeblack@google.comsc_report::~sc_report() throw() 7813157Sgabeblack@google.com{ 7913157Sgabeblack@google.com free((void *)_msgType); 8013157Sgabeblack@google.com free((void *)_msg); 8113157Sgabeblack@google.com} 8212852Sgabeblack@google.com 8312852Sgabeblack@google.comconst char * 8412852Sgabeblack@google.comsc_report::what() const throw() 8512852Sgabeblack@google.com{ 8612997Sgabeblack@google.com return _what.c_str(); 8712852Sgabeblack@google.com} 8812852Sgabeblack@google.com 8912902Sgabeblack@google.comconst char * 9012902Sgabeblack@google.comsc_report::get_message(int id) 9112902Sgabeblack@google.com{ 9213401Sgabeblack@google.com auto it = sc_gem5::reportIdToMsgMap().find(id); 9313401Sgabeblack@google.com if (it == sc_gem5::reportIdToMsgMap().end()) 9413313Sgabeblack@google.com return "unknown id"; 9513313Sgabeblack@google.com else 9613313Sgabeblack@google.com return it->second.c_str(); 9712902Sgabeblack@google.com} 9812902Sgabeblack@google.com 9912902Sgabeblack@google.combool 10012902Sgabeblack@google.comsc_report::is_suppressed(int id) 10112902Sgabeblack@google.com{ 10213401Sgabeblack@google.com auto it = sc_gem5::reportIdToMsgMap().find(id); 10313401Sgabeblack@google.com if (it == sc_gem5::reportIdToMsgMap().end()) 10413313Sgabeblack@google.com return false; 10513313Sgabeblack@google.com 10613401Sgabeblack@google.com auto &msgInfo = sc_gem5::reportMsgInfoMap()[it->second]; 10713314Sgabeblack@google.com 10813314Sgabeblack@google.com return (msgInfo.actions == SC_DO_NOTHING || 10913314Sgabeblack@google.com (msgInfo.sevActions[SC_INFO] == SC_DO_NOTHING && 11013314Sgabeblack@google.com msgInfo.sevActions[SC_WARNING] == SC_DO_NOTHING)); 11112902Sgabeblack@google.com} 11212902Sgabeblack@google.com 11312902Sgabeblack@google.comvoid 11413313Sgabeblack@google.comsc_report::make_warnings_errors(bool val) 11512902Sgabeblack@google.com{ 11613313Sgabeblack@google.com sc_gem5::reportWarningsAsErrors = val; 11712902Sgabeblack@google.com} 11812902Sgabeblack@google.com 11912902Sgabeblack@google.comvoid 12012902Sgabeblack@google.comsc_report::register_id(int id, const char *msg) 12112902Sgabeblack@google.com{ 12213313Sgabeblack@google.com if (id < 0) { 12313322Sgabeblack@google.com SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "invalid report id"); 12413313Sgabeblack@google.com return; 12513313Sgabeblack@google.com } 12613313Sgabeblack@google.com if (!msg) { 12713322Sgabeblack@google.com SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "invalid report message"); 12813313Sgabeblack@google.com return; 12913313Sgabeblack@google.com } 13013401Sgabeblack@google.com auto p = sc_gem5::reportIdToMsgMap().insert( 13113313Sgabeblack@google.com std::pair<int, std::string>(id, msg)); 13213313Sgabeblack@google.com if (!p.second) { 13313322Sgabeblack@google.com SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "report id already exists"); 13413313Sgabeblack@google.com } else { 13513401Sgabeblack@google.com sc_gem5::reportMsgInfoMap()[msg].id = id; 13613313Sgabeblack@google.com } 13712902Sgabeblack@google.com} 13812902Sgabeblack@google.com 13912902Sgabeblack@google.comvoid 14013313Sgabeblack@google.comsc_report::suppress_id(int id, bool suppress) 14112902Sgabeblack@google.com{ 14213401Sgabeblack@google.com auto it = sc_gem5::reportIdToMsgMap().find(id); 14313401Sgabeblack@google.com if (it == sc_gem5::reportIdToMsgMap().end()) 14413313Sgabeblack@google.com return; 14513313Sgabeblack@google.com 14613314Sgabeblack@google.com if (suppress) { 14713401Sgabeblack@google.com sc_gem5::reportMsgInfoMap()[it->second]. 14813314Sgabeblack@google.com sevActions[SC_INFO] = SC_DO_NOTHING; 14913401Sgabeblack@google.com sc_gem5::reportMsgInfoMap()[it->second]. 15013314Sgabeblack@google.com sevActions[SC_WARNING] = SC_DO_NOTHING; 15113314Sgabeblack@google.com } else { 15213401Sgabeblack@google.com sc_gem5::reportMsgInfoMap()[it->second]. 15313314Sgabeblack@google.com sevActions[SC_INFO] = SC_UNSPECIFIED; 15413401Sgabeblack@google.com sc_gem5::reportMsgInfoMap()[it->second]. 15513314Sgabeblack@google.com sevActions[SC_WARNING] = SC_UNSPECIFIED; 15613314Sgabeblack@google.com } 15712902Sgabeblack@google.com} 15812902Sgabeblack@google.com 15912902Sgabeblack@google.comvoid 16013313Sgabeblack@google.comsc_report::suppress_infos(bool suppress) 16112902Sgabeblack@google.com{ 16213313Sgabeblack@google.com if (suppress) 16313313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_INFO].actions = SC_DO_NOTHING; 16413313Sgabeblack@google.com else 16513313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_INFO].actions = SC_DEFAULT_INFO_ACTIONS; 16612902Sgabeblack@google.com} 16712902Sgabeblack@google.com 16812902Sgabeblack@google.comvoid 16913313Sgabeblack@google.comsc_report::suppress_warnings(bool suppress) 17012902Sgabeblack@google.com{ 17113313Sgabeblack@google.com if (suppress) { 17213313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_WARNING].actions = SC_DO_NOTHING; 17313313Sgabeblack@google.com } else { 17413313Sgabeblack@google.com sc_gem5::reportSevInfos[SC_WARNING].actions = 17513313Sgabeblack@google.com SC_DEFAULT_WARNING_ACTIONS; 17613313Sgabeblack@google.com } 17712902Sgabeblack@google.com} 17812902Sgabeblack@google.com 17912852Sgabeblack@google.comvoid 18012852Sgabeblack@google.comsc_abort() 18112852Sgabeblack@google.com{ 18212997Sgabeblack@google.com panic("simulation aborted"); 18312852Sgabeblack@google.com} 18412852Sgabeblack@google.com 18512852Sgabeblack@google.com} // namespace sc_core 186