sc_report_handler.hh revision 13312:a7685ffbead8
14826Ssaidi@eecs.umich.edu/*
24826Ssaidi@eecs.umich.edu * Copyright 2018 Google, Inc.
34826Ssaidi@eecs.umich.edu *
44826Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
54826Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
64826Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
74826Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
84826Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
94826Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
104826Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
114826Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
124826Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
134826Ssaidi@eecs.umich.edu * this software without specific prior written permission.
144826Ssaidi@eecs.umich.edu *
154826Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
164826Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
174826Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
184826Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
194826Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
204826Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
214826Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
224826Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
234826Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244826Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
254826Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
264826Ssaidi@eecs.umich.edu *
274826Ssaidi@eecs.umich.edu * Authors: Gabe Black
284826Ssaidi@eecs.umich.edu */
294826Ssaidi@eecs.umich.edu
304826Ssaidi@eecs.umich.edu#ifndef __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
314826Ssaidi@eecs.umich.edu#define __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
324826Ssaidi@eecs.umich.edu
334826Ssaidi@eecs.umich.edu#include <string>
344826Ssaidi@eecs.umich.edu
354826Ssaidi@eecs.umich.edu#include "sc_report.hh" // for sc_severity
368706Sandreas.hansson@arm.com
374826Ssaidi@eecs.umich.edunamespace sc_core
384826Ssaidi@eecs.umich.edu{
395569Snate@binkert.org
404826Ssaidi@eecs.umich.edutypedef unsigned sc_actions;
415569Snate@binkert.org
427707Sgblack@eecs.umich.eduenum
434826Ssaidi@eecs.umich.edu{
444826Ssaidi@eecs.umich.edu    SC_UNSPECIFIED = 0x0000,
455958Sgblack@eecs.umich.edu    SC_DO_NOTHING = 0x0001,
464826Ssaidi@eecs.umich.edu    SC_THROW = 0x0002,
474826Ssaidi@eecs.umich.edu    SC_LOG = 0x0004,
485958Sgblack@eecs.umich.edu    SC_DISPLAY = 0x0008,
494826Ssaidi@eecs.umich.edu    SC_CACHE_REPORT = 0x0010,
505958Sgblack@eecs.umich.edu    SC_INTERRUPT = 0x0020,
514826Ssaidi@eecs.umich.edu    SC_STOP = 0x0040,
524826Ssaidi@eecs.umich.edu    SC_ABORT = 0x0080,
538706Sandreas.hansson@arm.com
544826Ssaidi@eecs.umich.edu    // The spec says these should be macros, but that breaks the build for the
554826Ssaidi@eecs.umich.edu    // regression tests since they refer to, for instance,
564826Ssaidi@eecs.umich.edu    // sc_core::SC_DEFAULT_INFO_ACTIONS.
574826Ssaidi@eecs.umich.edu    SC_DEFAULT_INFO_ACTIONS = SC_LOG | SC_DISPLAY,
584826Ssaidi@eecs.umich.edu    SC_DEFAULT_WARNING_ACTIONS = SC_LOG | SC_DISPLAY,
594826Ssaidi@eecs.umich.edu    SC_DEFAULT_ERROR_ACTIONS = SC_LOG | SC_CACHE_REPORT | SC_THROW,
605569Snate@binkert.org    SC_DEFAULT_FATAL_ACTIONS = SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT
614826Ssaidi@eecs.umich.edu};
624826Ssaidi@eecs.umich.edu
634826Ssaidi@eecs.umich.edutypedef void (*sc_report_handler_proc)(const sc_report &, const sc_actions &);
646329Sgblack@eecs.umich.edu
656329Sgblack@eecs.umich.educlass sc_report_handler
666329Sgblack@eecs.umich.edu{
676329Sgblack@eecs.umich.edu  public:
686329Sgblack@eecs.umich.edu    static void report(sc_severity, const char *msg_type, const char *msg,
696329Sgblack@eecs.umich.edu                       const char *file, int line);
706329Sgblack@eecs.umich.edu    static void report(sc_severity, const char *msg_type, const char *msg,
716329Sgblack@eecs.umich.edu                       int verbosity, const char *file, int line);
726329Sgblack@eecs.umich.edu
736329Sgblack@eecs.umich.edu    // Deprecated
746329Sgblack@eecs.umich.edu    static void report(sc_severity, int id, const char *msg, const char *file,
756329Sgblack@eecs.umich.edu                       int line);
766329Sgblack@eecs.umich.edu
776329Sgblack@eecs.umich.edu    static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED);
786329Sgblack@eecs.umich.edu    static sc_actions set_actions(const char *msg_type,
797720Sgblack@eecs.umich.edu                                  sc_actions=SC_UNSPECIFIED);
806329Sgblack@eecs.umich.edu    static sc_actions set_actions(const char *msg_type, sc_severity,
816329Sgblack@eecs.umich.edu                                  sc_actions=SC_UNSPECIFIED);
826329Sgblack@eecs.umich.edu
836329Sgblack@eecs.umich.edu    static int stop_after(sc_severity, int limit=-1);
846329Sgblack@eecs.umich.edu    static int stop_after(const char *msg_type, int limit=-1);
856329Sgblack@eecs.umich.edu    static int stop_after(const char *msg_type, sc_severity, int limit=-1);
866329Sgblack@eecs.umich.edu
876329Sgblack@eecs.umich.edu    static int get_count(sc_severity);
886329Sgblack@eecs.umich.edu    static int get_count(const char *msg_type);
896329Sgblack@eecs.umich.edu    static int get_count(const char *msg_type, sc_severity);
906329Sgblack@eecs.umich.edu
916329Sgblack@eecs.umich.edu    // Nonstandard
926329Sgblack@eecs.umich.edu    // In the spec, these aren't listed as static functions. They are static in
936329Sgblack@eecs.umich.edu    // the Accellera implementation and are used as such in the tests.
946329Sgblack@eecs.umich.edu    static int set_verbosity_level(int);
956329Sgblack@eecs.umich.edu    static int get_verbosity_level();
966329Sgblack@eecs.umich.edu
977693SAli.Saidi@ARM.com    static sc_actions suppress(sc_actions);
987693SAli.Saidi@ARM.com    static sc_actions suppress();
997693SAli.Saidi@ARM.com    static sc_actions force(sc_actions);
1007720Sgblack@eecs.umich.edu    static sc_actions force();
1017720Sgblack@eecs.umich.edu
1027720Sgblack@eecs.umich.edu    static sc_actions set_catch_actions(sc_actions);
1037693SAli.Saidi@ARM.com    static sc_actions get_catch_actions();
1047693SAli.Saidi@ARM.com
1057693SAli.Saidi@ARM.com    static void set_handler(sc_report_handler_proc);
1064826Ssaidi@eecs.umich.edu    static void default_handler(const sc_report &, const sc_actions &);
1074826Ssaidi@eecs.umich.edu    static sc_actions get_new_action_id();
108
109    static sc_report *get_cached_report();
110    static void clear_cached_report();
111
112    static bool set_log_file_name(const char *);
113    static const char *get_log_file_name();
114};
115
116#define SC_REPORT_INFO_VERB(msg_type, msg, verbosity) \
117        ::sc_core::sc_report_handler::report( \
118            ::sc_core::SC_INFO, msg_type, msg, verbosity, __FILE__, __LINE__)
119
120#define SC_REPORT_INFO(msg_type, msg) \
121        ::sc_core::sc_report_handler::report( \
122            ::sc_core::SC_INFO, msg_type, msg, __FILE__, __LINE__)
123
124#define SC_REPORT_WARNING(msg_type, msg) \
125        ::sc_core::sc_report_handler::report( \
126            ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__)
127
128#define SC_REPORT_ERROR(msg_type, msg) \
129        ::sc_core::sc_report_handler::report( \
130            ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__)
131
132#define SC_REPORT_FATAL(msg_type, msg) \
133        ::sc_core::sc_report_handler::report( \
134            ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__)
135
136#define sc_assert(expr) \
137        ((void)((expr) ? 0 : (SC_REPORT_FATAL("assertion failed", #expr), 0)))
138
139void sc_interrupt_here(const char *msg_type, sc_severity);
140void sc_stop_here(const char *msg_type, sc_severity);
141
142// Nonstandard
143// From Accellera, "not documented, but available".
144const std::string sc_report_compose_message(const sc_report &);
145bool sc_report_close_default_log();
146
147} // namespace sc_core
148
149#endif  //__SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__
150