gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_report.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors: Gabe Black
28  */
29 
30 #include <cstring>
31 
32 #include "base/logging.hh"
36 #include "systemc/utils/report.hh"
37 
38 namespace sc_core
39 {
40 
41 sc_report::sc_report(sc_severity _severity, const char *msg_type,
42  const char *msg, int _verbosity, const char *_fileName,
43  int _lineNumber, sc_time _time, const char *_processName, int _id) :
44  _severity(_severity), _msgType(msg_type), _msg(msg),
45  _verbosity(_verbosity), _fileName(_fileName), _lineNumber(_lineNumber),
46  _time(_time), _processName(_processName), _id(_id)
47 {
48  if (_msgType)
49  _msgType = strdup(_msgType);
50  if (_msg)
51  _msg = strdup(_msg);
53 }
54 
57  r._lineNumber, r._time, r._processName, r._id)
58 {}
59 
60 sc_report &
62 {
63  _severity = r._severity;
64  free((void *)_msgType);
65  _msgType = r._msgType ? strdup(r._msgType) : nullptr;
66  free((void *)_msg);
67  _msg = r._msg ? strdup(r._msg) : nullptr;
69  _fileName = r._fileName;
71  _time = r._time;
73  _id = r._id;
74  return *this;
75 }
76 
78 {
79  free((void *)_msgType);
80  free((void *)_msg);
81 }
82 
83 const char *
84 sc_report::what() const throw()
85 {
86  return _what.c_str();
87 }
88 
89 const char *
91 {
92  auto it = sc_gem5::reportIdToMsgMap().find(id);
93  if (it == sc_gem5::reportIdToMsgMap().end())
94  return "unknown id";
95  else
96  return it->second.c_str();
97 }
98 
99 bool
101 {
102  auto it = sc_gem5::reportIdToMsgMap().find(id);
103  if (it == sc_gem5::reportIdToMsgMap().end())
104  return false;
105 
106  auto &msgInfo = sc_gem5::reportMsgInfoMap()[it->second];
107 
108  return (msgInfo.actions == SC_DO_NOTHING ||
109  (msgInfo.sevActions[SC_INFO] == SC_DO_NOTHING &&
110  msgInfo.sevActions[SC_WARNING] == SC_DO_NOTHING));
111 }
112 
113 void
115 {
117 }
118 
119 void
120 sc_report::register_id(int id, const char *msg)
121 {
122  if (id < 0) {
123  SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "invalid report id");
124  return;
125  }
126  if (!msg) {
127  SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "invalid report message");
128  return;
129  }
130  auto p = sc_gem5::reportIdToMsgMap().insert(
131  std::pair<int, std::string>(id, msg));
132  if (!p.second) {
133  SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "report id already exists");
134  } else {
135  sc_gem5::reportMsgInfoMap()[msg].id = id;
136  }
137 }
138 
139 void
140 sc_report::suppress_id(int id, bool suppress)
141 {
142  auto it = sc_gem5::reportIdToMsgMap().find(id);
143  if (it == sc_gem5::reportIdToMsgMap().end())
144  return;
145 
146  if (suppress) {
147  sc_gem5::reportMsgInfoMap()[it->second].
148  sevActions[SC_INFO] = SC_DO_NOTHING;
149  sc_gem5::reportMsgInfoMap()[it->second].
150  sevActions[SC_WARNING] = SC_DO_NOTHING;
151  } else {
152  sc_gem5::reportMsgInfoMap()[it->second].
153  sevActions[SC_INFO] = SC_UNSPECIFIED;
154  sc_gem5::reportMsgInfoMap()[it->second].
155  sevActions[SC_WARNING] = SC_UNSPECIFIED;
156  }
157 }
158 
159 void
161 {
162  if (suppress)
164  else
166 }
167 
168 void
170 {
171  if (suppress) {
173  } else {
176  }
177 }
178 
179 void
181 {
182  panic("simulation aborted");
183 }
184 
185 } // namespace sc_core
const char * _processName
Definition: sc_report.hh:111
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
virtual const char * what() const
Definition: sc_report.cc:84
std::map< std::string, ReportMsgInfo > & reportMsgInfoMap()
Definition: report.cc:51
std::string _what
Definition: sc_report.hh:113
sc_severity _severity
Definition: sc_report.hh:104
STL pair class.
Definition: stl.hh:61
sc_report & operator=(const sc_report &)
Definition: sc_report.cc:61
const std::string sc_report_compose_message(const sc_report &)
static void make_warnings_errors(bool)
Definition: sc_report.cc:114
static void suppress_id(int id, bool)
Definition: sc_report.cc:140
Bitfield< 33 > id
static void suppress_infos(bool)
Definition: sc_report.cc:160
sc_report(const sc_report &)
Definition: sc_report.cc:55
Bitfield< 63 > val
Definition: misc.hh:771
std::map< int, std::string > & reportIdToMsgMap()
Definition: report.cc:58
sc_core::sc_actions actions
Definition: report.hh:89
const char * _msg
Definition: sc_report.hh:106
const char SC_ID_REGISTER_ID_FAILED_[]
Definition: messages.cc:36
virtual ~sc_report()
Definition: sc_report.cc:77
ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY]
Definition: report.cc:42
const char * _fileName
Definition: sc_report.hh:108
#define SC_REPORT_ERROR(msg_type, msg)
static bool is_suppressed(int id)
Definition: sc_report.cc:100
bool reportWarningsAsErrors
Definition: report.cc:75
static const char * get_message(int id)
Definition: sc_report.cc:90
const char * _msgType
Definition: sc_report.hh:105
static void suppress_warnings(bool)
Definition: sc_report.cc:169
static void register_id(int id, const char *msg)
Definition: sc_report.cc:120
void sc_abort()
Definition: sc_report.cc:180
Bitfield< 0 > p

Generated on Fri Feb 28 2020 16:27:06 for gem5 by doxygen 1.8.13