sc_trace.cpp revision 12027:1eb7dc7aa10b
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/*****************************************************************************
21
22  sc_trace.cpp - Functions for tracing signals and variables.
23
24  Original Author: Abhijit Ghosh, Synopsys, Inc.
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38/*****************************************************************************
39
40   Acknowledgement: The tracing mechanism is based on the tracing
41   mechanism developed at Infineon (formerly Siemens HL). Though this
42   code is somewhat different, the basics are identical to what was
43   originally contributed by Infineon.  The contribution of Infineon
44   in the development of this tracing technology is hereby
45   acknowledged.
46
47 *****************************************************************************/
48
49#include <stdarg.h>
50#include <stdio.h>
51
52#include "sysc/tracing/sc_trace.h"
53#include "sysc/tracing/sc_tracing_ids.h"
54#include "sysc/communication/sc_signal_ifs.h"
55#include "sysc/utils/sc_report.h"
56#include "sysc/utils/sc_utils_ids.h"
57
58namespace sc_core {
59
60// Trace file common functions.
61
62sc_trace_file::sc_trace_file()
63{
64  /* Intentionally blank */
65}
66
67void tprintf(sc_trace_file* tf,  const char* format, ...)
68{
69    static char buffer[4096];
70    va_list ap;
71    va_start(ap, format);
72    (void) vsprintf(buffer, format, ap);
73    va_end(ap);
74    if (tf) tf->write_comment(buffer);
75}
76
77void sc_trace_file::space(int)
78{
79  /* Intentionally blank */
80}
81
82void sc_trace_file::delta_cycles(bool)
83{
84  /* Intentionally blank */
85}
86
87
88void
89sc_trace( sc_trace_file* tf,
90	  const sc_signal_in_if<char>& object,
91	  const std::string& name,
92	  int width )
93{
94    if( tf ) {
95	tf->trace( object.read(), name, width );
96    }
97}
98
99void
100sc_trace( sc_trace_file* tf,
101	  const sc_signal_in_if<short>& object,
102	  const std::string& name,
103	  int width )
104{
105    if( tf ) {
106	tf->trace( object.read(), name, width );
107    }
108}
109
110void
111sc_trace( sc_trace_file* tf,
112	  const sc_signal_in_if<int>& object,
113	  const std::string& name,
114	  int width )
115{
116    if( tf ) {
117	tf->trace( object.read(), name, width );
118    }
119}
120
121void
122sc_trace( sc_trace_file* tf,
123	  const sc_signal_in_if<long>& object,
124	  const std::string& name,
125	  int width )
126{
127    if( tf ) {
128	tf->trace( object.read(), name, width );
129    }
130}
131
132
133void
134sc_trace(sc_trace_file* /* not used */,
135	 const void* /* not used */,
136	 const std::string& name)
137{
138    SC_REPORT_WARNING( SC_ID_TRACING_OBJECT_IGNORED_, name.c_str() );
139}
140
141
142
143void double_to_special_int64(double in, unsigned* high, unsigned* low)
144{
145    double invar = in;
146    if(invar > 5e17) invar = 5e17; // Saturation limit
147    if(invar < 0.0) invar = 0.0;
148    invar += .5;
149    *high = (unsigned)(invar / 1e9);
150    double rest = invar - 1e9 * (*high);
151    if(rest < 0) *low = 0;
152    else *low = (unsigned)rest;
153}
154
155
156// ----------------------------------------------------------------------------
157
158#define DEFN_TRACE_FUNC_REF_A(tp)                                             \
159void                                                                          \
160sc_trace( sc_trace_file* tf, const tp& object, const std::string& name ) \
161{                                                                             \
162    if( tf ) {                                                                \
163	tf->trace( object, name );                                            \
164    }                                                                         \
165}
166
167#define DEFN_TRACE_FUNC_PTR_A(tp)                                             \
168void                                                                          \
169sc_trace( sc_trace_file* tf, const tp* object, const std::string& name ) \
170{                                                                             \
171    if( tf ) {                                                                \
172	tf->trace( *object, name );                                           \
173    }                                                                         \
174}
175
176#define DEFN_TRACE_FUNC_A(tp)                                                 \
177DEFN_TRACE_FUNC_REF_A(tp)                                                     \
178DEFN_TRACE_FUNC_PTR_A(tp)
179
180
181DEFN_TRACE_FUNC_A( sc_dt::sc_bit )
182DEFN_TRACE_FUNC_A( sc_dt::sc_logic )
183
184DEFN_TRACE_FUNC_A( sc_dt::sc_int_base )
185DEFN_TRACE_FUNC_A( sc_dt::sc_uint_base )
186DEFN_TRACE_FUNC_A( sc_dt::sc_signed )
187DEFN_TRACE_FUNC_A( sc_dt::sc_unsigned )
188
189DEFN_TRACE_FUNC_REF_A( sc_dt::sc_bv_base )
190DEFN_TRACE_FUNC_REF_A( sc_dt::sc_lv_base )
191
192
193#undef DEFN_TRACE_FUNC_REF_A
194#undef DEFN_TRACE_FUNC_PTR_A
195#undef DEFN_TRACE_FUNC_A
196
197
198void
199sc_trace( sc_trace_file* tf,
200	  const unsigned int& object,
201	  const std::string& name,
202	  const char** enum_literals )
203{
204    static bool warn_sc_trace_literals=true;
205    if ( warn_sc_trace_literals )
206    {
207        warn_sc_trace_literals=false;
208        SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
209            "tracing of enumerated literals is deprecated" );
210    }
211
212    if( tf ) tf->trace( object, name, enum_literals );
213}
214
215} // namespace sc_core
216
217// Taf!
218