1 /*****************************************************************************
2 
3   Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4   more contributor license agreements.  See the NOTICE file distributed
5   with this work for additional information regarding copyright ownership.
6   Accellera licenses this file to you under the Apache License, Version 2.0
7   (the "License"); you may not use this file except in compliance with the
8   License.  You may obtain a copy of the License at
9 
10     http://www.apache.org/licenses/LICENSE-2.0
11 
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15   implied.  See the License for the specific language governing
16   permissions and limitations under the License.
17 
18  *****************************************************************************/
19 /*
20  * @file
21  *  reporting.h
22  *
23  * @brief
24  * Convenience macros to simplify reporting.
25  */
26 
27 /*****************************************************************************
28   Original Authors:
29     Charles Wilson, ESLX
30     Bill Bunton, ESLX
31 *****************************************************************************/
32 
33 #ifndef __REPORTING_H__
34 #define __REPORTING_H__
35 
36 #include "tlm.h"                                        ///< TLM headers
37 #include <sstream>                                      ///< string streams
38 #include <iomanip>                                      ///< I/O manipulation
39 #include <stdio.h>                                      ///< standard I/O
40 
41 using std::setfill;
42 using std::setw;
43 using namespace std;
44 
45 #if ( defined ( REPORT_DEFINE_GLOBALS ) )
46 #   define RDG_EXTERN
47 #else /* REPORT_DEFINE_GLOBALS */
48 #   define RDG_EXTERN   extern
49 #endif /* REPORT_DEFINE_GLOBALS */
50 
51 RDG_EXTERN bool          tlm_enable_info_reporting;     ///< info level reporting enable
52 RDG_EXTERN bool          tlm_enable_warning_reporting;  ///< warning level reporting enable
53 RDG_EXTERN bool          tlm_enable_error_reporting;    ///< error level reporting enable
54 RDG_EXTERN bool          tlm_enable_fatal_reporting;    ///< fatal level reporting enable
55 
56 RDG_EXTERN ostringstream reporting_os;                  ///< reporting output string
57 
58 #define REPORT_ENABLE_INFO_REPORTING()     (tlm_enable_info_reporting    = true)
59 #define REPORT_ENABLE_WARNING_REPORTING()  (tlm_enable_warning_reporting = true)
60 #define REPORT_ENABLE_ERROR_REPORTING()    (tlm_enable_error_reporting   = true)
61 #define REPORT_ENABLE_FATAL_REPORTING()    (tlm_enable_fatal_reporting   = true)
62 
63 #define REPORT_DISABLE_INFO_REPORTING()    (tlm_enable_info_reporting    = false)
64 #define REPORT_DISABLE_WARNING_REPORTING() (tlm_enable_warning_reporting = false)
65 #define REPORT_DISABLE_ERROR_REPORTING()   (tlm_enable_error_reporting   = false)
66 #define REPORT_DISABLE_FATAL_REPORTING()   (tlm_enable_fatal_reporting   = false)
67 
68 #define REPORT_SET_ENABLES(ri,rw,re,rf) \
69 { \
70   if (ri) {REPORT_ENABLE_INFO_REPORTING    ();} else {REPORT_DISABLE_INFO_REPORTING    ();} \
71   if (rw) {REPORT_ENABLE_WARNING_REPORTING ();} else {REPORT_DISABLE_WARNING_REPORTING ();} \
72   if (re) {REPORT_ENABLE_ERROR_REPORTING   ();} else {REPORT_DISABLE_ERROR_REPORTING   ();} \
73   if (rf) {REPORT_ENABLE_FATAL_REPORTING   ();} else {REPORT_DISABLE_FATAL_REPORTING   ();} \
74 }
75 
76 #define REPORT_ENABLE_ALL_REPORTING() \
77 { \
78   REPORT_SET_ENABLES(true,true,true,true); \
79 }
80 
81 #define REPORT_DISABLE_ALL_REPORTING() \
82 { \
83   REPORT_SET_ENABLES(false,false,false,false); \
84 }
85 
86 #if ( defined ( REPORTING_OFF ) )
87 
88 #define REPORT_NEW(text) {}
89 #define REPORT_APPEND(text) {}
90 #define REPORT_OUTPUT(severity, source) {}
91 
92 #else /* REPORTING_OFF */
93 
94 #define REPORT_NEW(text) \
95 { \
96   reporting_os.str (""); \
97   reporting_os << text; \
98 }
99 
100 #define REPORT_APPEND(text) \
101 { \
102   reporting_os << text; \
103 }
104 
105 #define REPORT_OUTPUT(severity, source) \
106 { \
107   ostringstream os; \
108   os << sc_core::sc_time_stamp() << " - " << __FUNCTION__ << endl << "      " << reporting_os.str(); \
109   SC_REPORT_##severity (source, os.str().c_str()); \
110 }
111 #endif /* REPORTING_OFF */
112 
113 #define REPORT_INFO(source, routine, text) \
114 { ostringstream os; \
115   string routine_string (routine); \
116   int colon_location; \
117   if ((colon_location = routine_string.find("::")) != -1) \
118   { \
119     routine_string.erase(0, colon_location + 2); \
120   } \
121   os << sc_core::sc_time_stamp() << " - " << routine_string << endl << "      " << text; \
122   if (tlm_enable_info_reporting) \
123   { \
124     SC_REPORT_INFO(source, os.str().c_str()); \
125   } \
126 }
127 
128 #define REPORT_WARNING(source, routine, text) \
129 { ostringstream os; \
130   string routine_string (routine); \
131   int colon_location; \
132   if ((colon_location = routine_string.find("::")) != -1) \
133   { \
134     routine_string.erase(0, colon_location + 2); \
135   } \
136   os << sc_core::sc_time_stamp() << " - " << routine_string << endl << "      " << text; \
137   if (tlm_enable_warning_reporting) \
138   { \
139     SC_REPORT_WARNING(source, os.str().c_str()); \
140   } \
141 }
142 
143 #define REPORT_ERROR(source, routine, text) \
144 { ostringstream os; \
145   string routine_string (routine); \
146   int colon_location; \
147   if ((colon_location = routine_string.find("::")) != -1) \
148   { \
149     routine_string.erase(0, colon_location + 2); \
150   } \
151   os << sc_core::sc_time_stamp() << " - " << routine_string << endl << "      " << text; \
152   if (tlm_enable_error_reporting) \
153   { \
154     SC_REPORT_ERROR(source, os.str().c_str()); \
155   } \
156 }
157 
158 #define REPORT_FATAL(source, routine, text) \
159 { ostringstream os; \
160   string routine_string (routine); \
161   int colon_location; \
162   if ((colon_location = routine_string.find("::")) != -1) \
163   { \
164     routine_string.erase(0, colon_location + 2); \
165   } \
166   os << sc_core::sc_time_stamp() << " - " << routine_string << endl << "      " << text; \
167   if (tlm_enable_fatal_reporting) \
168   { \
169     SC_REPORT_FATAL(source, os.str().c_str()); \
170   } \
171 }
172 
173 namespace report
174 {
175   std::string print (const tlm::tlm_sync_enum status);
176   std::string print (const tlm::tlm_phase phase);
177 
178   void print
179   ( const int                 &ID              ///< Target ID/Initiator/?ID
180   , tlm::tlm_generic_payload  &trans           ///< transaction to be printed
181   , const char*               calling_filename= "print.cpp"
182   );
183 
184   void print_full
185   ( const int                 &ID              ///< Target ID/Initiator/?ID
186   , tlm::tlm_generic_payload  &trans           ///< transaction to be printed
187   , const char*               filename = "print.cpp"
188   );
189 
190   void
191   print
192   ( const int                 &ID              ///< Target ID/Initiator/?ID
193   , tlm::tlm_dmi              &dmi_parameters     ///< dmi transaction to be printed
194   , const char*               calling_filename = "print.cpp"
195   );
196 }
197 
198 
199 #endif /* __REPORTING_H__ */
200