113312Sgabeblack@google.com/*
213312Sgabeblack@google.com * Copyright 2018 Google, Inc.
313312Sgabeblack@google.com *
413312Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
513312Sgabeblack@google.com * modification, are permitted provided that the following conditions are
613312Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
713312Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
813312Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
913312Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1013312Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1113312Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1213312Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1313312Sgabeblack@google.com * this software without specific prior written permission.
1413312Sgabeblack@google.com *
1513312Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1613312Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1713312Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1813312Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1913312Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2013312Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2113312Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2213312Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2313312Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2413312Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2513312Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2613312Sgabeblack@google.com *
2713312Sgabeblack@google.com * Authors: Gabe Black
2813312Sgabeblack@google.com */
2913312Sgabeblack@google.com
3013312Sgabeblack@google.com#ifndef __SYSTEMC_UTILS_REPORT_HH__
3113312Sgabeblack@google.com#define __SYSTEMC_UTILS_REPORT_HH__
3213312Sgabeblack@google.com
3313316Sgabeblack@google.com#include <initializer_list>
3413312Sgabeblack@google.com#include <map>
3513312Sgabeblack@google.com#include <memory>
3613312Sgabeblack@google.com#include <string>
3713316Sgabeblack@google.com#include <utility>
3813312Sgabeblack@google.com
3913312Sgabeblack@google.com#include "systemc/ext/utils/sc_report.hh"
4013312Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
4113312Sgabeblack@google.com
4213312Sgabeblack@google.comnamespace sc_gem5
4313312Sgabeblack@google.com{
4413312Sgabeblack@google.com
4513312Sgabeblack@google.comstruct ReportMsgInfo
4613312Sgabeblack@google.com{
4713312Sgabeblack@google.com    explicit ReportMsgInfo() :
4813312Sgabeblack@google.com        actions(sc_core::SC_UNSPECIFIED), count(0), limit(-1),
4913312Sgabeblack@google.com        sevActions{ sc_core::SC_UNSPECIFIED, sc_core::SC_UNSPECIFIED,
5013312Sgabeblack@google.com                sc_core::SC_UNSPECIFIED, sc_core::SC_UNSPECIFIED },
5113312Sgabeblack@google.com        sevCounts{0, 0, 0, 0}, sevLimits{-1, -1, -1, -1}, id(-1)
5213312Sgabeblack@google.com    {}
5313312Sgabeblack@google.com
5413312Sgabeblack@google.com    void
5513312Sgabeblack@google.com    checkLimits(sc_core::sc_severity severity, sc_core::sc_actions &actions)
5613312Sgabeblack@google.com    {
5713312Sgabeblack@google.com        int sevLimit = sevLimits[severity];
5813312Sgabeblack@google.com        int sevCount = sevCounts[severity];
5913312Sgabeblack@google.com        if ((limit != -1 && limit >= count) ||
6013312Sgabeblack@google.com                (sevLimit != 1 && sevLimit >= sevCount)) {
6113312Sgabeblack@google.com            actions |= sc_core::SC_STOP;
6213312Sgabeblack@google.com        }
6313312Sgabeblack@google.com    }
6413312Sgabeblack@google.com
6513312Sgabeblack@google.com    sc_core::sc_actions actions;
6613312Sgabeblack@google.com    int count;
6713312Sgabeblack@google.com    int limit;
6813312Sgabeblack@google.com
6913312Sgabeblack@google.com    sc_core::sc_actions sevActions[sc_core::SC_MAX_SEVERITY];
7013312Sgabeblack@google.com    int sevCounts[sc_core::SC_MAX_SEVERITY];
7113312Sgabeblack@google.com    int sevLimits[sc_core::SC_MAX_SEVERITY];
7213312Sgabeblack@google.com
7313312Sgabeblack@google.com    int id;
7413312Sgabeblack@google.com};
7513312Sgabeblack@google.com
7613312Sgabeblack@google.comstruct ReportSevInfo
7713312Sgabeblack@google.com{
7813312Sgabeblack@google.com    explicit ReportSevInfo(sc_core::sc_actions actions) :
7913312Sgabeblack@google.com        actions(actions), count(0), limit(-1)
8013312Sgabeblack@google.com    {}
8113312Sgabeblack@google.com
8213312Sgabeblack@google.com    void
8313312Sgabeblack@google.com    checkLimit(sc_core::sc_actions &actions)
8413312Sgabeblack@google.com    {
8513312Sgabeblack@google.com        if (limit != -1 && limit >= count)
8613312Sgabeblack@google.com            actions |= sc_core::SC_STOP;
8713312Sgabeblack@google.com    }
8813312Sgabeblack@google.com
8913312Sgabeblack@google.com    sc_core::sc_actions actions;
9013312Sgabeblack@google.com    int count;
9113312Sgabeblack@google.com    int limit;
9213312Sgabeblack@google.com};
9313312Sgabeblack@google.com
9413312Sgabeblack@google.comextern const char *reportSeverityNames[sc_core::SC_MAX_SEVERITY];
9513312Sgabeblack@google.comextern ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY];
9613401Sgabeblack@google.com
9713401Sgabeblack@google.comstd::map<std::string, ReportMsgInfo> &reportMsgInfoMap();
9813401Sgabeblack@google.comstd::map<int, std::string> &reportIdToMsgMap();
9913312Sgabeblack@google.com
10013312Sgabeblack@google.comextern int reportVerbosityLevel;
10113312Sgabeblack@google.com
10213312Sgabeblack@google.comextern sc_core::sc_actions reportSuppressedActions;
10313312Sgabeblack@google.comextern sc_core::sc_actions reportForcedActions;
10413312Sgabeblack@google.comextern sc_core::sc_actions reportCatchActions;
10513312Sgabeblack@google.com
10613312Sgabeblack@google.comextern sc_core::sc_report_handler_proc reportHandlerProc;
10713312Sgabeblack@google.com
10813312Sgabeblack@google.comextern std::unique_ptr<sc_core::sc_report> globalReportCache;
10913312Sgabeblack@google.com
11013313Sgabeblack@google.comextern bool reportWarningsAsErrors;
11113313Sgabeblack@google.com
11213316Sgabeblack@google.comstruct DefaultReportMessages
11313316Sgabeblack@google.com{
11413316Sgabeblack@google.com  public:
11513316Sgabeblack@google.com    DefaultReportMessages(std::initializer_list<std::pair<int, const char *>>);
11613316Sgabeblack@google.com};
11713316Sgabeblack@google.com
11813312Sgabeblack@google.com} // namespace sc_gem5
11913312Sgabeblack@google.com
12013312Sgabeblack@google.com#endif // __SYSTEMC_UTILS_REPORT_HH__
121