summaryrefslogtreecommitdiff
path: root/ext/systemc/src/sysc/utils/sc_report.cpp
blob: 378d45cde34ea21fa4a2f28d42840c405055f1e9 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*****************************************************************************

  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
  more contributor license agreements.  See the NOTICE file distributed
  with this work for additional information regarding copyright ownership.
  Accellera licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  implied.  See the License for the specific language governing
  permissions and limitations under the License.

 *****************************************************************************/

/*****************************************************************************

  sc_report.cpp -- Run-time logging and reporting facilities

  Interface design by SystemC Verification Working Group.
  Implementation by Alex Riesen, Synopsys Inc.
  Original implementation by Martin Janssen, Synopsys Inc.
  Reference implementation by Cadence Design Systems, Inc., 2002-09-23:
  Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
  John Pierce, Rachida Kebichi, Ted Elkind, David Bailey.

  CHANGE LOG AT END OF FILE
 *****************************************************************************/


#include <stdlib.h>
#include <string.h>

#include "sysc/kernel/sc_process.h"
#include "sysc/kernel/sc_simcontext_int.h"
#include "sysc/utils/sc_stop_here.h"
#include "sysc/utils/sc_report.h"
#include "sysc/utils/sc_utils_ids.h"
#include <algorithm> // std::swap

namespace sc_core {


static void sc_deprecated_report_ids(const char* method)
{
    static bool warn_report_ids_deprecated=true;
    if ( warn_report_ids_deprecated )
    {
        std::string message;
	message = "integer report ids are deprecated, use string values: ";
	message += method;
        warn_report_ids_deprecated=false;
	SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_, message.c_str());
    }
}

static char empty_str[] = "";
static inline char * empty_dup(const char * p)
{
    if ( p && *p )
    {
        char* result;
        result = (char*)malloc(strlen(p)+1);
        strcpy(result, p);
        return result;
    }
    else
    {
        return empty_str;
    }
}

sc_report::sc_report() 
: severity(SC_INFO),
  md(0),
  msg(empty_dup(0)),
  file(empty_dup(0)),
  line(0),
  timestamp(new sc_time(sc_time_stamp())),
  process(0),
  m_verbosity_level(SC_MEDIUM),
  m_what(empty_dup(0))
{
}

sc_report::sc_report(sc_severity severity_,
		     const sc_msg_def* md_,
		     const char* msg_,
		     const char* file_,
		     int line_,
		     int verbosity_level)
: severity(severity_),
  md(md_),
  msg(empty_dup(msg_)),
  file(empty_dup(file_)),
  line(line_),
  timestamp(new sc_time(sc_time_stamp())),
  process(sc_get_current_process_b()),
  m_verbosity_level(verbosity_level),
  m_what( empty_dup( sc_report_compose_message(*this).c_str() ) )
{
}

sc_report::sc_report(const sc_report& other)
: std::exception(other),
  severity(other.severity),
  md(other.md),
  msg(empty_dup(other.msg)),
  file(empty_dup(other.file)),
  line(other.line),
  timestamp(new sc_time(*other.timestamp)),
  process(other.process),
  m_verbosity_level(other.m_verbosity_level),
  m_what(empty_dup(other.m_what))
{
}

sc_report & sc_report::operator=(const sc_report& other)
{
    sc_report copy(other);
    swap( copy );
    return *this;
}

void
sc_report::swap( sc_report & that )
{
    using std::swap;
    swap( severity,          that.severity );
    swap( md,                that.md );
    swap( msg,               that.msg );
    swap( file,              that.file );
    swap( line,              that.line );
    swap( timestamp,         that.timestamp );
    swap( process,           that.process );
    swap( m_verbosity_level, that.m_verbosity_level );
    swap( m_what,            that.m_what );
} 

sc_report::~sc_report() throw()
{
    if ( file != empty_str )
	free(file);
    if ( msg != empty_str )
	free(msg);
    delete timestamp;
    if ( m_what != empty_str )
    free(m_what);
}

const char * sc_report::get_msg_type() const
{
    return md->msg_type;
}

//
// backward compatibility with 2.0+
//

static bool warnings_are_errors = false;
static const char unknown_id[] = "unknown id";

void sc_report_handler::report(sc_severity severity_,
			       int         id_,
			       const char* msg_,
			       const char* file_,
			       int         line_ )
{
    sc_msg_def * md = sc_report_handler::mdlookup(id_);

    if ( !md )
    {
	md = sc_report_handler::add_msg_type(unknown_id);
	md->id = id_;
    }

    if ( severity_ == SC_WARNING && warnings_are_errors )
	severity_ = SC_ERROR;

    sc_actions actions = execute(md, severity_);
    sc_report rep(severity_, md, msg_, file_, line_);

    if ( actions & SC_CACHE_REPORT )
	cache_report(rep);

    if ( severity_ == SC_ERROR )
	actions |= SC_THROW;
    else if ( severity_ == SC_FATAL )
	actions |= SC_ABORT;

    handler(rep, actions);
}

void sc_report::register_id( int id, const char* msg )
{
    sc_deprecated_report_ids("sc_report::register_id()");
    if( id < 0 ) {
	SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
			 "invalid report id" );
    }
    if( msg == 0 ) {
	SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
			 "invalid report message" );
    }
    sc_msg_def * md = sc_report_handler::mdlookup(id);

    if ( !md )
	md = sc_report_handler::add_msg_type(msg);

    if ( !md ) {
	SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
			 "report_map insertion error" );
    }

    if( md->id != -1 ) {
	if( strcmp( msg, md->msg_type ) != 0 ) {
	    SC_REPORT_ERROR( SC_ID_REGISTER_ID_FAILED_,
			     "report id already exists" );
	}
	return;
    }
    md->id = id;
}

const char* sc_report::get_message( int id )
{
    sc_deprecated_report_ids("sc_report::get_message()");
    sc_msg_def* md = sc_report_handler::mdlookup(id);

    return md ? md->msg_type: unknown_id;
}

bool sc_report::is_suppressed( int id )
{
    sc_deprecated_report_ids("sc_report::is_suppressed()");
    sc_msg_def* md = sc_report_handler::mdlookup(id);

    return md ? md->actions == SC_DO_NOTHING: false; // only do-nothing set
}

void sc_report::suppress_id(int id_, bool suppress)
{
    sc_deprecated_report_ids("sc_report::suppress_id()");
    sc_msg_def* md = sc_report_handler::mdlookup(id_);

    if ( md )
	md->actions = suppress ? SC_DO_NOTHING: SC_UNSPECIFIED;
}

void sc_report::suppress_infos(bool suppress)
{
    sc_deprecated_report_ids("sc_report::supress_infos");
    sc_report_handler::sev_actions[SC_INFO] =
	suppress ? SC_DO_NOTHING: SC_DEFAULT_INFO_ACTIONS;
}

void sc_report::suppress_warnings(bool suppress)
{
    sc_deprecated_report_ids("sc_report::suppress_warnings");
    sc_report_handler::sev_actions[SC_WARNING] =
	suppress ? SC_DO_NOTHING: SC_DEFAULT_WARNING_ACTIONS;
}

void sc_report::make_warnings_errors(bool flag)
{
    sc_deprecated_report_ids("sc_report::make_warnings_errors");
    warnings_are_errors = flag;
}

int sc_report::get_id() const
{
    return md->id;
}

} // namespace sc_core

// $Log: sc_report.cpp,v $
// Revision 1.8  2011/08/29 18:04:32  acg
//  Philipp A. Hartmann: miscellaneous clean ups.
//
// Revision 1.7  2011/08/26 20:43:01  acg
//  Andy Goodrich:
//    (1) Replaced strdup with new and strcpy to eliminate issue with the
//        Greenhills compiler.
//    (2) Moved modification log to the end of the file to eliminate line
//        skew when check-ins are done.
//
// Revision 1.6  2011/08/24 22:05:56  acg
//  Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.5  2011/05/05 17:46:04  acg
//  Philip A. Hartmann: changes in "swap" support.
//
// Revision 1.4  2011/03/23 16:16:48  acg
//  Andy Goodrich: finish message verbosity support.
//
// Revision 1.3  2011/02/18 20:38:44  acg
//  Andy Goodrich: Updated Copyright notice.
//
// Revision 1.2  2011/02/01 23:02:05  acg
//  Andy Goodrich: IEEE 1666 2011 changes.
//
// Revision 1.1.1.1  2006/12/15 20:20:06  acg
// SystemC 2.3
//
// Revision 1.7  2006/03/21 00:00:37  acg
//   Andy Goodrich: changed name of sc_get_current_process_base() to be
//   sc_get_current_process_b() since its returning an sc_process_b instance.
//
// Revision 1.6  2006/01/25 00:31:27  acg
//  Andy Goodrich: Changed over to use a standard message id of
//  SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
//
// Revision 1.5  2006/01/24 22:02:30  acg
//  Andy Goodrich: switch deprecated features warnings to use a single message
//  id, SC_ID_IEEE_1666_DEPRECATION_.
//
// Revision 1.4  2006/01/24 20:53:41  acg
// Andy Goodrich: added warnings indicating that use of integer ids in reports
// is deprecated. Added tracing/sc_trace_ids.h to message list.
//
// Revision 1.3  2006/01/13 18:53:11  acg
// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
// the source.

// taf