From 1c110fafffdf82034e34146f90729ad92865238d Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 6 Nov 2018 17:48:58 -0800 Subject: systemc: Wrap some report maps in functions. By declaring the map as a static variable in that function and then returning it, we can guarantee that it's initialized relative to other static initializers so that we don't try to use a data structure that isn't constructed yet. This will let us get rid of the dependence on python for setting up that mapping. Change-Id: I031ce2039de8f5f79fbb9d76cf1363f15207b64b Reviewed-on: https://gem5-review.googlesource.com/c/13975 Maintainer: Gabe Black Reviewed-by: Jason Lowe-Power --- src/systemc/utils/report.cc | 15 +++++++++++++-- src/systemc/utils/report.hh | 5 +++-- src/systemc/utils/sc_report.cc | 26 +++++++++++++------------- src/systemc/utils/sc_report_handler.cc | 16 ++++++++-------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/systemc/utils/report.cc b/src/systemc/utils/report.cc index 87671f181..4a4521582 100644 --- a/src/systemc/utils/report.cc +++ b/src/systemc/utils/report.cc @@ -49,8 +49,19 @@ ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY] = [sc_core::SC_FATAL] = ReportSevInfo(sc_core::SC_DEFAULT_FATAL_ACTIONS) }; -std::map reportMsgInfoMap; -std::map reportIdToMsgMap; +std::map & +reportMsgInfoMap() +{ + static std::map m; + return m; +} + +std::map & +reportIdToMsgMap() +{ + static std::map m; + return m; +} int reportVerbosityLevel = sc_core::SC_MEDIUM; diff --git a/src/systemc/utils/report.hh b/src/systemc/utils/report.hh index a0840c65b..70716cb91 100644 --- a/src/systemc/utils/report.hh +++ b/src/systemc/utils/report.hh @@ -93,8 +93,9 @@ struct ReportSevInfo extern const char *reportSeverityNames[sc_core::SC_MAX_SEVERITY]; extern ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY]; -extern std::map reportMsgInfoMap; -extern std::map reportIdToMsgMap; + +std::map &reportMsgInfoMap(); +std::map &reportIdToMsgMap(); extern int reportVerbosityLevel; diff --git a/src/systemc/utils/sc_report.cc b/src/systemc/utils/sc_report.cc index 122facc24..a0491d3d5 100644 --- a/src/systemc/utils/sc_report.cc +++ b/src/systemc/utils/sc_report.cc @@ -89,8 +89,8 @@ sc_report::what() const throw() const char * sc_report::get_message(int id) { - auto it = sc_gem5::reportIdToMsgMap.find(id); - if (it == sc_gem5::reportIdToMsgMap.end()) + auto it = sc_gem5::reportIdToMsgMap().find(id); + if (it == sc_gem5::reportIdToMsgMap().end()) return "unknown id"; else return it->second.c_str(); @@ -99,11 +99,11 @@ sc_report::get_message(int id) bool sc_report::is_suppressed(int id) { - auto it = sc_gem5::reportIdToMsgMap.find(id); - if (it == sc_gem5::reportIdToMsgMap.end()) + auto it = sc_gem5::reportIdToMsgMap().find(id); + if (it == sc_gem5::reportIdToMsgMap().end()) return false; - auto &msgInfo = sc_gem5::reportMsgInfoMap[it->second]; + auto &msgInfo = sc_gem5::reportMsgInfoMap()[it->second]; return (msgInfo.actions == SC_DO_NOTHING || (msgInfo.sevActions[SC_INFO] == SC_DO_NOTHING && @@ -127,31 +127,31 @@ sc_report::register_id(int id, const char *msg) SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "invalid report message"); return; } - auto p = sc_gem5::reportIdToMsgMap.insert( + auto p = sc_gem5::reportIdToMsgMap().insert( std::pair(id, msg)); if (!p.second) { SC_REPORT_ERROR(SC_ID_REGISTER_ID_FAILED_, "report id already exists"); } else { - sc_gem5::reportMsgInfoMap[msg].id = id; + sc_gem5::reportMsgInfoMap()[msg].id = id; } } void sc_report::suppress_id(int id, bool suppress) { - auto it = sc_gem5::reportIdToMsgMap.find(id); - if (it == sc_gem5::reportIdToMsgMap.end()) + auto it = sc_gem5::reportIdToMsgMap().find(id); + if (it == sc_gem5::reportIdToMsgMap().end()) return; if (suppress) { - sc_gem5::reportMsgInfoMap[it->second]. + sc_gem5::reportMsgInfoMap()[it->second]. sevActions[SC_INFO] = SC_DO_NOTHING; - sc_gem5::reportMsgInfoMap[it->second]. + sc_gem5::reportMsgInfoMap()[it->second]. sevActions[SC_WARNING] = SC_DO_NOTHING; } else { - sc_gem5::reportMsgInfoMap[it->second]. + sc_gem5::reportMsgInfoMap()[it->second]. sevActions[SC_INFO] = SC_UNSPECIFIED; - sc_gem5::reportMsgInfoMap[it->second]. + sc_gem5::reportMsgInfoMap()[it->second]. sevActions[SC_WARNING] = SC_UNSPECIFIED; } } diff --git a/src/systemc/utils/sc_report_handler.cc b/src/systemc/utils/sc_report_handler.cc index ad0d3b84e..151c3c9c3 100644 --- a/src/systemc/utils/sc_report_handler.cc +++ b/src/systemc/utils/sc_report_handler.cc @@ -70,7 +70,7 @@ sc_report_handler::report(sc_severity severity, const char *msg_type, return; sc_gem5::ReportSevInfo &sevInfo = sc_gem5::reportSevInfos[severity]; - sc_gem5::ReportMsgInfo &msgInfo = sc_gem5::reportMsgInfoMap[msg_type]; + sc_gem5::ReportMsgInfo &msgInfo = sc_gem5::reportMsgInfoMap()[msg_type]; sevInfo.count++; msgInfo.count++; @@ -111,7 +111,7 @@ void sc_report_handler::report(sc_severity severity, int id, const char *msg, const char *file, int line) { - std::string &msg_type = sc_gem5::reportIdToMsgMap[id]; + std::string &msg_type = sc_gem5::reportIdToMsgMap()[id]; if (sc_gem5::reportWarningsAsErrors && severity == SC_WARNING) severity = SC_ERROR; @@ -134,7 +134,7 @@ sc_report_handler::set_actions(const char *msg_type, sc_actions actions) if (!msg_type) msg_type = SC_ID_UNKNOWN_ERROR_; - sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type]; + sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap()[msg_type]; sc_actions previous = info.actions; info.actions = actions; return previous; @@ -147,7 +147,7 @@ sc_report_handler::set_actions( if (!msg_type) msg_type = SC_ID_UNKNOWN_ERROR_; - sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type]; + sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap()[msg_type]; sc_actions previous = info.sevActions[severity]; info.sevActions[severity] = actions; return previous; @@ -168,7 +168,7 @@ sc_report_handler::stop_after(const char *msg_type, int limit) if (!msg_type) msg_type = SC_ID_UNKNOWN_ERROR_; - sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type]; + sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap()[msg_type]; int previous = info.limit; info.limit = limit; return previous; @@ -181,7 +181,7 @@ sc_report_handler::stop_after( if (!msg_type) msg_type = SC_ID_UNKNOWN_ERROR_; - sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap[msg_type]; + sc_gem5::ReportMsgInfo &info = sc_gem5::reportMsgInfoMap()[msg_type]; int previous = info.sevLimits[severity]; info.sevLimits[severity] = limit; return previous; @@ -199,7 +199,7 @@ sc_report_handler::get_count(const char *msg_type) if (!msg_type) msg_type = SC_ID_UNKNOWN_ERROR_; - return sc_gem5::reportMsgInfoMap[msg_type].count; + return sc_gem5::reportMsgInfoMap()[msg_type].count; } int @@ -208,7 +208,7 @@ sc_report_handler::get_count(const char *msg_type, sc_severity severity) if (!msg_type) msg_type = SC_ID_UNKNOWN_ERROR_; - return sc_gem5::reportMsgInfoMap[msg_type].sevCounts[severity]; + return sc_gem5::reportMsgInfoMap()[msg_type].sevCounts[severity]; } int -- cgit v1.2.3