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 string conversion of sc_[u]int
39
40#include "systemc.h"
41
42void
43test_string_conversions()
44{
45    cout << "*** test_string_conversions" << endl;
46    {
47	cout << "sc_int" << endl;
48
49        sc_int<8> a = -1;
50        sc_int<8> b;
51	std::string s;
52
53	s = a.to_string();
54	cout << s << endl;
55	b = s.c_str();
56	sc_assert( b == a );
57
58	s = a.to_string( SC_BIN );
59	cout << s << endl;
60	b = s.c_str();
61	sc_assert( b == a );
62
63	s = a.to_string( SC_BIN_US );
64	cout << s << endl;
65	// b = s.c_str();
66	// sc_assert( b == a );
67
68	s = a.to_string( SC_BIN_SM );
69	cout << s << endl;
70	b = s.c_str();
71	sc_assert( b == a );
72
73	s = a.to_string( SC_OCT );
74	cout << s << endl;
75	b = s.c_str();
76	sc_assert( b == a );
77
78	s = a.to_string( SC_OCT_US );
79	cout << s << endl;
80	// b = s.c_str();
81	// sc_assert( b == a );
82
83	s = a.to_string( SC_OCT_SM );
84	cout << s << endl;
85	b = s.c_str();
86	sc_assert( b == a );
87
88	s = a.to_string( SC_HEX );
89	cout << s << endl;
90	b = s.c_str();
91	sc_assert( b == a );
92
93	s = a.to_string( SC_HEX_US );
94	cout << s << endl;
95	// b = s.c_str();
96	// sc_assert( b == a );
97
98	s = a.to_string( SC_HEX_SM );
99	cout << s << endl;
100	b = s.c_str();
101	sc_assert( b == a );
102
103	s = a.to_string( SC_DEC );
104	cout << s << endl;
105	b = s.c_str();
106	sc_assert( b == a );
107
108	s = a.to_string( SC_CSD );
109	cout << s << endl;
110	b = s.c_str();
111	sc_assert( b == a );
112
113	sc_int<8> c( a.to_string().c_str() );
114	cout << c.to_string() << endl;
115
116	c.range( 7, 0 ) = a.to_string().c_str();
117	cout << c.range( 7, 0 ).to_string() << endl;
118    }
119    {
120	cout << "sc_uint" << endl;
121
122        sc_uint<8> a = -1;
123        sc_uint<8> b;
124	std::string s;
125
126	s = a.to_string();
127	cout << s << endl;
128	b = s.c_str();
129	sc_assert( b == a );
130
131	s = a.to_string( SC_BIN );
132	cout << s << endl;
133	b = s.c_str();
134	sc_assert( b == a );
135
136	s = a.to_string( SC_BIN_US );
137	cout << s << endl;
138	b = s.c_str();
139	sc_assert( b == a );
140
141	s = a.to_string( SC_BIN_SM );
142	cout << s << endl;
143	b = s.c_str();
144	sc_assert( b == a );
145
146	s = a.to_string( SC_OCT );
147	cout << s << endl;
148	b = s.c_str();
149	sc_assert( b == a );
150
151	s = a.to_string( SC_OCT_US );
152	cout << s << endl;
153	b = s.c_str();
154	sc_assert( b == a );
155
156	s = a.to_string( SC_OCT_SM );
157	cout << s << endl;
158	b = s.c_str();
159	sc_assert( b == a );
160
161	s = a.to_string( SC_HEX );
162	cout << s << endl;
163	b = s.c_str();
164	sc_assert( b == a );
165
166	s = a.to_string( SC_HEX_US );
167	cout << s << endl;
168	b = s.c_str();
169	sc_assert( b == a );
170
171	s = a.to_string( SC_HEX_SM );
172	cout << s << endl;
173	b = s.c_str();
174	sc_assert( b == a );
175
176	s = a.to_string( SC_DEC );
177	cout << s << endl;
178	b = s.c_str();
179	sc_assert( b == a );
180
181	s = a.to_string( SC_CSD );
182	cout << s << endl;
183	b = s.c_str();
184	sc_assert( b == a );
185
186	sc_uint<8> c( a.to_string().c_str() );
187	cout << c.to_string() << endl;
188
189	c.range( 7, 0 ) = a.to_string().c_str();
190	cout << c.range( 7, 0 ).to_string() << endl;
191    }
192}
193
194int
195sc_main( int, char*[] )
196{
197    test_string_conversions();
198
199    return 0;
200}
201