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