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 | //#include <stdint.h> |
---|
45 | |
---|
46 | #include "sc_fwd.h" |
---|
47 | #include "alias.h" |
---|
48 | #include "sc_module_ext.h" |
---|
49 | #include "sc_localvar.h" |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | namespace sc_core { |
---|
54 | |
---|
55 | using namespace sc_dt; |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | struct signal2trace { |
---|
60 | const sc_interface * inter; |
---|
61 | const char * alias; |
---|
62 | unsigned int bit_size; |
---|
63 | tab_t * pointer; |
---|
64 | std::string nomSig; |
---|
65 | }; |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | template< typename T > struct bits_number_getter {}; |
---|
70 | |
---|
71 | |
---|
72 | #define BITS_NUMBER_GETTER_DEF(newt, typ, expr) \ |
---|
73 | template<newt> struct bits_number_getter<typ> { \ |
---|
74 | typedef typ val_t; \ |
---|
75 | static inline unsigned int get() { return expr; } \ |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | BITS_NUMBER_GETTER_DEF(, bool , 1); |
---|
80 | BITS_NUMBER_GETTER_DEF(, char , 8 * sizeof(val_t)); |
---|
81 | BITS_NUMBER_GETTER_DEF(, signed char , 8 * sizeof(val_t)); |
---|
82 | BITS_NUMBER_GETTER_DEF(, unsigned char , 8 * sizeof(val_t)); |
---|
83 | BITS_NUMBER_GETTER_DEF(, unsigned short, 8 * sizeof(val_t)); |
---|
84 | BITS_NUMBER_GETTER_DEF(, signed short, 8 * sizeof(val_t)); |
---|
85 | BITS_NUMBER_GETTER_DEF(, signed int , 8 * sizeof(val_t)); |
---|
86 | BITS_NUMBER_GETTER_DEF(, unsigned int , 8 * sizeof(val_t)); |
---|
87 | BITS_NUMBER_GETTER_DEF(, signed long , 8 * sizeof(val_t)); |
---|
88 | BITS_NUMBER_GETTER_DEF(, unsigned long , 8 * sizeof(val_t)); |
---|
89 | BITS_NUMBER_GETTER_DEF(, float , 8 * sizeof(val_t)); |
---|
90 | BITS_NUMBER_GETTER_DEF(, sc_unsigned , 8 * sizeof(unsigned int)); |
---|
91 | BITS_NUMBER_GETTER_DEF(, sc_signed , 8 * sizeof(int)); |
---|
92 | BITS_NUMBER_GETTER_DEF(, double , 8 * sizeof(val_t)); |
---|
93 | BITS_NUMBER_GETTER_DEF(, uint64 , 8 * sizeof(val_t)); |
---|
94 | BITS_NUMBER_GETTER_DEF(, int64 , 8 * sizeof(val_t)); |
---|
95 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_in<inval_t> , bits_number_getter<inval_t>::get()); |
---|
96 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_out<inval_t> , bits_number_getter<inval_t>::get()); |
---|
97 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_inout<inval_t> , bits_number_getter<inval_t>::get()); |
---|
98 | BITS_NUMBER_GETTER_DEF(typename inval_t, sc_signal<inval_t>, bits_number_getter<inval_t>::get()); |
---|
99 | BITS_NUMBER_GETTER_DEF(int W, sc_int<W>, W); |
---|
100 | BITS_NUMBER_GETTER_DEF(int W, sc_uint<W>, W); |
---|
101 | BITS_NUMBER_GETTER_DEF(int W, sc_bigint<W>, W); |
---|
102 | BITS_NUMBER_GETTER_DEF(int W, sc_biguint<W>, W); |
---|
103 | BITS_NUMBER_GETTER_DEF(int W, sc_bv<W>, W); |
---|
104 | BITS_NUMBER_GETTER_DEF(int W, sc_lv<W>, W); |
---|
105 | #undef BITS_NUMBER_GETTER_DEF |
---|
106 | |
---|
107 | |
---|
108 | template < typename T > |
---|
109 | inline unsigned int get_bits_number (const T & object) { |
---|
110 | return bits_number_getter<T>::get(); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | struct sc_trace_file; |
---|
116 | |
---|
117 | |
---|
118 | extern void sc_trace(sc_trace_file * tf, const signal2trace & t, const std::string & name); |
---|
119 | |
---|
120 | |
---|
121 | template < class T > /*inline*/ |
---|
122 | void sc_trace(sc_trace_file * tf, const sc_in< T > & port, const std::string & name) { |
---|
123 | signal2trace t; |
---|
124 | t.inter = (const sc_interface *) &port; |
---|
125 | t.alias = alias(); |
---|
126 | t.bit_size = get_bits_number(port); |
---|
127 | t.nomSig = name; |
---|
128 | sc_trace (tf, t, name); |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | template <class T> /*inline*/ |
---|
134 | void sc_trace(sc_trace_file * tf, const sc_out< T > & out, const std::string & name) { |
---|
135 | signal2trace t; |
---|
136 | t.inter = (const sc_interface *) &out; |
---|
137 | t.alias = alias(); |
---|
138 | t.bit_size = get_bits_number(out); |
---|
139 | t.nomSig = name; |
---|
140 | sc_trace (tf, t, name); |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | template <typename T> /*inline*/ |
---|
146 | void sc_trace(sc_trace_file * tf, const sc_inout< T > & inout, const std::string & name) { |
---|
147 | signal2trace t; |
---|
148 | t.inter = (const sc_interface *) &inout; |
---|
149 | t.alias = alias(); |
---|
150 | t.bit_size = get_bits_number(inout); |
---|
151 | t.nomSig = name; |
---|
152 | sc_trace (tf, t, name); |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | template <typename T> /*inline*/ |
---|
158 | void sc_trace( sc_trace_file * tf, const sc_signal< T > & signal, const std::string & name) { |
---|
159 | signal2trace t; |
---|
160 | t.inter = (const sc_interface *) &signal; |
---|
161 | t.alias = alias(); |
---|
162 | t.bit_size = get_bits_number(signal); |
---|
163 | t.nomSig = name; |
---|
164 | sc_trace (tf, t, name); |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | #define DEF_SC_TRACE(T) /*inline \*/ \ |
---|
170 | extern void sc_trace (sc_trace_file *, \ |
---|
171 | const T & object, \ |
---|
172 | const std::string &); |
---|
173 | |
---|
174 | DEF_SC_TRACE(bool) |
---|
175 | DEF_SC_TRACE(float) |
---|
176 | DEF_SC_TRACE(double) |
---|
177 | DEF_SC_TRACE(unsigned char) |
---|
178 | DEF_SC_TRACE(unsigned short) |
---|
179 | DEF_SC_TRACE(unsigned int) |
---|
180 | DEF_SC_TRACE(unsigned long) |
---|
181 | DEF_SC_TRACE(char) |
---|
182 | DEF_SC_TRACE(short) |
---|
183 | DEF_SC_TRACE(int) |
---|
184 | DEF_SC_TRACE(long) |
---|
185 | DEF_SC_TRACE(uint64) |
---|
186 | DEF_SC_TRACE(int64) |
---|
187 | #undef DEF_SC_TRACE |
---|
188 | |
---|
189 | } // end of sc_core namespace |
---|
190 | |
---|
191 | |
---|
192 | #endif |
---|
193 | |
---|
194 | /* |
---|
195 | # Local Variables: |
---|
196 | # tab-width: 4; |
---|
197 | # c-basic-offset: 4; |
---|
198 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
199 | # indent-tabs-mode: nil; |
---|
200 | # End: |
---|
201 | # |
---|
202 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
203 | */ |
---|
204 | |
---|