-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreport.hpp
98 lines (94 loc) · 3.97 KB
/
report.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @file report.hpp
* @brief Improve reporting with macros, more overloads on `operator<<`,
* and other enhancements to `sc_report_handler`.
*
* See `ABOUT_REPORT.md` for more information.
*/
#ifndef REPORT_HPP
#define REPORT_HPP
#include <systemc>
#include <tlm>
#include <sstream>
#include <iomanip>
extern std::ostringstream mout;
#define HEX std::hex << std::showbase
#define DEC std::dec << std::noshowbase << std::setfill(' ')
#ifdef __SYNTHESIS__
#define REPORT(type,stream)
#define ASSERT(expr,stream)
#define SC_ALWAYS SC_NONE
#define SC_NEVER (1<<14)
#define SC_HYPER 1024
#define DEVID (std::string("(")+name()+")").c_str()
#define NOINFO(level,stream)
#define INFO(level,stream)
#define MESSAGE(stream)
#define MEND(level)
#define RULER(c)
#define TODO(stream)
#define NOT_YET_IMPLEMENTED()
#define DELETE_THIS_LINE(lno,message)
#else
#define REPORT(type,stream) \
do { \
mout << DEC << stream << std::ends; \
SC_REPORT_##type( MSGID, mout.str().c_str() ); \
mout.str( "" ); \
} while (0)
//
// Use the following to (A) add more information in the event of failure, and
// and (B) control sc_assert behavior (i.e. not unconditional abort on failure).
#ifndef NDEBUG
#define ASSERT(expr,stream) do {\
if(!(expr)) SC_REPORT_FATAL( "Assertion failed: ", # expr << " " << stream );\
} while (0)
#else
#define ASSERT(expr,stream)
#endif
//
#define SC_ALWAYS SC_NONE
#define SC_NEVER 16*KB
#define SC_HYPER 1024
#define DEVID ((std::string("(")+name()+")").c_str())
#define NOINFO(level,stream)
#define INFO(level,stream) \
do { \
if( sc_core::sc_report_handler::get_verbosity_level() >= (sc_core::SC_##level) ) {\
mout << DEC << stream << std::ends; \
if( (sc_core::SC_##level) > sc_core::SC_DEBUG ) { \
std::string id{"DEBUG("}; \
id+=__FILE__ ; id+=":"; id+=std::to_string(__LINE__)+")"; \
size_t p0=id.find("/"),p1=id.find_last_of("/"); \
if(p1!=std::string::npos) id.erase(p0,p1-p0+1); \
SC_REPORT_INFO_VERB( id.c_str(), mout.str().c_str(), (sc_core::SC_##level) ); \
} else \
SC_REPORT_INFO_VERB( MSGID, mout.str().c_str(), (sc_core::SC_##level) ); \
} \
mout.str( "" ); \
} while (0)
//
#define MESSAGE(stream) do { mout << stream; } while(0)
#define MEND(level) do { \
if( sc_core::sc_report_handler::get_verbosity_level() >= (sc_core::SC_##level) ) {\
mout << std::ends; \
SC_REPORT_INFO_VERB( MSGID, mout.str().c_str(), (sc_core::SC_##level)); \
} \
mout.str( "" ); \
} while (0)
#define RULER(c) MESSAGE( std::string( 80, c ) << "\n" )
//
#define TODO(stream) REPORT( WARNING, "TODO: " << stream )
#define NOT_YET_IMPLEMENTED() REPORT( WARNING, __func__ << " is not yet implemented." )
//
struct DELETE_THIS
{
DELETE_THIS( char const * const filename, int lineno, char const * const message )
{
::sc_core::sc_report_handler::report( \
::sc_core::SC_WARNING, "Code incomplete", message, filename, lineno );
}
};
#define DELETE_THIS_LINE(lno,message) const DELETE_THIS lno{ __FILE__, __LINE__, #message }
#endif/*__SYNTHESIS__*/
#endif/*REPORT_HPP*/