sc_report_handler.hh revision 12997
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
3312921Sgabeblack@google.com#include <string>
3412921Sgabeblack@google.com
3512852Sgabeblack@google.com#include "sc_report.hh" // for sc_severity
3612852Sgabeblack@google.com
3712852Sgabeblack@google.comnamespace sc_core
3812852Sgabeblack@google.com{
3912852Sgabeblack@google.com
4012852Sgabeblack@google.comtypedef unsigned sc_actions;
4112852Sgabeblack@google.com
4212852Sgabeblack@google.comenum
4312852Sgabeblack@google.com{
4412852Sgabeblack@google.com    SC_UNSPECIFIED = 0x0000,
4512852Sgabeblack@google.com    SC_DO_NOTHING = 0x0001,
4612852Sgabeblack@google.com    SC_THROW = 0x0002,
4712852Sgabeblack@google.com    SC_LOG = 0x0004,
4812852Sgabeblack@google.com    SC_DISPLAY = 0x0008,
4912852Sgabeblack@google.com    SC_CACHE_REPORT = 0x0010,
5012852Sgabeblack@google.com    SC_INTERRUPT = 0x0020,
5112852Sgabeblack@google.com    SC_STOP = 0x0040,
5212875Sgabeblack@google.com    SC_ABORT = 0x0080,
5312875Sgabeblack@google.com
5412875Sgabeblack@google.com    // The spec says these should be macros, but that breaks the build for the
5512875Sgabeblack@google.com    // regression tests since they refer to, for instance,
5612875Sgabeblack@google.com    // sc_core::SC_DEFAULT_INFO_ACTIONS.
5712875Sgabeblack@google.com    SC_DEFAULT_INFO_ACTIONS = SC_LOG | SC_DISPLAY,
5812875Sgabeblack@google.com    SC_DEFAULT_WARNING_ACTIONS = SC_LOG | SC_DISPLAY,
5912875Sgabeblack@google.com    SC_DEFAULT_ERROR_ACTIONS = SC_LOG | SC_CACHE_REPORT | SC_THROW,
6012875Sgabeblack@google.com    SC_DEFAULT_FATAL_ACTIONS = SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT
6112852Sgabeblack@google.com};
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
7312902Sgabeblack@google.com    // Deprecated
7412902Sgabeblack@google.com    static void report(sc_severity, int id, const char *msg, const char *file,
7512902Sgabeblack@google.com                       int line);
7612902Sgabeblack@google.com
7712852Sgabeblack@google.com    static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED);
7812852Sgabeblack@google.com    static sc_actions set_actions(const char *msg_type,
7912852Sgabeblack@google.com                                  sc_actions=SC_UNSPECIFIED);
8012852Sgabeblack@google.com    static sc_actions set_actions(const char *msg_type, sc_severity,
8112852Sgabeblack@google.com                                  sc_actions=SC_UNSPECIFIED);
8212852Sgabeblack@google.com
8312852Sgabeblack@google.com    static int stop_after(sc_severity, int limit=-1);
8412852Sgabeblack@google.com    static int stop_after(const char *msg_type, int limit=-1);
8512997Sgabeblack@google.com    static int stop_after(const char *msg_type, sc_severity, int limit=-1);
8612852Sgabeblack@google.com
8712852Sgabeblack@google.com    static int get_count(sc_severity);
8812852Sgabeblack@google.com    static int get_count(const char *msg_type);
8912852Sgabeblack@google.com    static int get_count(const char *msg_type, sc_severity);
9012852Sgabeblack@google.com
9112932Sgabeblack@google.com    // Nonstandard
9212932Sgabeblack@google.com    // In the spec, these aren't listed as static functions. They are static in
9312932Sgabeblack@google.com    // the Accellera implementation and are used as such in the tests.
9412932Sgabeblack@google.com    static int set_verbosity_level(int);
9512932Sgabeblack@google.com    static int get_verbosity_level();
9612852Sgabeblack@google.com
9712852Sgabeblack@google.com    static sc_actions suppress(sc_actions);
9812852Sgabeblack@google.com    static sc_actions suppress();
9912852Sgabeblack@google.com    static sc_actions force(sc_actions);
10012852Sgabeblack@google.com    static sc_actions force();
10112852Sgabeblack@google.com
10212911Sgabeblack@google.com    static sc_actions set_catch_actions(sc_actions);
10312911Sgabeblack@google.com    static sc_actions get_catch_actions();
10412911Sgabeblack@google.com
10512852Sgabeblack@google.com    static void set_handler(sc_report_handler_proc);
10612852Sgabeblack@google.com    static void default_handler(const sc_report &, const sc_actions &);
10712852Sgabeblack@google.com    static sc_actions get_new_action_id();
10812852Sgabeblack@google.com
10912852Sgabeblack@google.com    static sc_report *get_cached_report();
11012852Sgabeblack@google.com    static void clear_cached_report();
11112852Sgabeblack@google.com
11212852Sgabeblack@google.com    static bool set_log_file_name(const char *);
11312852Sgabeblack@google.com    static const char *get_log_file_name();
11412852Sgabeblack@google.com};
11512852Sgabeblack@google.com
11612852Sgabeblack@google.com#define SC_REPORT_INFO_VERB(msg_type, msg, verbosity) \
11712852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
11812852Sgabeblack@google.com            ::sc_core::SC_INFO, msg_type, msg, verbosity, __FILE__, __LINE__)
11912852Sgabeblack@google.com
12012852Sgabeblack@google.com#define SC_REPORT_INFO(msg_type, msg) \
12112852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
12212852Sgabeblack@google.com            ::sc_core::SC_INFO, msg_type, msg, __FILE__, __LINE__)
12312852Sgabeblack@google.com
12412852Sgabeblack@google.com#define SC_REPORT_WARNING(msg_type, msg) \
12512852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
12612852Sgabeblack@google.com            ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__)
12712852Sgabeblack@google.com
12812852Sgabeblack@google.com#define SC_REPORT_ERROR(msg_type, msg) \
12912852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
13012852Sgabeblack@google.com            ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__)
13112852Sgabeblack@google.com
13212852Sgabeblack@google.com#define SC_REPORT_FATAL(msg_type, msg) \
13312852Sgabeblack@google.com        ::sc_core::sc_report_handler::report( \
13412852Sgabeblack@google.com            ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__)
13512852Sgabeblack@google.com
13612852Sgabeblack@google.com#define sc_assert(expr) \
13712852Sgabeblack@google.com        ((void)((expr) ? 0 : (SC_REPORT_FATAL("assertion failed", #expr), 0)))
13812852Sgabeblack@google.com
13912852Sgabeblack@google.comvoid sc_interrupt_here(const char *msg_type, sc_severity);
14012852Sgabeblack@google.comvoid sc_stop_here(const char *msg_type, sc_severity);
14112852Sgabeblack@google.com
14212921Sgabeblack@google.com// Nonstandard
14312921Sgabeblack@google.com// From Accellera, "not documented, but available".
14412921Sgabeblack@google.comconst std::string sc_report_compose_message(const sc_report &);
14512921Sgabeblack@google.combool sc_report_close_default_log();
14612921Sgabeblack@google.com
14712852Sgabeblack@google.com} // namespace sc_core
14812852Sgabeblack@google.com
14912852Sgabeblack@google.com#endif  //__SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
150