diff options
author | Gabe Black <gabeblack@google.com> | 2018-05-24 01:37:55 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-08-08 10:09:54 +0000 |
commit | 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch) | |
tree | 7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype | |
parent | 7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff) | |
download | gem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz |
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6
Reviewed-on: https://gem5-review.googlesource.com/10845
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype')
2 files changed, 127 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype/c_array_datatype.cpp b/src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype/c_array_datatype.cpp new file mode 100644 index 000000000..db29e9061 --- /dev/null +++ b/src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype/c_array_datatype.cpp @@ -0,0 +1,110 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + c_array_datatype.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: + + *****************************************************************************/ + +/* Main file for "C array" data type */ + +#include "systemc.h" + +int sc_main(int ac, char *av[]) +{ + +// 1. DECLARATION SYNTAX + int a[4] = { 0, 23, -534, 23423 }; + long b[4] = { 0, 23, -534, 23423 }; + short c[4] = { 0, 23, -534, 23423 }; + char d[9] = { 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-' }; + + unsigned int e[4] = { 0, 23, 534, 23423 }; + unsigned long f[4] = { 0, 23, 534, 23423 }; + unsigned short g[4] = { 0, 23, 534, 23423 }; + unsigned char h[9] = { 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-' }; + + float i[4] = { 0, 4.89, -345.6778, 543222.898394322 }; + double j[4] = { 0, 4.89, -345.6778, 543222.898394322 }; +// type 'long double' is non-portable +// long double k[4] = { 0, 4.89, -345.6778, 543222.898394322 }; + + bool l[4] = { 0, 1, true, false }; + + sc_logic m[9] = { sc_logic('U'), sc_logic('X'), sc_logic('0'), sc_logic('1'), + sc_logic('Z'), sc_logic('W'), sc_logic('L'), sc_logic('H'), sc_logic('-') }; + + +// 2. TYPE CONVERSION + + // No type conversion because assignment of arrays is illegal + +// 3. OPERATORS +// Supported operators: [] + + cout.precision(15); + cout << "\nINT \t\t" + << a[0] << "\t" << a[1] << "\t" << a[2] << "\t" << a[3] + << "\nLONG \t\t" + << b[0] << "\t" << b[1] << "\t" << b[2] << "\t" << b[3] + << "\nSHORT \t\t" + << c[0] << "\t" << c[1] << "\t" << c[2] << "\t" << c[3] + << "\nCHAR \t\t" + << d[0] << "\t" << d[1] << "\t" << d[2] << "\t" + << d[3] << "\t" << d[4] << "\t" << d[5] << "\t" + << d[6] << "\t" << d[7] << "\t" << d[8] + << "\n\nUNSIGNED INT \t" + << e[0] << "\t" << e[1] << "\t" << e[2] << "\t" << e[3] + << "\nUNSIGNED LONG \t" + << f[0] << "\t" << f[1] << "\t" << f[2] << "\t" << f[3] + << "\nUNSIGNED SHORT \t" + << g[0] << "\t" << g[1] << "\t" << g[2] << "\t" << g[3] + << "\nUNSIGNED CHAR \t" + << h[0] << "\t" << h[1] << "\t" << h[2] << "\t" + << h[3] << "\t" << h[4] << "\t" << h[5] << "\t" + << h[6] << "\t" << h[7] << "\t" << h[8] + << "\n\nFLOAT \t\t" + << i[0] << "\t" << i[1] << "\t" << i[2] << "\t" << i[3] + << "\nDOUBLE \t\t" + << j[0] << "\t" << j[1] << "\t" << j[2] << "\t" << j[3] +// type 'long double' is non-portable +// << "\nLONG DOUBLE \t" +// << k[0] << "\t" << k[1] << "\t" << k[2] << "\t" << k[3] + << "\n\nBOOL \t\t" + << l[0] << "\t" << l[1] << "\t" << l[2] << "\t" << l[3] + << "\nSTD_ULOGIC \t" + << m[0] << "\t" << m[1] << "\t" << m[2] << "\t" + << m[3] << "\t" << m[4] << "\t" << m[5] << "\t" + << m[6] << "\t" << m[7] << "\t" << m[8] + << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype/golden/c_array_datatype.log b/src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype/golden/c_array_datatype.log new file mode 100644 index 000000000..3e0671235 --- /dev/null +++ b/src/systemc/tests/systemc/misc/unit/data/user_guide/ch9/c_array_datatype/golden/c_array_datatype.log @@ -0,0 +1,17 @@ +SystemC Simulation + +INT 0 23 -534 23423 +LONG 0 23 -534 23423 +SHORT 0 23 -534 23423 +CHAR U X 0 1 Z W L H - + +UNSIGNED INT 0 23 534 23423 +UNSIGNED LONG 0 23 534 23423 +UNSIGNED SHORT 0 23 534 23423 +UNSIGNED CHAR U X 0 1 Z W L H - + +FLOAT 0 4.8899998664856 -345.677795410156 543222.875 +DOUBLE 0 4.89 -345.6778 543222.898394322 + +BOOL 0 1 1 0 +STD_ULOGIC X X 0 1 Z X X X X |