sc_logic.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_logic.cpp -- C++ implementation of logic type. Behaves
00021                   pretty much the same way as HDLs logic type.
00022 
00023   Original Author: Stan Y. Liao, Synopsys, Inc.
00024 
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034 
00035  *****************************************************************************/
00036 
00037 
00038 // $Log: sc_logic.cpp,v $
00039 // Revision 1.1.1.1  2006/12/15 20:31:36  acg
00040 // SystemC 2.2
00041 //
00042 // Revision 1.3  2006/01/13 18:53:53  acg
00043 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
00044 // the source.
00045 //
00046 
00047 #include "sysc/utils/sc_string.h"
00048 #include "sysc/datatypes/bit/sc_bit_ids.h"
00049 #include "sysc/datatypes/bit/sc_logic.h"
00050 
00051 
00052 namespace sc_dt
00053 {
00054 
00055 // ----------------------------------------------------------------------------
00056 //  CLASS : sc_logic
00057 //
00058 //  Four-valued logic type.
00059 // ----------------------------------------------------------------------------
00060 
00061 // support methods
00062 
00063 void
00064 sc_logic::invalid_value( sc_logic_value_t v )
00065 {
00066     char msg[BUFSIZ];
00067     std::sprintf( msg, "sc_logic( %d )", v );
00068     SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg );
00069 }
00070 
00071 void
00072 sc_logic::invalid_value( char c )
00073 {
00074     char msg[BUFSIZ];
00075     std::sprintf( msg, "sc_logic( '%c' )", c );
00076     SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg );
00077 }
00078 
00079 void
00080 sc_logic::invalid_value( int i )
00081 {
00082     char msg[BUFSIZ];
00083     std::sprintf( msg, "sc_logic( %d )", i );
00084     SC_REPORT_ERROR( sc_core::SC_ID_VALUE_NOT_VALID_, msg );
00085 }
00086 
00087 
00088 void
00089 sc_logic::invalid_01() const
00090 {
00091     if( (int) m_val == Log_Z ) {
00092     SC_REPORT_WARNING( sc_core::SC_ID_LOGIC_Z_TO_BOOL_, 0 );
00093     } else {
00094     SC_REPORT_WARNING( sc_core::SC_ID_LOGIC_X_TO_BOOL_, 0 );
00095     }
00096 }
00097 
00098 
00099 // conversion tables
00100 
00101 const sc_logic_value_t sc_logic::char_to_logic[128] =
00102 {
00103     Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
00104     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00105     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00106     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00107     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00108     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00109     Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00110     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00111     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00112     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00113     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00114     Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
00115     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00116     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00117     Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
00118     Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X
00119 };
00120 
00121 const char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' };
00122 
00123 const sc_logic_value_t sc_logic::and_table[4][4] =
00124 {
00125     { Log_0, Log_0, Log_0, Log_0 },
00126     { Log_0, Log_1, Log_X, Log_X },
00127     { Log_0, Log_X, Log_X, Log_X },
00128     { Log_0, Log_X, Log_X, Log_X }
00129 };
00130 
00131 const sc_logic_value_t sc_logic::or_table[4][4] =
00132 {
00133     { Log_0, Log_1, Log_X, Log_X },
00134     { Log_1, Log_1, Log_1, Log_1 },
00135     { Log_X, Log_1, Log_X, Log_X },
00136     { Log_X, Log_1, Log_X, Log_X }
00137 };
00138 
00139 const sc_logic_value_t sc_logic::xor_table[4][4] =
00140 {
00141     { Log_0, Log_1, Log_X, Log_X },
00142     { Log_1, Log_0, Log_X, Log_X },
00143     { Log_X, Log_X, Log_X, Log_X },
00144     { Log_X, Log_X, Log_X, Log_X }
00145 };
00146 
00147 const sc_logic_value_t sc_logic::not_table[4] =
00148     { Log_1, Log_0, Log_X, Log_X  };
00149 
00150 
00151 // other methods
00152 
00153 void
00154 sc_logic::scan( ::std::istream& is )
00155 {
00156     char c;
00157     is >> c;
00158     *this = c;
00159 }
00160 
00161 
00162 // #ifdef SC_DT_DEPRECATED
00163 const sc_logic sc_logic_0( Log_0 );
00164 const sc_logic sc_logic_1( Log_1 );
00165 const sc_logic sc_logic_Z( Log_Z );
00166 const sc_logic sc_logic_X( Log_X );
00167 // #endif
00168 
00169 const sc_logic SC_LOGIC_0( Log_0 );
00170 const sc_logic SC_LOGIC_1( Log_1 );
00171 const sc_logic SC_LOGIC_Z( Log_Z );
00172 const sc_logic SC_LOGIC_X( Log_X );
00173 
00174 } // namespace sc_dt

Generated on Wed Jan 21 15:32:07 2009 for SystemC by  doxygen 1.5.5