diff options
Diffstat (limited to 'src/systemc/tests/systemc/datatypes/int/string_conversion/test01')
-rw-r--r-- | src/systemc/tests/systemc/datatypes/int/string_conversion/test01/golden/test01.log | 32 | ||||
-rw-r--r-- | src/systemc/tests/systemc/datatypes/int/string_conversion/test01/test01.cpp | 200 |
2 files changed, 232 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/datatypes/int/string_conversion/test01/golden/test01.log b/src/systemc/tests/systemc/datatypes/int/string_conversion/test01/golden/test01.log new file mode 100644 index 000000000..414113f5b --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/string_conversion/test01/golden/test01.log @@ -0,0 +1,32 @@ +SystemC Simulation +*** test_string_conversions +sc_int +-1 +0b11111111 +negative +-0bsm00000001 +0o777 +negative +-0osm001 +0xff +negative +-0xsm01 +-1 +0csd0000000- +-1 +255 +sc_uint +255 +0b011111111 +0bus11111111 +0bsm11111111 +0o377 +0ous377 +0osm377 +0x0ff +0xusff +0xsmff +255 +0csd10000000- +255 +255 diff --git a/src/systemc/tests/systemc/datatypes/int/string_conversion/test01/test01.cpp b/src/systemc/tests/systemc/datatypes/int/string_conversion/test01/test01.cpp new file mode 100644 index 000000000..93e6a01cf --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/int/string_conversion/test01/test01.cpp @@ -0,0 +1,200 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +/***************************************************************************** + + test01.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// test string conversion of sc_[u]int + +#include "systemc.h" + +void +test_string_conversions() +{ + cout << "*** test_string_conversions" << endl; + { + cout << "sc_int" << endl; + + sc_int<8> a = -1; + sc_int<8> b; + std::string s; + + s = a.to_string(); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_BIN ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_BIN_US ); + cout << s << endl; + // b = s.c_str(); + // sc_assert( b == a ); + + s = a.to_string( SC_BIN_SM ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_OCT ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_OCT_US ); + cout << s << endl; + // b = s.c_str(); + // sc_assert( b == a ); + + s = a.to_string( SC_OCT_SM ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_HEX ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_HEX_US ); + cout << s << endl; + // b = s.c_str(); + // sc_assert( b == a ); + + s = a.to_string( SC_HEX_SM ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_DEC ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_CSD ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + sc_int<8> c( a.to_string().c_str() ); + cout << c.to_string() << endl; + + c.range( 7, 0 ) = a.to_string().c_str(); + cout << c.range( 7, 0 ).to_string() << endl; + } + { + cout << "sc_uint" << endl; + + sc_uint<8> a = -1; + sc_uint<8> b; + std::string s; + + s = a.to_string(); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_BIN ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_BIN_US ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_BIN_SM ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_OCT ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_OCT_US ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_OCT_SM ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_HEX ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_HEX_US ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_HEX_SM ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_DEC ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + s = a.to_string( SC_CSD ); + cout << s << endl; + b = s.c_str(); + sc_assert( b == a ); + + sc_uint<8> c( a.to_string().c_str() ); + cout << c.to_string() << endl; + + c.range( 7, 0 ) = a.to_string().c_str(); + cout << c.range( 7, 0 ).to_string() << endl; + } +} + +int +sc_main( int, char*[] ) +{ + test_string_conversions(); + + return 0; +} |