sc_logic.cpp revision 12027
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 sc_logic.cpp -- C++ implementation of logic type. Behaves 23 pretty much the same way as HDLs logic type. 24 25 Original Author: Stan Y. Liao, Synopsys, Inc. 26 27 *****************************************************************************/ 28 29/***************************************************************************** 30 31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 32 changes you are making here. 33 34 Name, Affiliation, Date: 35 Description of Modification: 36 37 *****************************************************************************/ 38 39 40// $Log: sc_logic.cpp,v $ 41// Revision 1.1.1.1 2006/12/15 20:20:04 acg 42// SystemC 2.3 43// 44// Revision 1.3 2006/01/13 18:53:53 acg 45// Andy Goodrich: added $Log command so that CVS comments are reproduced in 46// the source. 47// 48 49#include "sysc/datatypes/bit/sc_bit_ids.h" 50#include "sysc/datatypes/bit/sc_logic.h" 51 52 53namespace sc_dt 54{ 55 56// ---------------------------------------------------------------------------- 57// CLASS : sc_logic 58// 59// Four-valued logic type. 60// ---------------------------------------------------------------------------- 61 62// support methods 63 64void 65sc_logic::invalid_value( sc_logic_value_t v ) 66{ 67 char msg[BUFSIZ]; 68 std::sprintf( msg, "sc_logic( %d )", v ); 69 SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg ); 70} 71 72void 73sc_logic::invalid_value( char c ) 74{ 75 char msg[BUFSIZ]; 76 std::sprintf( msg, "sc_logic( '%c' )", c ); 77 SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg ); 78} 79 80void 81sc_logic::invalid_value( int i ) 82{ 83 char msg[BUFSIZ]; 84 std::sprintf( msg, "sc_logic( %d )", i ); 85 SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg ); 86} 87 88 89void 90sc_logic::invalid_01() const 91{ 92 if( (int) m_val == Log_Z ) { 93 SC_REPORT_WARNING( sc_core::SC_ID_LOGIC_Z_TO_BOOL_, 0 ); 94 } else { 95 SC_REPORT_WARNING( sc_core::SC_ID_LOGIC_X_TO_BOOL_, 0 ); 96 } 97} 98 99 100// conversion tables 101 102const sc_logic_value_t sc_logic::char_to_logic[128] = 103{ 104 Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X, 105 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 106 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 107 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 108 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 109 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 110 Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 111 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 112 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 113 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 114 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 115 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X, 116 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 117 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 118 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, 119 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X 120}; 121 122const char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' }; 123 124const sc_logic_value_t sc_logic::and_table[4][4] = 125{ 126 { Log_0, Log_0, Log_0, Log_0 }, 127 { Log_0, Log_1, Log_X, Log_X }, 128 { Log_0, Log_X, Log_X, Log_X }, 129 { Log_0, Log_X, Log_X, Log_X } 130}; 131 132const sc_logic_value_t sc_logic::or_table[4][4] = 133{ 134 { Log_0, Log_1, Log_X, Log_X }, 135 { Log_1, Log_1, Log_1, Log_1 }, 136 { Log_X, Log_1, Log_X, Log_X }, 137 { Log_X, Log_1, Log_X, Log_X } 138}; 139 140const sc_logic_value_t sc_logic::xor_table[4][4] = 141{ 142 { Log_0, Log_1, Log_X, Log_X }, 143 { Log_1, Log_0, Log_X, Log_X }, 144 { Log_X, Log_X, Log_X, Log_X }, 145 { Log_X, Log_X, Log_X, Log_X } 146}; 147 148const sc_logic_value_t sc_logic::not_table[4] = 149 { Log_1, Log_0, Log_X, Log_X }; 150 151 152// other methods 153 154void 155sc_logic::scan( ::std::istream& is ) 156{ 157 char c; 158 is >> c; 159 *this = c; 160} 161 162 163// #ifdef SC_DT_DEPRECATED 164const sc_logic sc_logic_0( Log_0 ); 165const sc_logic sc_logic_1( Log_1 ); 166const sc_logic sc_logic_Z( Log_Z ); 167const sc_logic sc_logic_X( Log_X ); 168// #endif 169 170const sc_logic SC_LOGIC_0( Log_0 ); 171const sc_logic SC_LOGIC_1( Log_1 ); 172const sc_logic SC_LOGIC_Z( Log_Z ); 173const sc_logic SC_LOGIC_X( Log_X ); 174 175} // namespace sc_dt 176