112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de/***************************************************************************** 2112027Sjungma@eit.uni-kl.de 2212027Sjungma@eit.uni-kl.de sc_logic.cpp -- C++ implementation of logic type. Behaves 2312027Sjungma@eit.uni-kl.de pretty much the same way as HDLs logic type. 2412027Sjungma@eit.uni-kl.de 2512027Sjungma@eit.uni-kl.de Original Author: Stan Y. Liao, Synopsys, Inc. 2612027Sjungma@eit.uni-kl.de 2712027Sjungma@eit.uni-kl.de *****************************************************************************/ 2812027Sjungma@eit.uni-kl.de 2912027Sjungma@eit.uni-kl.de/***************************************************************************** 3012027Sjungma@eit.uni-kl.de 3112027Sjungma@eit.uni-kl.de MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3212027Sjungma@eit.uni-kl.de changes you are making here. 3312027Sjungma@eit.uni-kl.de 3412027Sjungma@eit.uni-kl.de Name, Affiliation, Date: 3512027Sjungma@eit.uni-kl.de Description of Modification: 3612027Sjungma@eit.uni-kl.de 3712027Sjungma@eit.uni-kl.de *****************************************************************************/ 3812027Sjungma@eit.uni-kl.de 3912027Sjungma@eit.uni-kl.de 4012027Sjungma@eit.uni-kl.de// $Log: sc_logic.cpp,v $ 4112027Sjungma@eit.uni-kl.de// Revision 1.1.1.1 2006/12/15 20:20:04 acg 4212027Sjungma@eit.uni-kl.de// SystemC 2.3 4312027Sjungma@eit.uni-kl.de// 4412027Sjungma@eit.uni-kl.de// Revision 1.3 2006/01/13 18:53:53 acg 4512027Sjungma@eit.uni-kl.de// Andy Goodrich: added $Log command so that CVS comments are reproduced in 4612027Sjungma@eit.uni-kl.de// the source. 4712027Sjungma@eit.uni-kl.de// 4812027Sjungma@eit.uni-kl.de 4912027Sjungma@eit.uni-kl.de#include "sysc/datatypes/bit/sc_bit_ids.h" 5012027Sjungma@eit.uni-kl.de#include "sysc/datatypes/bit/sc_logic.h" 5112027Sjungma@eit.uni-kl.de 5212027Sjungma@eit.uni-kl.de 5312027Sjungma@eit.uni-kl.denamespace sc_dt 5412027Sjungma@eit.uni-kl.de{ 5512027Sjungma@eit.uni-kl.de 5612027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 5712027Sjungma@eit.uni-kl.de// CLASS : sc_logic 5812027Sjungma@eit.uni-kl.de// 5912027Sjungma@eit.uni-kl.de// Four-valued logic type. 6012027Sjungma@eit.uni-kl.de// ---------------------------------------------------------------------------- 6112027Sjungma@eit.uni-kl.de 6212027Sjungma@eit.uni-kl.de// support methods 6312027Sjungma@eit.uni-kl.de 6412027Sjungma@eit.uni-kl.devoid 6512027Sjungma@eit.uni-kl.desc_logic::invalid_value( sc_logic_value_t v ) 6612027Sjungma@eit.uni-kl.de{ 6712027Sjungma@eit.uni-kl.de char msg[BUFSIZ]; 6812027Sjungma@eit.uni-kl.de std::sprintf( msg, "sc_logic( %d )", v ); 6912027Sjungma@eit.uni-kl.de SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg ); 7012027Sjungma@eit.uni-kl.de} 7112027Sjungma@eit.uni-kl.de 7212027Sjungma@eit.uni-kl.devoid 7312027Sjungma@eit.uni-kl.desc_logic::invalid_value( char c ) 7412027Sjungma@eit.uni-kl.de{ 7512027Sjungma@eit.uni-kl.de char msg[BUFSIZ]; 7612027Sjungma@eit.uni-kl.de std::sprintf( msg, "sc_logic( '%c' )", c ); 7712027Sjungma@eit.uni-kl.de SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg ); 7812027Sjungma@eit.uni-kl.de} 7912027Sjungma@eit.uni-kl.de 8012027Sjungma@eit.uni-kl.devoid 8112027Sjungma@eit.uni-kl.desc_logic::invalid_value( int i ) 8212027Sjungma@eit.uni-kl.de{ 8312027Sjungma@eit.uni-kl.de char msg[BUFSIZ]; 8412027Sjungma@eit.uni-kl.de std::sprintf( msg, "sc_logic( %d )", i ); 8512027Sjungma@eit.uni-kl.de SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg ); 8612027Sjungma@eit.uni-kl.de} 8712027Sjungma@eit.uni-kl.de 8812027Sjungma@eit.uni-kl.de 8912027Sjungma@eit.uni-kl.devoid 9012027Sjungma@eit.uni-kl.desc_logic::invalid_01() const 9112027Sjungma@eit.uni-kl.de{ 9212027Sjungma@eit.uni-kl.de if( (int) m_val == Log_Z ) { 9312027Sjungma@eit.uni-kl.de SC_REPORT_WARNING( sc_core::SC_ID_LOGIC_Z_TO_BOOL_, 0 ); 9412027Sjungma@eit.uni-kl.de } else { 9512027Sjungma@eit.uni-kl.de SC_REPORT_WARNING( sc_core::SC_ID_LOGIC_X_TO_BOOL_, 0 ); 9612027Sjungma@eit.uni-kl.de } 9712027Sjungma@eit.uni-kl.de} 9812027Sjungma@eit.uni-kl.de 9912027Sjungma@eit.uni-kl.de 10012027Sjungma@eit.uni-kl.de// conversion tables 10112027Sjungma@eit.uni-kl.de 10212027Sjungma@eit.uni-kl.deconst sc_logic_value_t sc_logic::char_to_logic[128] = 10312027Sjungma@eit.uni-kl.de{ 10412027Sjungma@eit.uni-kl.de Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X, 10512027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 10612027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 10712027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 10812027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 10912027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11012027Sjungma@eit.uni-kl.de Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11112027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11212027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11312027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11412027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11512027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X, 11612027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11712027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11812027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 11912027Sjungma@eit.uni-kl.de Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X 12012027Sjungma@eit.uni-kl.de}; 12112027Sjungma@eit.uni-kl.de 12212027Sjungma@eit.uni-kl.deconst char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' }; 12312027Sjungma@eit.uni-kl.de 12412027Sjungma@eit.uni-kl.deconst sc_logic_value_t sc_logic::and_table[4][4] = 12512027Sjungma@eit.uni-kl.de{ 12612027Sjungma@eit.uni-kl.de { Log_0, Log_0, Log_0, Log_0 }, 12712027Sjungma@eit.uni-kl.de { Log_0, Log_1, Log_X, Log_X }, 12812027Sjungma@eit.uni-kl.de { Log_0, Log_X, Log_X, Log_X }, 12912027Sjungma@eit.uni-kl.de { Log_0, Log_X, Log_X, Log_X } 13012027Sjungma@eit.uni-kl.de}; 13112027Sjungma@eit.uni-kl.de 13212027Sjungma@eit.uni-kl.deconst sc_logic_value_t sc_logic::or_table[4][4] = 13312027Sjungma@eit.uni-kl.de{ 13412027Sjungma@eit.uni-kl.de { Log_0, Log_1, Log_X, Log_X }, 13512027Sjungma@eit.uni-kl.de { Log_1, Log_1, Log_1, Log_1 }, 13612027Sjungma@eit.uni-kl.de { Log_X, Log_1, Log_X, Log_X }, 13712027Sjungma@eit.uni-kl.de { Log_X, Log_1, Log_X, Log_X } 13812027Sjungma@eit.uni-kl.de}; 13912027Sjungma@eit.uni-kl.de 14012027Sjungma@eit.uni-kl.deconst sc_logic_value_t sc_logic::xor_table[4][4] = 14112027Sjungma@eit.uni-kl.de{ 14212027Sjungma@eit.uni-kl.de { Log_0, Log_1, Log_X, Log_X }, 14312027Sjungma@eit.uni-kl.de { Log_1, Log_0, Log_X, Log_X }, 14412027Sjungma@eit.uni-kl.de { Log_X, Log_X, Log_X, Log_X }, 14512027Sjungma@eit.uni-kl.de { Log_X, Log_X, Log_X, Log_X } 14612027Sjungma@eit.uni-kl.de}; 14712027Sjungma@eit.uni-kl.de 14812027Sjungma@eit.uni-kl.deconst sc_logic_value_t sc_logic::not_table[4] = 14912027Sjungma@eit.uni-kl.de { Log_1, Log_0, Log_X, Log_X }; 15012027Sjungma@eit.uni-kl.de 15112027Sjungma@eit.uni-kl.de 15212027Sjungma@eit.uni-kl.de// other methods 15312027Sjungma@eit.uni-kl.de 15412027Sjungma@eit.uni-kl.devoid 15512027Sjungma@eit.uni-kl.desc_logic::scan( ::std::istream& is ) 15612027Sjungma@eit.uni-kl.de{ 15712027Sjungma@eit.uni-kl.de char c; 15812027Sjungma@eit.uni-kl.de is >> c; 15912027Sjungma@eit.uni-kl.de *this = c; 16012027Sjungma@eit.uni-kl.de} 16112027Sjungma@eit.uni-kl.de 16212027Sjungma@eit.uni-kl.de 16312027Sjungma@eit.uni-kl.de// #ifdef SC_DT_DEPRECATED 16412027Sjungma@eit.uni-kl.deconst sc_logic sc_logic_0( Log_0 ); 16512027Sjungma@eit.uni-kl.deconst sc_logic sc_logic_1( Log_1 ); 16612027Sjungma@eit.uni-kl.deconst sc_logic sc_logic_Z( Log_Z ); 16712027Sjungma@eit.uni-kl.deconst sc_logic sc_logic_X( Log_X ); 16812027Sjungma@eit.uni-kl.de// #endif 16912027Sjungma@eit.uni-kl.de 17012027Sjungma@eit.uni-kl.deconst sc_logic SC_LOGIC_0( Log_0 ); 17112027Sjungma@eit.uni-kl.deconst sc_logic SC_LOGIC_1( Log_1 ); 17212027Sjungma@eit.uni-kl.deconst sc_logic SC_LOGIC_Z( Log_Z ); 17312027Sjungma@eit.uni-kl.deconst sc_logic SC_LOGIC_X( Log_X ); 17412027Sjungma@eit.uni-kl.de 17512027Sjungma@eit.uni-kl.de} // namespace sc_dt 176