test01.cpp revision 12855:588919e0e4aa
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  test01.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
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// test of i/o streaming of the datatypes
39
40#define SC_INCLUDE_FX
41#include "systemc.h"
42# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
43#   include "sstream"
44#else
45#   include "strstream.h"
46#endif
47
48// THE FOLLOWING SPECIALIZATIONS FOR sc_bitref<X> AND sc_subref<X> GO AWAY
49// WHEN sc_bv and sc_lv ARE INTEGRATED INTO THE NORMAL CONCATENATION SCHEME:
50
51template <class X>
52void
53test( sc_dt::sc_bitref<X> a )
54{
55# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
56    std::stringstream ss;
57# else
58	strstream ss;
59# endif
60
61    cout << a << endl;
62    ss << a;
63    ss >> a;
64    cout << a << endl;
65}
66
67template <class X>
68void
69test( sc_dt::sc_subref<X> a )
70{
71# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
72    std::stringstream ss;
73# else
74	strstream ss;
75# endif
76
77    cout << a << endl;
78    ss << a;
79    ss >> a;
80    cout << a << endl;
81}
82
83
84void
85test( sc_dt::sc_fxnum_bitref a )
86{
87# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
88    std::stringstream ss;
89# else
90	strstream ss;
91# endif
92
93    cout << a << endl;
94    ss << a;
95    ss >> a;
96    cout << a << endl;
97}
98
99void
100test( sc_dt::sc_fxnum_fast_bitref a )
101{
102# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
103    std::stringstream ss;
104# else
105	strstream ss;
106# endif
107
108    cout << a << endl;
109    ss << a;
110    ss >> a;
111    cout << a << endl;
112}
113
114
115void
116test( sc_dt::sc_fxnum_subref a )
117{
118# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
119    std::stringstream ss;
120# else
121	strstream ss;
122# endif
123
124    cout << a << endl;
125    ss << a;
126    ss >> a;
127    cout << a << endl;
128}
129
130void
131test( sc_dt::sc_fxnum_fast_subref a )
132{
133# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
134    std::stringstream ss;
135# else
136	strstream ss;
137# endif
138
139    cout << a << endl;
140    ss << a;
141    ss >> a;
142    cout << a << endl;
143}
144
145template <class T>
146void
147test( T& a )
148{
149# if (defined(__GNUC__) && (__GNUC__ >= 3))|| (defined(_MSC_VER) && (_MSC_VER >= 1300))
150    std::stringstream ss;
151# else
152	strstream ss;
153# endif
154
155    cout << a << endl;
156    ss << a;
157    ss >> a;
158    cout << a << endl;
159}
160
161void
162test_bit()
163{
164    cout << "\n*** test_bit ***" << endl;
165
166    // sc_bit
167    {
168        cout << "\nsc_bit" << endl;
169        sc_bit a( true );
170        sc_bit b( false );
171        test( a );
172        test( b );
173    }
174
175    // sc_logic
176    {
177        cout << "\nsc_logic" << endl;
178        sc_logic a( SC_LOGIC_0 );
179        sc_logic b( SC_LOGIC_1 );
180        sc_logic c( SC_LOGIC_Z );
181        sc_logic d( SC_LOGIC_X );
182        test( a );
183        test( b );
184        test( c );
185        test( d );
186    }
187
188    // sc_bv
189    {
190        cout << "\nsc_bv" << endl;
191        sc_bv<4> a( "0101" );
192        sc_bv<8> b( "11110000" );
193        test( a );
194        test( b );
195    }
196
197    // sc_lv
198    {
199        cout << "\nsc_lv" << endl;
200        sc_lv<4> a( "01ZX" );
201        sc_lv<8> b( "XXZZ1100" );
202        test( a );
203        test( b );
204    }
205
206    // sc_bitref
207    {
208        cout << "\nsc_bitref" << endl;
209        sc_bv<4> a( "0101" );
210        sc_lv<4> b( "01ZX" );
211        test( a[0] );
212        test( b[0] );
213    }
214
215    // sc_subref
216    {
217        cout << "\nsc_subref" << endl;
218        sc_bv<4> a( "0101" );
219        sc_lv<4> b( "01ZX" );
220        test( a( 1, 0 ) );
221        test( b( 1, 0 ) );
222    }
223
224    // sc_concref
225    {
226        cout << "\nsc_concref" << endl;
227        sc_bv<4> a( "0101" );
228        sc_lv<4> b( "01ZX" );
229#if 0 // #### re-enable when concatenation support is homogenous.
230        test( ( a[1], a[0] ) );
231        test( ( b[1], b[0] ) );
232#endif // 0
233    }
234}
235
236void
237test_int()
238{
239    cout << "\n*** test_int ***" << endl;
240
241    // sc_int
242    {
243        cout << "\nsc_int" << endl;
244        sc_int<4> a = -7;
245        sc_int<8> b = 15;
246        test( a );
247        test( b );
248    }
249
250    // sc_int_bitref
251    {
252        cout << "\nsc_int_bitref" << endl;
253        sc_int<4> a = -7;
254        sc_int<8> b = 15;
255        test( a[0] );
256        test( b[0] );
257    }
258
259    // sc_int_subref
260    {
261        cout << "\nsc_int_subref" << endl;
262        sc_int<4> a = -7;
263        sc_int<8> b = 15;
264        test( a( 3, 0 ) );
265        test( b( 3, 0 ) );
266    }
267
268    // sc_int_concref
269    {
270        cout << "\nsc_int_concref" << endl;
271        sc_int<4> a = -7;
272        sc_int<8> b = 15;
273        test( (a[1], a[0]) );
274        test( (b[1], b[0]) );
275    }
276
277    // sc_uint
278    {
279        cout << "\nsc_uint" << endl;
280        sc_uint<4> a = -7;
281        sc_uint<8> b = 15;
282        test( a );
283        test( b );
284    }
285
286    // sc_uint_bitref
287    {
288        cout << "\nsc_uint_bitref" << endl;
289        sc_uint<4> a = -7;
290        sc_uint<8> b = 15;
291        test( a[0] );
292        test( b[0] );
293    }
294
295    // sc_uint_subref
296    {
297        cout << "\nsc_uint_subref" << endl;
298        sc_uint<4> a = -7;
299        sc_uint<8> b = 15;
300        test( a( 3, 0 ) );
301        test( b( 3, 0 ) );
302    }
303
304    // sc_uint_concref
305    {
306        cout << "\nsc_uint_concref" << endl;
307        sc_uint<4> a = -7;
308        sc_uint<8> b = 15;
309        test( (a[1], a[0]) );
310        test( (b[1], b[0]) );
311    }
312
313    // sc_bigint
314    {
315        cout << "\nsc_bigint" << endl;
316        sc_bigint<4> a = -7;
317        sc_bigint<8> b = 15;
318        test( a );
319        test( b );
320    }
321
322    // sc_signed_bitref
323    {
324        cout << "\nsc_signed_bitref" << endl;
325        sc_bigint<4> a = -7;
326        sc_bigint<8> b = 15;
327        test( a[0] );
328        test( b[0] );
329    }
330
331    // sc_signed_subref
332    {
333        cout << "\nsc_signed_subref" << endl;
334        sc_bigint<4> a = -7;
335        sc_bigint<8> b = 15;
336        test( a( 3, 0 ) );
337        test( b( 3, 0 ) );
338    }
339
340    // sc_signed_concref
341    {
342        sc_bigint<4> a = -7;
343        sc_bigint<8> b = 15;
344        test( (a[1], a[0]) );
345        test( (b[1], b[0]) );
346    }
347
348    // sc_biguint
349    {
350        cout << "\nsc_biguint" << endl;
351        sc_biguint<4> a = -7;
352        sc_biguint<8> b = 15;
353        test( a );
354        test( b );
355    }
356
357    // sc_unsigned_bitref
358    {
359        cout << "\nsc_unsigned_bitref" << endl;
360        sc_biguint<4> a = -7;
361        sc_biguint<8> b = 15;
362        test( a[0] );
363        test( b[0] );
364    }
365
366    // sc_unsigned_subref
367    {
368        cout << "\nsc_unsigned_subref" << endl;
369        sc_biguint<4> a = -7;
370        sc_biguint<8> b = 15;
371        test( a( 3, 0 ) );
372        test( b( 3, 0 ) );
373    }
374
375    // sc_unsigned_concref
376    {
377        sc_biguint<4> a = -7;
378        sc_biguint<8> b = 15;
379        test( (a[1], a[0]) );
380        test( (b[1], b[0]) );
381    }
382}
383
384void
385test_fx()
386{
387    cout << "\n*** test_fx ***" << endl;
388
389    // sc_fxnum
390    {
391        cout << "\nsc_fxnum" << endl;
392        sc_fixed<4,4> a = -7;
393        sc_fixed<8,8> b = 15;
394        test( a );
395        test( b );
396    }
397
398    // sc_fxnum_fast
399    {
400        cout << "\nsc_fxnum_fast" << endl;
401        sc_fixed_fast<4,4> a = -7;
402        sc_fixed_fast<8,8> b = 15;
403        test( a );
404        test( b );
405    }
406
407    // sc_fxnum_bitref
408    {
409        cout << "\nsc_fxnum_bitref" << endl;
410        sc_fixed<4,4> a = -7;
411        sc_fixed<8,8> b = 15;
412        test( a[0] );
413        test( b[0] );
414    }
415
416    // sc_fxnum_fast_bitref
417    {
418        cout << "\nsc_fxnum_fast_bitref" << endl;
419        sc_fixed_fast<4,4> a = -7;
420        sc_fixed_fast<8,8> b = 15;
421        test( a[0] );
422        test( b[0] );
423    }
424
425    // sc_fxnum_subref
426    {
427        cout << "\nsc_fxnum_subref" << endl;
428        sc_fixed<4,4> a = -7;
429        sc_fixed<8,8> b = 15;
430        test( a( 3, 0 ) );
431        test( b( 3, 0 ) );
432    }
433
434    // sc_fxnum_fast_subref
435    {
436        cout << "\nsc_fxnum_fast_subref" << endl;
437        sc_fixed_fast<4,4> a = -7;
438        sc_fixed_fast<8,8> b = 15;
439        test( a( 3, 0 ) );
440        test( b( 3, 0 ) );
441    }
442
443    // sc_fxval
444    {
445        cout << "\nsc_fxval" << endl;
446        sc_fxval a(-7);
447        sc_fxval b(15);
448        test( a );
449        test( b );
450    }
451
452    // sc_fxval_fast
453    {
454        cout << "\nsc_fxval_fast" << endl;
455        sc_fxval_fast a(-7);
456        sc_fxval_fast b(15);
457        test( a );
458        test( b );
459    }
460}
461
462int
463sc_main( int, char*[] )
464{
465    test_bit();
466    test_int();
467    test_fx();
468
469    return 0;
470}
471