1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__ 31#define __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__ 32 33#include <string> 34
| 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#ifndef __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__ 31#define __SYSTEMC_EXT_UTIL_SC_REPORT_HANDLER_HH__ 32 33#include <string> 34
|
35#include "sc_report.hh" // for sc_severity 36 37namespace sc_core 38{ 39 40typedef unsigned sc_actions; 41 42enum 43{ 44 SC_UNSPECIFIED = 0x0000, 45 SC_DO_NOTHING = 0x0001, 46 SC_THROW = 0x0002, 47 SC_LOG = 0x0004, 48 SC_DISPLAY = 0x0008, 49 SC_CACHE_REPORT = 0x0010, 50 SC_INTERRUPT = 0x0020, 51 SC_STOP = 0x0040, 52 SC_ABORT = 0x0080, 53 54 // The spec says these should be macros, but that breaks the build for the 55 // regression tests since they refer to, for instance, 56 // sc_core::SC_DEFAULT_INFO_ACTIONS. 57 SC_DEFAULT_INFO_ACTIONS = SC_LOG | SC_DISPLAY, 58 SC_DEFAULT_WARNING_ACTIONS = SC_LOG | SC_DISPLAY, 59 SC_DEFAULT_ERROR_ACTIONS = SC_LOG | SC_CACHE_REPORT | SC_THROW, 60 SC_DEFAULT_FATAL_ACTIONS = SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT 61}; 62 63typedef void (*sc_report_handler_proc)(const sc_report &, const sc_actions &); 64 65class sc_report_handler 66{ 67 public: 68 static void report(sc_severity, const char *msg_type, const char *msg, 69 const char *file, int line); 70 static void report(sc_severity, const char *msg_type, const char *msg, 71 int verbosity, const char *file, int line); 72 73 // Deprecated 74 static void report(sc_severity, int id, const char *msg, const char *file, 75 int line); 76 77 static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED); 78 static sc_actions set_actions(const char *msg_type, 79 sc_actions=SC_UNSPECIFIED); 80 static sc_actions set_actions(const char *msg_type, sc_severity, 81 sc_actions=SC_UNSPECIFIED); 82 83 static int stop_after(sc_severity, int limit=-1); 84 static int stop_after(const char *msg_type, int limit=-1); 85 static int stop_after(const char *msg_type, sc_severity, int limit=-1); 86 87 static int get_count(sc_severity); 88 static int get_count(const char *msg_type); 89 static int get_count(const char *msg_type, sc_severity); 90 91 // Nonstandard 92 // In the spec, these aren't listed as static functions. They are static in 93 // the Accellera implementation and are used as such in the tests. 94 static int set_verbosity_level(int); 95 static int get_verbosity_level(); 96 97 static sc_actions suppress(sc_actions); 98 static sc_actions suppress(); 99 static sc_actions force(sc_actions); 100 static sc_actions force(); 101 102 static sc_actions set_catch_actions(sc_actions); 103 static sc_actions get_catch_actions(); 104 105 static void set_handler(sc_report_handler_proc); 106 static void default_handler(const sc_report &, const sc_actions &); 107 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) \
| 36#include "sc_report.hh" // for sc_severity 37 38namespace sc_core 39{ 40 41typedef unsigned sc_actions; 42 43enum 44{ 45 SC_UNSPECIFIED = 0x0000, 46 SC_DO_NOTHING = 0x0001, 47 SC_THROW = 0x0002, 48 SC_LOG = 0x0004, 49 SC_DISPLAY = 0x0008, 50 SC_CACHE_REPORT = 0x0010, 51 SC_INTERRUPT = 0x0020, 52 SC_STOP = 0x0040, 53 SC_ABORT = 0x0080, 54 55 // The spec says these should be macros, but that breaks the build for the 56 // regression tests since they refer to, for instance, 57 // sc_core::SC_DEFAULT_INFO_ACTIONS. 58 SC_DEFAULT_INFO_ACTIONS = SC_LOG | SC_DISPLAY, 59 SC_DEFAULT_WARNING_ACTIONS = SC_LOG | SC_DISPLAY, 60 SC_DEFAULT_ERROR_ACTIONS = SC_LOG | SC_CACHE_REPORT | SC_THROW, 61 SC_DEFAULT_FATAL_ACTIONS = SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT 62}; 63 64typedef void (*sc_report_handler_proc)(const sc_report &, const sc_actions &); 65 66class sc_report_handler 67{ 68 public: 69 static void report(sc_severity, const char *msg_type, const char *msg, 70 const char *file, int line); 71 static void report(sc_severity, const char *msg_type, const char *msg, 72 int verbosity, const char *file, int line); 73 74 // Deprecated 75 static void report(sc_severity, int id, const char *msg, const char *file, 76 int line); 77 78 static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED); 79 static sc_actions set_actions(const char *msg_type, 80 sc_actions=SC_UNSPECIFIED); 81 static sc_actions set_actions(const char *msg_type, sc_severity, 82 sc_actions=SC_UNSPECIFIED); 83 84 static int stop_after(sc_severity, int limit=-1); 85 static int stop_after(const char *msg_type, int limit=-1); 86 static int stop_after(const char *msg_type, sc_severity, int limit=-1); 87 88 static int get_count(sc_severity); 89 static int get_count(const char *msg_type); 90 static int get_count(const char *msg_type, sc_severity); 91 92 // Nonstandard 93 // In the spec, these aren't listed as static functions. They are static in 94 // the Accellera implementation and are used as such in the tests. 95 static int set_verbosity_level(int); 96 static int get_verbosity_level(); 97 98 static sc_actions suppress(sc_actions); 99 static sc_actions suppress(); 100 static sc_actions force(sc_actions); 101 static sc_actions force(); 102 103 static sc_actions set_catch_actions(sc_actions); 104 static sc_actions get_catch_actions(); 105 106 static void set_handler(sc_report_handler_proc); 107 static void default_handler(const sc_report &, const sc_actions &); 108 static sc_actions get_new_action_id(); 109 110 static sc_report *get_cached_report(); 111 static void clear_cached_report(); 112 113 static bool set_log_file_name(const char *); 114 static const char *get_log_file_name(); 115}; 116 117#define SC_REPORT_INFO_VERB(msg_type, msg, verbosity) \ 118 ::sc_core::sc_report_handler::report( \ 119 ::sc_core::SC_INFO, msg_type, msg, verbosity, __FILE__, __LINE__) 120 121#define SC_REPORT_INFO(msg_type, msg) \ 122 ::sc_core::sc_report_handler::report( \ 123 ::sc_core::SC_INFO, msg_type, msg, __FILE__, __LINE__) 124 125#define SC_REPORT_WARNING(msg_type, msg) \ 126 ::sc_core::sc_report_handler::report( \ 127 ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__) 128 129#define SC_REPORT_ERROR(msg_type, msg) \ 130 ::sc_core::sc_report_handler::report( \ 131 ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__) 132 133#define SC_REPORT_FATAL(msg_type, msg) \ 134 ::sc_core::sc_report_handler::report( \ 135 ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__) 136 137#define sc_assert(expr) \
|