#include "systemc/core/scheduler.hh"
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/utils/sc_report_handler.hh"
+#include "systemc/utils/report.hh"
// A weak symbol to detect if sc_main has been defined, and if so where it is.
[[gnu::weak]] int sc_main(int argc, char *argv[]);
} catch (const sc_report &r) {
// There was an exception nobody caught.
resultStr = "uncaught sc_report";
- sc_report_handler::get_handler()(
+ sc_gem5::reportHandlerProc(
r, sc_report_handler::get_catch_actions());
} catch (...) {
// There was some other type of exception we need to wrap.
resultStr = "uncaught exception";
- sc_report_handler::get_handler()(
+ sc_gem5::reportHandlerProc(
::sc_gem5::reportifyException(),
sc_report_handler::get_catch_actions());
}
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/utils/sc_report.hh"
#include "systemc/ext/utils/sc_report_handler.hh"
+#include "systemc/utils/report.hh"
#include "systemc/utils/tracefile.hh"
namespace sc_gem5
const ::sc_core::sc_report
reportifyException()
{
- ::sc_core::sc_report_handler_proc old_handler =
- ::sc_core::sc_report_handler::get_handler();
+ ::sc_core::sc_report_handler_proc old_handler = reportHandlerProc;
::sc_core::sc_report_handler::set_handler(&throwingReportHandler);
try {
static void set_handler(sc_report_handler_proc);
static void default_handler(const sc_report &, const sc_actions &);
static sc_actions get_new_action_id();
- // Nonstandard
- // Returns the current handler so it can be restored if it needs to be
- // changed temporarily.
- static sc_report_handler_proc get_handler();
static sc_report *get_cached_report();
static void clear_cached_report();
if env['USE_SYSTEMC']:
Source('functions.cc')
+ Source('report.cc')
Source('sc_report.cc')
Source('sc_report_handler.cc')
Source('sc_trace_file.cc')
--- /dev/null
+/*
+ * Copyright 2018 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#include "systemc/utils/report.hh"
+
+namespace sc_gem5
+{
+
+const char *reportSeverityNames[] = {
+ [sc_core::SC_INFO] = "Info",
+ [sc_core::SC_WARNING] = "Warning",
+ [sc_core::SC_ERROR] = "Error",
+ [sc_core::SC_FATAL] = "Fatal"
+};
+
+ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY] =
+{
+ [sc_core::SC_INFO] = ReportSevInfo(sc_core::SC_DEFAULT_INFO_ACTIONS),
+ [sc_core::SC_WARNING] = ReportSevInfo(sc_core::SC_DEFAULT_WARNING_ACTIONS),
+ [sc_core::SC_ERROR] = ReportSevInfo(sc_core::SC_DEFAULT_ERROR_ACTIONS),
+ [sc_core::SC_FATAL] = ReportSevInfo(sc_core::SC_DEFAULT_FATAL_ACTIONS)
+};
+
+std::map<std::string, ReportMsgInfo> reportMsgInfoMap;
+
+int reportVerbosityLevel = sc_core::SC_MEDIUM;
+
+sc_core::sc_actions reportSuppressedActions = sc_core::SC_UNSPECIFIED;
+sc_core::sc_actions reportForcedActions = sc_core::SC_UNSPECIFIED;
+sc_core::sc_actions reportCatchActions = sc_core::SC_DISPLAY;
+
+sc_core::sc_report_handler_proc reportHandlerProc =
+ &sc_core::sc_report_handler::default_handler;
+
+std::unique_ptr<sc_core::sc_report> globalReportCache;
+
+} // namespace sc_gem5
--- /dev/null
+/*
+ * Copyright 2018 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#ifndef __SYSTEMC_UTILS_REPORT_HH__
+#define __SYSTEMC_UTILS_REPORT_HH__
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "systemc/ext/utils/sc_report.hh"
+#include "systemc/ext/utils/sc_report_handler.hh"
+
+namespace sc_gem5
+{
+
+struct ReportMsgInfo
+{
+ explicit ReportMsgInfo() :
+ actions(sc_core::SC_UNSPECIFIED), count(0), limit(-1),
+ sevActions{ sc_core::SC_UNSPECIFIED, sc_core::SC_UNSPECIFIED,
+ sc_core::SC_UNSPECIFIED, sc_core::SC_UNSPECIFIED },
+ sevCounts{0, 0, 0, 0}, sevLimits{-1, -1, -1, -1}, id(-1)
+ {}
+
+ void
+ checkLimits(sc_core::sc_severity severity, sc_core::sc_actions &actions)
+ {
+ int sevLimit = sevLimits[severity];
+ int sevCount = sevCounts[severity];
+ if ((limit != -1 && limit >= count) ||
+ (sevLimit != 1 && sevLimit >= sevCount)) {
+ actions |= sc_core::SC_STOP;
+ }
+ }
+
+ sc_core::sc_actions actions;
+ int count;
+ int limit;
+
+ sc_core::sc_actions sevActions[sc_core::SC_MAX_SEVERITY];
+ int sevCounts[sc_core::SC_MAX_SEVERITY];
+ int sevLimits[sc_core::SC_MAX_SEVERITY];
+
+ int id;
+};
+
+struct ReportSevInfo
+{
+ explicit ReportSevInfo(sc_core::sc_actions actions) :
+ actions(actions), count(0), limit(-1)
+ {}
+
+ void
+ checkLimit(sc_core::sc_actions &actions)
+ {
+ if (limit != -1 && limit >= count)
+ actions |= sc_core::SC_STOP;
+ }
+
+ sc_core::sc_actions actions;
+ int count;
+ int limit;
+};
+
+extern const char *reportSeverityNames[sc_core::SC_MAX_SEVERITY];
+extern ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY];
+extern std::map<std::string, ReportMsgInfo> reportMsgInfoMap;
+
+extern int reportVerbosityLevel;
+
+extern sc_core::sc_actions reportSuppressedActions;
+extern sc_core::sc_actions reportForcedActions;
+extern sc_core::sc_actions reportCatchActions;
+
+extern sc_core::sc_report_handler_proc reportHandlerProc;
+
+extern std::unique_ptr<sc_core::sc_report> globalReportCache;
+
+} // namespace sc_gem5
+
+#endif // __SYSTEMC_UTILS_REPORT_HH__
#include "systemc/core/scheduler.hh"
#include "systemc/ext/core/sc_main.hh"
#include "systemc/ext/utils/sc_report_handler.hh"
+#include "systemc/utils/report.hh"
namespace sc_core
{
std::unique_ptr<std::string> logFileName;
std::unique_ptr<std::ofstream> logFile;
-struct ReportCatInfo
-{
- explicit ReportCatInfo(sc_actions actions) :
- actions(actions), count(0), limit(-1)
- {}
- ReportCatInfo() : ReportCatInfo(SC_UNSPECIFIED) {}
-
- bool
- checkLimit(sc_actions &actions)
- {
- if (limit == 0 || count < limit)
- return false;
- if (limit != -1)
- actions |= SC_STOP;
- return true;
- }
-
- sc_actions actions;
- int count;
- int limit;
-};
-
-const char *severityNames[] = {
- [SC_INFO] = "Info",
- [SC_WARNING] = "Warning",
- [SC_ERROR] = "Error",
- [SC_FATAL] = "Fatal"
-};
-
-ReportCatInfo catForSeverity[SC_MAX_SEVERITY] =
-{
- [SC_INFO] = ReportCatInfo(SC_DEFAULT_INFO_ACTIONS),
- [SC_WARNING] = ReportCatInfo(SC_DEFAULT_WARNING_ACTIONS),
- [SC_ERROR] = ReportCatInfo(SC_DEFAULT_ERROR_ACTIONS),
- [SC_FATAL] = ReportCatInfo(SC_DEFAULT_FATAL_ACTIONS)
-};
-
-std::map<std::string, ReportCatInfo> catForMsgType;
-std::map<std::pair<std::string, sc_severity>, ReportCatInfo>
- catForSeverityAndMsgType;
-
-int verbosityLevel = SC_MEDIUM;
-
-sc_actions suppressedActions = SC_UNSPECIFIED;
-sc_actions forcedActions = SC_UNSPECIFIED;
-sc_actions catchActions = SC_DISPLAY;
-
-sc_report_handler_proc reportHandlerProc = &sc_report_handler::default_handler;
-
-sc_actions maxAction = SC_ABORT;
-
-std::unique_ptr<sc_report> globalReportCache;
-
} // anonymous namespace
void
const char *msg, int verbosity, const char *file,
int line)
{
- if (severity == SC_INFO && verbosity > verbosityLevel)
+ if (severity == SC_INFO && verbosity > sc_gem5::reportVerbosityLevel)
return;
- ReportCatInfo &sevInfo = catForSeverity[severity];
- ReportCatInfo &msgInfo = catForMsgType[msg_type];
- ReportCatInfo &sevMsgInfo = catForSeverityAndMsgType[
- std::make_pair(std::string(msg_type), severity)];
+ sc_gem5::ReportSevInfo &sevInfo = sc_gem5::reportSevInfos[severity];
+ sc_gem5::ReportMsgInfo &msgInfo = sc_gem5::reportMsgInfoMap[msg_type];
sevInfo.count++;
msgInfo.count++;
- sevMsgInfo.count++;
+ msgInfo.sevCounts[severity]++;
sc_actions actions = SC_UNSPECIFIED;
- if (sevMsgInfo.actions != SC_UNSPECIFIED)
- actions = sevMsgInfo.actions;
+ if (msgInfo.sevActions[severity] != SC_UNSPECIFIED)
+ actions = msgInfo.sevActions[severity];
else if (msgInfo.actions != SC_UNSPECIFIED)
actions = msgInfo.actions;
else if (sevInfo.actions != SC_UNSPECIFIED)
actions = sevInfo.actions;
- actions &= ~suppressedActions;
- actions |= forcedActions;
+ actions &= ~sc_gem5::reportSuppressedActions;
+ actions |= sc_gem5::reportForcedActions;
- if (sevMsgInfo.checkLimit(actions) && msgInfo.checkLimit(actions))
- sevInfo.checkLimit(actions);
+ msgInfo.checkLimits(severity, actions);
+ sevInfo.checkLimit(actions);
::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
sc_report report(severity, msg_type, msg, verbosity, file, line,
if (current) {
current->lastReport(&report);
} else {
- globalReportCache =
+ sc_gem5::globalReportCache =
std::unique_ptr<sc_report>(new sc_report(report));
}
}
- reportHandlerProc(report, actions);
+ sc_gem5::reportHandlerProc(report, actions);
}
void
sc_actions
sc_report_handler::set_actions(sc_severity severity, sc_actions actions)
{
- ReportCatInfo &info = catForSeverity[severity];
+ sc_gem5::ReportSevInfo &info = sc_gem5::reportSevInfos[severity];
sc_actions previous = info.actions;
info.actions = actions;
return previous;
sc_actions
sc_report_handler::set_actions(const char *msg_type, sc_actions actions)
{
- ReportCatInfo &info = catForMsgType[msg_type];
+ sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type];
sc_actions previous = info.actions;
info.actions = actions;
return previous;
sc_report_handler::set_actions(
const char *msg_type, sc_severity severity, sc_actions actions)
{
- ReportCatInfo &info = catForSeverityAndMsgType[
- std::make_pair(std::string(msg_type), severity)];
- sc_actions previous = info.actions;
- info.actions = actions;
+ sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type];
+ sc_actions previous = info.sevActions[severity];
+ info.sevActions[severity] = actions;
return previous;
}
int
sc_report_handler::stop_after(sc_severity severity, int limit)
{
- ReportCatInfo &info = catForSeverity[severity];
+ sc_gem5::ReportSevInfo &info = sc_gem5::reportSevInfos[severity];
int previous = info.limit;
info.limit = limit;
return previous;
int
sc_report_handler::stop_after(const char *msg_type, int limit)
{
- ReportCatInfo &info = catForMsgType[msg_type];
+ sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type];
int previous = info.limit;
info.limit = limit;
return previous;
sc_report_handler::stop_after(
const char *msg_type, sc_severity severity, int limit)
{
- ReportCatInfo &info = catForSeverityAndMsgType[
- std::make_pair(std::string(msg_type), severity)];
- int previous = info.limit;
- info.limit = limit;
+ sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type];
+ int previous = info.sevLimits[severity];
+ info.sevLimits[severity] = limit;
return previous;
}
int
sc_report_handler::get_count(sc_severity severity)
{
- return catForSeverity[severity].count;
+ return sc_gem5::reportSevInfos[severity].count;
}
int
sc_report_handler::get_count(const char *msg_type)
{
- return catForMsgType[msg_type].count;
+ return sc_gem5::reportMsgInfoMap[msg_type].count;
}
int
sc_report_handler::get_count(const char *msg_type, sc_severity severity)
{
- return catForSeverityAndMsgType[
- std::make_pair(std::string(msg_type), severity)].count;
+ return sc_gem5::reportMsgInfoMap[msg_type].sevCounts[severity];
}
int
sc_report_handler::set_verbosity_level(int vl)
{
- int previous = verbosityLevel;
- verbosityLevel = vl;
+ int previous = sc_gem5::reportVerbosityLevel;
+ sc_gem5::reportVerbosityLevel = vl;
return previous;
}
int
sc_report_handler::get_verbosity_level()
{
- return verbosityLevel;
+ return sc_gem5::reportVerbosityLevel;
}
sc_actions
sc_report_handler::suppress(sc_actions actions)
{
- sc_actions previous = suppressedActions;
- suppressedActions = actions;
+ sc_actions previous = sc_gem5::reportSuppressedActions;
+ sc_gem5::reportSuppressedActions = actions;
return previous;
}
sc_actions
sc_report_handler::force(sc_actions actions)
{
- sc_actions previous = forcedActions;
- forcedActions = actions;
+ sc_actions previous = sc_gem5::reportForcedActions;
+ sc_gem5::reportForcedActions = actions;
return previous;
}
sc_actions
sc_report_handler::set_catch_actions(sc_actions actions)
{
- sc_actions previous = catchActions;
- catchActions = actions;
+ sc_actions previous = sc_gem5::reportCatchActions;
+ sc_gem5::reportCatchActions = actions;
return previous;
}
sc_actions
sc_report_handler::get_catch_actions()
{
- return catchActions;
+ return sc_gem5::reportCatchActions;
}
void
sc_report_handler::set_handler(sc_report_handler_proc proc)
{
- reportHandlerProc = proc;
+ sc_gem5::reportHandlerProc = proc;
}
void
sc_actions
sc_report_handler::get_new_action_id()
{
+ static sc_actions maxAction = SC_ABORT;
maxAction = maxAction << 1;
return maxAction;
}
-sc_report_handler_proc
-sc_report_handler::get_handler()
-{
- return reportHandlerProc;
-}
-
sc_report *
sc_report_handler::get_cached_report()
{
::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
if (current)
return current->lastReport();
- return globalReportCache.get();
+ return ::sc_gem5::globalReportCache.get();
}
void
if (current) {
current->lastReport(nullptr);
} else {
- globalReportCache = nullptr;
+ ::sc_gem5::globalReportCache = nullptr;
}
}
{
std::ostringstream str;
- const char *sevName = severityNames[report.get_severity()];
+ const char *sevName = sc_gem5::reportSeverityNames[report.get_severity()];
int id = report.get_id();
str << sevName << ": ";