From 8aa9f52953dfe5bd6bf53e6d509d06cc343534d5 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 5 Jan 2023 03:24:29 +0000 Subject: [PATCH] systemc: Add facilities to add extra SystemC message handlers Some clients (e.g. fastmodel integration) would like to catch specific warning messages from SystemC. Adding facilities to chain extra report handler (instead of just replacing the default one), that are run after the default/set handler. Change-Id: I8ef140fc897ae5eee0fc78c70caf081f625efbfd Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67234 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/systemc/utils/report.cc | 25 +++++++++++++++++++++++++ src/systemc/utils/report.hh | 8 ++++++++ src/systemc/utils/sc_report_handler.cc | 4 ++++ 3 files changed, 37 insertions(+) diff --git a/src/systemc/utils/report.cc b/src/systemc/utils/report.cc index 2b15fced8c..5f3425f398 100644 --- a/src/systemc/utils/report.cc +++ b/src/systemc/utils/report.cc @@ -68,6 +68,31 @@ sc_core::sc_actions reportCatchActions = sc_core::SC_DISPLAY; sc_core::sc_report_handler_proc reportHandlerProc = &sc_core::sc_report_handler::default_handler; +namespace +{ + +std::list extraReportHandlerProcs; + +} // anonymous namespace + +const std::list & +getExtraSystemCReportHandlers() +{ + return extraReportHandlerProcs; +} + +void +addExtraSystemCReportHandler(sc_core::sc_report_handler_proc proc) +{ + extraReportHandlerProcs.push_back(proc); +} + +void +removeExtraSystemCReportHandler(sc_core::sc_report_handler_proc proc) +{ + extraReportHandlerProcs.remove(proc); +} + std::unique_ptr globalReportCache; bool reportWarningsAsErrors = false; diff --git a/src/systemc/utils/report.hh b/src/systemc/utils/report.hh index 1f12eef6a8..d7ea3401e3 100644 --- a/src/systemc/utils/report.hh +++ b/src/systemc/utils/report.hh @@ -29,6 +29,7 @@ #define __SYSTEMC_UTILS_REPORT_HH__ #include +#include #include #include #include @@ -103,6 +104,13 @@ extern sc_core::sc_actions reportCatchActions; extern sc_core::sc_report_handler_proc reportHandlerProc; +// gem5-specific support for extra SystemC report handlers. Called _after_ +// the default/set handler. +const std::list + &getExtraSystemCReportHandlers(); +void addExtraSystemCReportHandler(sc_core::sc_report_handler_proc proc); +void removeExtraSystemCReportHandler(sc_core::sc_report_handler_proc proc); + extern std::unique_ptr globalReportCache; extern bool reportWarningsAsErrors; diff --git a/src/systemc/utils/sc_report_handler.cc b/src/systemc/utils/sc_report_handler.cc index b893b1dff3..3421ab912d 100644 --- a/src/systemc/utils/sc_report_handler.cc +++ b/src/systemc/utils/sc_report_handler.cc @@ -103,6 +103,10 @@ sc_report_handler::report(sc_severity severity, const char *msg_type, } sc_gem5::reportHandlerProc(report, actions); + + for (auto& handler : sc_gem5::getExtraSystemCReportHandlers()) { + handler(report, actions); + } } void