1 | /*------------------------------------------------------------\ |
---|
2 | | | |
---|
3 | | Tool : systemcass | |
---|
4 | | | |
---|
5 | | File : sc_trace.h | |
---|
6 | | | |
---|
7 | | Author : Kingbo Paul-Jerome | |
---|
8 | | Buchmann Richard | |
---|
9 | | | |
---|
10 | | Date : 09_07_2004 | |
---|
11 | | | |
---|
12 | \------------------------------------------------------------*/ |
---|
13 | |
---|
14 | /* |
---|
15 | * This file is part of the Disydent Project |
---|
16 | * Copyright (C) Laboratoire LIP6 - Département ASIM |
---|
17 | * Universite Pierre et Marie Curie |
---|
18 | * |
---|
19 | * Home page : http://www-asim.lip6.fr/disydent |
---|
20 | * E-mail : mailto:richard.buchmann@lip6.fr |
---|
21 | * |
---|
22 | * This library is free software; you can redistribute it and/or modify it |
---|
23 | * under the terms of the GNU Library General Public License as published |
---|
24 | * by the Free Software Foundation; either version 2 of the License, or (at |
---|
25 | * your option) any later version. |
---|
26 | * |
---|
27 | * Disydent is distributed in the hope that it will be |
---|
28 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
30 | * Public License for more details. |
---|
31 | * |
---|
32 | * You should have received a copy of the GNU General Public License along |
---|
33 | * with the GNU C Library; see the file COPYING. If not, write to the Free |
---|
34 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
35 | */ |
---|
36 | |
---|
37 | #ifndef __SC_TRACE_EXT_H__ |
---|
38 | #define __SC_TRACE_EXT_H__ |
---|
39 | |
---|
40 | #include <vector> |
---|
41 | #include <iostream> |
---|
42 | #include <string> |
---|
43 | #include <sstream> |
---|
44 | |
---|
45 | #include "sc_fwd.h" |
---|
46 | #include "alias.h" |
---|
47 | #include "sc_module_ext.h" |
---|
48 | #include "sc_localvar.h" |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | namespace sc_core { |
---|
53 | |
---|
54 | using namespace sc_dt; |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | struct signal2trace { |
---|
59 | const sc_interface * inter; |
---|
60 | const char * alias; |
---|
61 | unsigned int bit_size; |
---|
62 | tab_t * pointer; |
---|
63 | std::string nomSig; |
---|
64 | }; |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | template< typename T > struct bits_number_getter {}; |
---|
69 | |
---|
70 | |
---|
71 | #define BITS_NUMBER_GETTER_DEF(newt, typ, expr) \ |
---|
72 | template<newt> struct bits_number_getter<typ> { \ |
---|
73 | typedef typ val_t; \ |
---|
74 | static inline unsigned int get() { return expr; } \ |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | BITS_NUMBER_GETTER_DEF(, bool , 1); |
---|
79 | BITS_NUMBER_GETTER_DEF(, char , 8 * sizeof(val_t)); |
---|
80 | BITS_NUMBER_GETTER_DEF(, signed char , 8 * sizeof(val_t)); |
---|
81 | BITS_NUMBER_GETTER_DEF(, unsigned char , 8 * sizeof(val_t)); |
---|
82 | BITS_NUMBER_GETTER_DEF(, unsigned short, 8 * sizeof(val_t)); |
---|
83 | BITS_NUMBER_GETTER_DEF(, signed short, 8 * sizeof(val_t)); |
---|
84 | BITS_NUMBER_GETTER_DEF(, signed int , 8 * sizeof(val_t)); |
---|
85 | BITS_NUMBER_GETTER_DEF(, unsigned int , 8 * sizeof(val_t)); |
---|
86 | BITS_NUMBER_GETTER_DEF(, signed long , 8 * sizeof(val_t)); |
---|
87 | BITS_NUMBER_GETTER_DEF(, unsigned long , 8 * sizeof(val_t)); |
---|
88 | BITS_NUMBER_GETTER_DEF(, float , 8 * sizeof(val_t)); |
---|
89 | BITS_NUMBER_GETTER_DEF(, sc_unsigned , 8 * sizeof(unsigned int)); |
---|
90 | BITS_NUMBER_GETTER_DEF(, sc_signed , 8 * sizeof(int)); |
---|
91 | BITS_NUMBER_GETTER_DEF(, double , 8 * sizeof(val_t)); |
---|
92 | BITS_NUMBER_GETTER_DEF(, uint64 , 8 * sizeof(val_t)); |
---|
93 | BITS_NUMBER_GETTER_DEF(, int64 , 8 * sizeof(val_t)); |
---|
94 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_in<inval_t> , bits_number_getter<inval_t>::get()); |
---|
95 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_out<inval_t> , bits_number_getter<inval_t>::get()); |
---|
96 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_inout<inval_t> , bits_number_getter<inval_t>::get()); |
---|
97 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_signal<inval_t>, bits_number_getter<inval_t>::get()); |
---|
98 | BITS_NUMBER_GETTER_DEF(int W, sc_int<W>, W); |
---|
99 | BITS_NUMBER_GETTER_DEF(int W, sc_uint<W>, W); |
---|
100 | BITS_NUMBER_GETTER_DEF(int W, sc_bigint<W>, W); |
---|
101 | BITS_NUMBER_GETTER_DEF(int W, sc_biguint<W>, W); |
---|
102 | BITS_NUMBER_GETTER_DEF(int W, sc_bv<W>, W); |
---|
103 | BITS_NUMBER_GETTER_DEF(int W, sc_lv<W>, W); |
---|
104 | #undef BITS_NUMBER_GETTER_DEF |
---|
105 | |
---|
106 | |
---|
107 | template < typename T > |
---|
108 | inline unsigned int get_bits_number (const T & object) { |
---|
109 | return bits_number_getter<T>::get(); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | struct sc_trace_file; |
---|
115 | |
---|
116 | |
---|
117 | extern void sc_trace(sc_trace_file * tf, const signal2trace & t, const std::string & name); |
---|
118 | |
---|
119 | |
---|
120 | template < class T > /*inline*/ |
---|
121 | void sc_trace(sc_trace_file * tf, const sc_in< T > & port, const std::string & name) { |
---|
122 | signal2trace t; |
---|
123 | t.inter = (const sc_interface *) &port; |
---|
124 | t.alias = alias(); |
---|
125 | t.bit_size = get_bits_number(port); |
---|
126 | t.nomSig = name; |
---|
127 | sc_trace (tf, t, name); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | template <class T> /*inline*/ |
---|
133 | void sc_trace(sc_trace_file * tf, const sc_out< T > & out, const std::string & name) { |
---|
134 | signal2trace t; |
---|
135 | t.inter = (const sc_interface *) &out; |
---|
136 | t.alias = alias(); |
---|
137 | t.bit_size = get_bits_number(out); |
---|
138 | t.nomSig = name; |
---|
139 | sc_trace (tf, t, name); |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | template <typename T> /*inline*/ |
---|
145 | void sc_trace(sc_trace_file * tf, const sc_inout< T > & inout, const std::string & name) { |
---|
146 | signal2trace t; |
---|
147 | t.inter = (const sc_interface *) &inout; |
---|
148 | t.alias = alias(); |
---|
149 | t.bit_size = get_bits_number(inout); |
---|
150 | t.nomSig = name; |
---|
151 | sc_trace (tf, t, name); |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | template <typename T> /*inline*/ |
---|
157 | void sc_trace( sc_trace_file * tf, const sc_signal< T > & signal, const std::string & name) { |
---|
158 | signal2trace t; |
---|
159 | t.inter = (const sc_interface *) &signal; |
---|
160 | t.alias = alias(); |
---|
161 | t.bit_size = get_bits_number(signal); |
---|
162 | t.nomSig = name; |
---|
163 | sc_trace (tf, t, name); |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | #define DEF_SC_TRACE(T) /*inline \*/ \ |
---|
169 | extern void sc_trace (sc_trace_file *, \ |
---|
170 | const T & object, \ |
---|
171 | const std::string &); |
---|
172 | |
---|
173 | DEF_SC_TRACE(bool) |
---|
174 | DEF_SC_TRACE(float) |
---|
175 | DEF_SC_TRACE(double) |
---|
176 | DEF_SC_TRACE(unsigned char) |
---|
177 | DEF_SC_TRACE(unsigned short) |
---|
178 | DEF_SC_TRACE(unsigned int) |
---|
179 | DEF_SC_TRACE(unsigned long) |
---|
180 | DEF_SC_TRACE(char) |
---|
181 | DEF_SC_TRACE(short) |
---|
182 | DEF_SC_TRACE(int) |
---|
183 | DEF_SC_TRACE(long) |
---|
184 | DEF_SC_TRACE(uint64) |
---|
185 | DEF_SC_TRACE(int64) |
---|
186 | #undef DEF_SC_TRACE |
---|
187 | |
---|
188 | } // end of sc_core namespace |
---|
189 | |
---|
190 | |
---|
191 | #endif |
---|
192 | |
---|
193 | /* |
---|
194 | # Local Variables: |
---|
195 | # tab-width: 4; |
---|
196 | # c-basic-offset: 4; |
---|
197 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
198 | # indent-tabs-mode: nil; |
---|
199 | # End: |
---|
200 | # |
---|
201 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
202 | */ |
---|
203 | |
---|