sc_report_handler.hh revision 12852
112852Sgabeblack@google.com/*
212852Sgabeblack@google.com * Copyright 2018 Google, Inc.
312852Sgabeblack@google.com *
412852Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512852Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612852Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812852Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012852Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112852Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212852Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312852Sgabeblack@google.com * this software without specific prior written permission.
1412852Sgabeblack@google.com *
1512852Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612852Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712852Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812852Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912852Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012852Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112852Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212852Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312852Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412852Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512852Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612852Sgabeblack@google.com *
2712852Sgabeblack@google.com * Authors: Gabe Black
2812852Sgabeblack@google.com */
2912852Sgabeblack@google.com
3012852Sgabeblack@google.com#ifndef __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
3112852Sgabeblack@google.com#define __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
3212852Sgabeblack@google.com
3312852Sgabeblack@google.com#include "sc_report.hh" // for sc_severity
3412852Sgabeblack@google.com
3512852Sgabeblack@google.comnamespace sc_core
3612852Sgabeblack@google.com{
3712852Sgabeblack@google.com
3812852Sgabeblack@google.comtypedef unsigned sc_actions;
3912852Sgabeblack@google.com
4012852Sgabeblack@google.comenum
4112852Sgabeblack@google.com{
4212852Sgabeblack@google.com    SC_UNSPECIFIED = 0x0000,
4312852Sgabeblack@google.com    SC_DO_NOTHING = 0x0001,
4412852Sgabeblack@google.com    SC_THROW = 0x0002,
4512852Sgabeblack@google.com    SC_LOG = 0x0004,
4612852Sgabeblack@google.com    SC_DISPLAY = 0x0008,
4712852Sgabeblack@google.com    SC_CACHE_REPORT = 0x0010,
4812852Sgabeblack@google.com    SC_INTERRUPT = 0x0020,
4912852Sgabeblack@google.com    SC_STOP = 0x0040,
5012852Sgabeblack@google.com    SC_ABORT = 0x0080
5112852Sgabeblack@google.com};
5212852Sgabeblack@google.com
5312852Sgabeblack@google.com#define SC_DEFAULT_INFO_ACTIONS \
5412852Sgabeblack@google.com        (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY)
5512852Sgabeblack@google.com#define SC_DEFAULT_WARNING_ACTIONS \
5612852Sgabeblack@google.com        (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY)
5712852Sgabeblack@google.com#define SC_DEFAULT_ERROR_ACTIONS \
5812852Sgabeblack@google.com        (::sc_core::SC_LOG | ::sc_core::SC_CACHE_REPORT | ::sc_core::SC_THROW)
5912852Sgabeblack@google.com#define SC_DEFAULT_FATAL_ACTIONS \
6012852Sgabeblack@google.com        (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY | \
6112852Sgabeblack@google.com         ::sc_core::SC_CACHE_REPORT | ::sc_core::SC_ABORT)
6212852Sgabeblack@google.com
6312852Sgabeblack@google.comtypedef void (*sc_report_handler_proc)(const sc_report &, const sc_actions &);
6412852Sgabeblack@google.com
6512852Sgabeblack@google.comclass sc_report_handler
6612852Sgabeblack@google.com{
6712852Sgabeblack@google.com  public:
6812852Sgabeblack@google.com    static void report(sc_severity, const char *msg_type, const char *msg,
6912852Sgabeblack@google.com                       const char *file, int line);
7012852Sgabeblack@google.com    static void report(sc_severity, const char *msg_type, const char *msg,
7112852Sgabeblack@google.com                       int verbosity, const char *file, int line);
7212852Sgabeblack@google.com
7312852Sgabeblack@google.com    static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED);
7412852Sgabeblack@google.com    static sc_actions set_actions(const char *msg_type,
7512852Sgabeblack@google.com                                  sc_actions=SC_UNSPECIFIED);
7612852Sgabeblack@google.com    static sc_actions set_actions(const char *msg_type, sc_severity,
7712852Sgabeblack@google.com                                  sc_actions=SC_UNSPECIFIED);
7812852Sgabeblack@google.com
7912852Sgabeblack@google.com    static int stop_after(sc_severity, int limit=-1);
8012852Sgabeblack@google.com    static int stop_after(const char *msg_type, int limit=-1);
8112852Sgabeblack@google.com    static int stop_after(const char *msg_type, sc_severity,
8212852Sgabeblack@google.com                          sc_actions=SC_UNSPECIFIED);
8312852Sgabeblack@google.com
8412852Sgabeblack@google.com    static int get_count(sc_severity);
8512852Sgabeblack@google.com    static int get_count(const char *msg_type);
8612852Sgabeblack@google.com    static int get_count(const char *msg_type, sc_severity);
8712852Sgabeblack@google.com
8812852Sgabeblack@google.com    int set_verbosity_level(int);
8912852Sgabeblack@google.com    int get_verbosity_level();
9012852Sgabeblack@google.com
9112852Sgabeblack@google.com    static sc_actions suppress(sc_actions);
9212852Sgabeblack@google.com    static sc_actions suppress();
9312852Sgabeblack@google.com    static sc_actions force(sc_actions);
9412852Sgabeblack@google.com    static sc_actions force();
9512852Sgabeblack@google.com
9612852Sgabeblack@google.com    static void set_handler(sc_report_handler_proc);
9712852Sgabeblack@google.com    static void default_handler(const sc_report &, const sc_actions &);
9812852Sgabeblack@google.com    static sc_actions get_new_action_id();
9912852Sgabeblack@google.com
10012852Sgabeblack@google.com    static sc_report *get_cached_report();
10112852Sgabeblack@google.com    static void clear_cached_report();
10212852Sgabeblack@google.com
10312852Sgabeblack@google.com    static bool set_log_file_name(const char *);
10412852Sgabeblack@google.com    static const char *get_log_file_name();
10512852Sgabeblack@google.com};
10612852Sgabeblack@google.com
10712852Sgabeblack@google.com#define SC_REPORT_INFO_VERB(msg_type, msg, verbosity) \
10812852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
10912852Sgabeblack@google.com            ::sc_core::SC_INFO, msg_type, msg, verbosity, __FILE__, __LINE__)
11012852Sgabeblack@google.com
11112852Sgabeblack@google.com#define SC_REPORT_INFO(msg_type, msg) \
11212852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
11312852Sgabeblack@google.com            ::sc_core::SC_INFO, msg_type, msg, __FILE__, __LINE__)
11412852Sgabeblack@google.com
11512852Sgabeblack@google.com#define SC_REPORT_WARNING(msg_type, msg) \
11612852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
11712852Sgabeblack@google.com            ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__)
11812852Sgabeblack@google.com
11912852Sgabeblack@google.com#define SC_REPORT_ERROR(msg_type, msg) \
12012852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
12112852Sgabeblack@google.com            ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__)
12212852Sgabeblack@google.com
12312852Sgabeblack@google.com#define SC_REPORT_FATAL(msg_type, msg) \
12412852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
12512852Sgabeblack@google.com            ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__)
12612852Sgabeblack@google.com
12712852Sgabeblack@google.com#define sc_assert(expr) \
12812852Sgabeblack@google.com        ((void)((expr) ? 0 : (SC_REPORT_FATAL("assertion failed", #expr), 0)))
12912852Sgabeblack@google.com
13012852Sgabeblack@google.comvoid sc_interrupt_here(const char *msg_type, sc_severity);
13112852Sgabeblack@google.comvoid sc_stop_here(const char *msg_type, sc_severity);
13212852Sgabeblack@google.com
13312852Sgabeblack@google.com} // namespace sc_core
13412852Sgabeblack@google.com
13512852Sgabeblack@google.com#endif  //__SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
136