sc_report.cc revision 13313
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"
33#include "systemc/ext/utils/sc_report.hh"
34#include "systemc/ext/utils/sc_report_handler.hh"
35#include "systemc/utils/report.hh"
36
37namespace sc_core
38{
39
40sc_report::sc_report(sc_severity _severity, const char *msg_type,
41        const char *msg, int _verbosity, const char *_fileName,
42        int _lineNumber, sc_time _time, const char *_processName, int _id) :
43    _severity(_severity), _msgType(msg_type), _msg(msg),
44    _verbosity(_verbosity), _fileName(_fileName), _lineNumber(_lineNumber),
45    _time(_time), _processName(_processName), _id(_id)
46{
47    if (_msgType)
48        _msgType = strdup(_msgType);
49    if (_msg)
50        _msg = strdup(_msg);
51    _what = sc_report_compose_message(*this);
52}
53
54sc_report::sc_report(const sc_report &r) :
55    sc_report(r._severity, r._msgType, r._msg, r._verbosity, r._fileName,
56            r._lineNumber, r._time, r._processName, r._id)
57{}
58
59sc_report &
60sc_report::operator = (const sc_report &r)
61{
62    _severity = r._severity;
63    free((void *)_msgType);
64    _msgType = r._msgType ? strdup(r._msgType) : nullptr;
65    free((void *)_msg);
66    _msg = r._msg ? strdup(r._msg) : nullptr;
67    _verbosity = r._verbosity;
68    _fileName = r._fileName;
69    _lineNumber = r._lineNumber;
70    _time = r._time;
71    _processName = r._processName;
72    _id = r._id;
73    return *this;
74}
75
76sc_report::~sc_report() throw()
77{
78    free((void *)_msgType);
79    free((void *)_msg);
80}
81
82const char *
83sc_report::what() const throw()
84{
85    return _what.c_str();
86}
87
88const char *
89sc_report::get_message(int id)
90{
91    auto it = sc_gem5::reportIdToMsgMap.find(id);
92    if (it == sc_gem5::reportIdToMsgMap.end())
93        return "unknown id";
94    else
95        return it->second.c_str();
96}
97
98bool
99sc_report::is_suppressed(int id)
100{
101    auto it = sc_gem5::reportIdToMsgMap.find(id);
102    if (it == sc_gem5::reportIdToMsgMap.end())
103        return false;
104
105    return sc_gem5::reportMsgInfoMap[it->second].actions == SC_DO_NOTHING;
106}
107
108void
109sc_report::make_warnings_errors(bool val)
110{
111    sc_gem5::reportWarningsAsErrors = val;
112}
113
114void
115sc_report::register_id(int id, const char *msg)
116{
117    if (id < 0) {
118        SC_REPORT_ERROR("(E800) register_id failed", "invalid report id");
119        return;
120    }
121    if (!msg) {
122        SC_REPORT_ERROR("(E800) register_id failed", "invalid report message");
123        return;
124    }
125    auto p = sc_gem5::reportIdToMsgMap.insert(
126            std::pair<int, std::string>(id, msg));
127    if (!p.second) {
128        SC_REPORT_ERROR("(E800) register_id failed",
129                "report id already exists");
130    } else {
131        sc_gem5::reportMsgInfoMap[msg].id = id;
132    }
133}
134
135void
136sc_report::suppress_id(int id, bool suppress)
137{
138    auto it = sc_gem5::reportIdToMsgMap.find(id);
139    if (it == sc_gem5::reportIdToMsgMap.end())
140        return;
141
142    if (suppress)
143        sc_gem5::reportMsgInfoMap[it->second].actions = SC_DO_NOTHING;
144    else
145        sc_gem5::reportMsgInfoMap[it->second].actions = SC_UNSPECIFIED;
146}
147
148void
149sc_report::suppress_infos(bool suppress)
150{
151    if (suppress)
152        sc_gem5::reportSevInfos[SC_INFO].actions = SC_DO_NOTHING;
153    else
154        sc_gem5::reportSevInfos[SC_INFO].actions = SC_DEFAULT_INFO_ACTIONS;
155}
156
157void
158sc_report::suppress_warnings(bool suppress)
159{
160    if (suppress) {
161        sc_gem5::reportSevInfos[SC_WARNING].actions = SC_DO_NOTHING;
162    } else {
163        sc_gem5::reportSevInfos[SC_WARNING].actions =
164            SC_DEFAULT_WARNING_ACTIONS;
165    }
166}
167
168void
169sc_abort()
170{
171    panic("simulation aborted");
172}
173
174} // namespace sc_core
175