SystemC 34 Error and Message Report
sc_report
- represents an instance of a report as generated by function
sc_report_handler::report
. - accessible to the application if the action
SC_CACHE_REPORT
is set for a given severity level and message type. - may be caught by the application when thrown by the report handler.
sc_report_handler
provides features for writing out textual reports on the occurrence of exceptional circumstances and for defining application-specific behavior to be executed when those reports are generated.
sc_severity
represents the severity level of a report:
enum sc_severity {SC_INFO = 0, SC_WARNING, SC_ERROR, SC_FATAL, SC_MAX_SEVERITY};
- there are four severity levels.
SC_MAX_SEVERITY
is not a severity level. It’s an error to passSC_MAX_SEVERITY
to a function requiring an argument of typesc_severity
.
sc_verbosity
provides the values of indicative verbosity levels that may be passed as arguments to member function set_verbosity_level
of class sc_report_handler
and to member function report of class sc_report_handler
:
enum sc_verbosity {SC_NONE = 0, SC_LOW = 100, SC_MEDIUM = 200, SC_HIGH = 300, SC_FULL = 400, SC_DEBUG = 500};
sc_actions
represents a word where each bit in the word represents a distinct action. More than one bit may be set, in which case all of the corresponding actions shall be executed:
- enum declaration
1 2 3 4 5 6 7 8 9 10 11
enum { SC_UNSPECIFIED = 0x0000, //is not an action, serves as the default value meaning that no action has been set. SC_DO_NOTHING = 0x0001, // is a specified action SC_THROW = 0x0002, SC_LOG = 0x0004, SC_DISPLAY = 0x0008, SC_CACHE_REPORT = 0x0010, SC_INTERRUPT = 0x0020, SC_STOP = 0x0040, SC_ABORT = 0x0080 }
- each severity level is associated with a set of default actions, which can be overridden by calling member function
set_actions
. - Default actions:
1 2 3 4
a) #define SC_DEFAULT_INFO_ACTIONS ( SC_LOG | SC_DISPLAY ) b) #define SC_DEFAULT_WARNING_ACTIONS ( SC_LOG | SC_DISPLAY ) c) #define SC_DEFAULT_ERROR_ACTIONS ( SC_LOG | SC_CACHE_REPORT | SC_THROW ) d) #define SC_DEFAULT_FATAL_ACTIONS ( SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT )
report(…)
void report(sc_severity, const char* msg_type, const char* msg, [int verbosity], const char* file, int line)
generate a report and cause the appropriate actions to be taken:
- use the severity passed as the first argument and the message type passed as the second argument to determine the set of actions to be executed as a result of previous calls to functions
set_actions
,stop_after
,suppress
, andforce
. - create an object of class
sc_report
initialized using all five argument values and pass this object to the handler set by the member functionset_handler
. - not persist beyond the call to member function report unless the action
SC_CACHE_REPORT
is set, in which case the object can be retrieved by calling functionget_cached_reports
. - be responsible for determining the set of actions to be executed. The handler function set by function
set_handler
is responsible for executing those actions. - maintain counts of the number of reports generated. These counts shall be incremented regardless of whether actions are executed or suppressed, except where reports are ignored due to their verbosity level, in which case the counts shall not be incremented.
set_actions()
- set the actions to be taken by member function report when report is called with the given severity level, message type, or both.
- replace the actions set by the previous call for the given severity, message type, or severity-message type pair.
stop_after()
report shall call sc_stop
when exactly the number of reports given by argument limit to function stop_after have been generated for the given severity level, message type, or severity-message type pair.
get_count()
return the count of the number of reports generated for each severity level, each message type, and each severity-message type pair maintained by member function report.
Verbosity level:
-
int set_verbosity_level(int)
: set the maximum verbosity level to the value passed as an argument, return the previous value of the maximum verbosity level. -
int get_verbosity_level()
: return the value of the maximum verbosity level.
Code
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
// Learn with Examples, 2020, MIT license
#include <systemc>
using namespace sc_core;
SC_MODULE(MODULE) { // a test module
sc_port<sc_signal<int>> p; // a port
SC_CTOR(MODULE) { // constructor
SC_REPORT_WARNING("ctor", "register function"); // gen report to "ctor"
SC_THREAD(writer); // a writer process
SC_THREAD(reader); // a reader process
sensitive << p; // sensitive to p
dont_initialize();
}
void writer() {
int v = 1;
while (true) {
SC_REPORT_INFO("writer", ("write " + std::to_string(v)).c_str()); // gen report to "writer"
p->write(v++); // write to channel via port
wait(1, SC_SEC); // write every 1 s
}
}
void reader() {
while (true) {
SC_REPORT_INFO("reader", ("read " + std::to_string(p->read())).c_str()); // gen report to "reader"
wait();
}
}
};
int sc_main(int, char*[]) {
sc_report_handler::set_log_file_name("report.log"); // initialize report
sc_report_handler::set_actions("writer", SC_INFO, SC_LOG); // INFO of "writer" saved in log, no display
MODULE module("module"); // instantiate module
sc_signal<int> s; // declares signal channel
module.p(s); // bind port to channel
SC_REPORT_INFO("main", "simulation starts"); // gen report to "main"
sc_start(2, SC_SEC); // run simulation for 2 s
SC_REPORT_INFO("main", "simulation ends"); // gen report to "main"
return 0;
}
// Result:
// console display:
// warning, generated inside constructor
Warning: ctor: register function In file: report.cpp:68
// info, generated in sc_main
Info: main: simulation starts
// generated in reader
Info: reader: read 1
// genrated in reader
Info: reader: read 2
// generated in sc_main
Info: main: simulation ends
// report.log:
// additional sc_time_stamp()
0 s: Warning: ctor: register function In file: report.cpp:68
0 s: Info: main: simulation starts
// only in report.log, not printed to console
0 s: Info: writer: write 1
0 s: Info: reader: read 1
// only in report.log, not printed to console
1 s: Info: writer: write 2
1 s: Info: reader: read 2
2 s: Info: main: simulation ends