112854Sgabeblack@google.com/*****************************************************************************
212854Sgabeblack@google.com
312854Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412854Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512854Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612854Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712854Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812854Sgabeblack@google.com  License.  You may obtain a copy of the License at
912854Sgabeblack@google.com
1012854Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112854Sgabeblack@google.com
1212854Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312854Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412854Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512854Sgabeblack@google.com  implied.  See the License for the specific language governing
1612854Sgabeblack@google.com  permissions and limitations under the License.
1712854Sgabeblack@google.com
1812854Sgabeblack@google.com *****************************************************************************/
1912854Sgabeblack@google.com
2012854Sgabeblack@google.com/*****************************************************************************
2112854Sgabeblack@google.com
2212854Sgabeblack@google.com  sc_logic.cpp -- C++ implementation of logic type. Behaves
2312854Sgabeblack@google.com                  pretty much the same way as HDLs logic type.
2412854Sgabeblack@google.com
2512854Sgabeblack@google.com  Original Author: Stan Y. Liao, Synopsys, Inc.
2612854Sgabeblack@google.com
2712854Sgabeblack@google.com *****************************************************************************/
2812854Sgabeblack@google.com
2912854Sgabeblack@google.com/*****************************************************************************
3012854Sgabeblack@google.com
3112854Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3212854Sgabeblack@google.com  changes you are making here.
3312854Sgabeblack@google.com
3412854Sgabeblack@google.com      Name, Affiliation, Date:
3512854Sgabeblack@google.com  Description of Modification:
3612854Sgabeblack@google.com
3712854Sgabeblack@google.com *****************************************************************************/
3812854Sgabeblack@google.com
3912854Sgabeblack@google.com
4012854Sgabeblack@google.com// $Log: sc_logic.cpp,v $
4112854Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:20:04  acg
4212854Sgabeblack@google.com// SystemC 2.3
4312854Sgabeblack@google.com//
4412854Sgabeblack@google.com// Revision 1.3  2006/01/13 18:53:53  acg
4512854Sgabeblack@google.com// Andy Goodrich: added $Log command so that CVS comments are reproduced in
4612854Sgabeblack@google.com// the source.
4712854Sgabeblack@google.com//
4812854Sgabeblack@google.com
4912854Sgabeblack@google.com#include <sstream>
5012854Sgabeblack@google.com
5113325Sgabeblack@google.com#include "systemc/ext/dt/bit/messages.hh"
5212854Sgabeblack@google.com#include "systemc/ext/dt/bit/sc_logic.hh"
5312854Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
5412854Sgabeblack@google.com
5512854Sgabeblack@google.comnamespace sc_dt
5612854Sgabeblack@google.com{
5712854Sgabeblack@google.com
5812854Sgabeblack@google.com// ----------------------------------------------------------------------------
5912854Sgabeblack@google.com//  CLASS : sc_logic
6012854Sgabeblack@google.com//
6112854Sgabeblack@google.com//  Four-valued logic type.
6212854Sgabeblack@google.com// ----------------------------------------------------------------------------
6312854Sgabeblack@google.com
6412854Sgabeblack@google.com// support methods
6512854Sgabeblack@google.comvoid
6612854Sgabeblack@google.comsc_logic::invalid_value(sc_logic_value_t v)
6712854Sgabeblack@google.com{
6812854Sgabeblack@google.com    invalid_value((int)v);
6912854Sgabeblack@google.com}
7012854Sgabeblack@google.com
7112854Sgabeblack@google.comvoid
7212854Sgabeblack@google.comsc_logic::invalid_value(char c)
7312854Sgabeblack@google.com{
7412854Sgabeblack@google.com    std::stringstream msg;
7512854Sgabeblack@google.com    msg << "sc_logic('" << c << "')";
7613325Sgabeblack@google.com    SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str());
7712854Sgabeblack@google.com}
7812854Sgabeblack@google.com
7912854Sgabeblack@google.comvoid
8012854Sgabeblack@google.comsc_logic::invalid_value(int i)
8112854Sgabeblack@google.com{
8212854Sgabeblack@google.com    std::stringstream msg;
8312854Sgabeblack@google.com    msg << "sc_logic(" << i << ")";
8413325Sgabeblack@google.com    SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str());
8512854Sgabeblack@google.com}
8612854Sgabeblack@google.com
8712854Sgabeblack@google.com
8812854Sgabeblack@google.comvoid
8912854Sgabeblack@google.comsc_logic::invalid_01() const
9012854Sgabeblack@google.com{
9113325Sgabeblack@google.com    if ((int)m_val == Log_Z)
9213325Sgabeblack@google.com        SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_Z_TO_BOOL_, 0);
9313325Sgabeblack@google.com    else
9413325Sgabeblack@google.com        SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_X_TO_BOOL_, 0);
9512854Sgabeblack@google.com}
9612854Sgabeblack@google.com
9712854Sgabeblack@google.com
9812854Sgabeblack@google.com// conversion tables
9912854Sgabeblack@google.comconst sc_logic_value_t sc_logic::char_to_logic[128] = {
10012854Sgabeblack@google.com    Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
10112854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10212854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10312854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10412854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10512854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10612854Sgabeblack@google.com    Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10712854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10812854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
10912854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
11012854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
11112854Sgabeblack@google.com    Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
11212854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
11312854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
11412854Sgabeblack@google.com    Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
11512854Sgabeblack@google.com    Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X
11612854Sgabeblack@google.com};
11712854Sgabeblack@google.com
11812854Sgabeblack@google.comconst char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' };
11912854Sgabeblack@google.com
12012854Sgabeblack@google.comconst sc_logic_value_t sc_logic::and_table[4][4] = {
12112854Sgabeblack@google.com    { Log_0, Log_0, Log_0, Log_0 },
12212854Sgabeblack@google.com    { Log_0, Log_1, Log_X, Log_X },
12312854Sgabeblack@google.com    { Log_0, Log_X, Log_X, Log_X },
12412854Sgabeblack@google.com    { Log_0, Log_X, Log_X, Log_X }
12512854Sgabeblack@google.com};
12612854Sgabeblack@google.com
12712854Sgabeblack@google.comconst sc_logic_value_t sc_logic::or_table[4][4] = {
12812854Sgabeblack@google.com    { Log_0, Log_1, Log_X, Log_X },
12912854Sgabeblack@google.com    { Log_1, Log_1, Log_1, Log_1 },
13012854Sgabeblack@google.com    { Log_X, Log_1, Log_X, Log_X },
13112854Sgabeblack@google.com    { Log_X, Log_1, Log_X, Log_X }
13212854Sgabeblack@google.com};
13312854Sgabeblack@google.com
13412854Sgabeblack@google.comconst sc_logic_value_t sc_logic::xor_table[4][4] = {
13512854Sgabeblack@google.com    { Log_0, Log_1, Log_X, Log_X },
13612854Sgabeblack@google.com    { Log_1, Log_0, Log_X, Log_X },
13712854Sgabeblack@google.com    { Log_X, Log_X, Log_X, Log_X },
13812854Sgabeblack@google.com    { Log_X, Log_X, Log_X, Log_X }
13912854Sgabeblack@google.com};
14012854Sgabeblack@google.com
14112854Sgabeblack@google.comconst sc_logic_value_t sc_logic::not_table[4] = {
14212854Sgabeblack@google.com    Log_1, Log_0, Log_X, Log_X
14312854Sgabeblack@google.com};
14412854Sgabeblack@google.com
14512854Sgabeblack@google.com// other methods
14612854Sgabeblack@google.comvoid
14712854Sgabeblack@google.comsc_logic::scan(::std::istream &is)
14812854Sgabeblack@google.com{
14912854Sgabeblack@google.com    char c;
15012854Sgabeblack@google.com    is >> c;
15112854Sgabeblack@google.com    *this = c;
15212854Sgabeblack@google.com}
15312854Sgabeblack@google.com
15412854Sgabeblack@google.com// #ifdef SC_DT_DEPRECATED
15512854Sgabeblack@google.comconst sc_logic sc_logic_0(Log_0);
15612854Sgabeblack@google.comconst sc_logic sc_logic_1(Log_1);
15712854Sgabeblack@google.comconst sc_logic sc_logic_Z(Log_Z);
15812854Sgabeblack@google.comconst sc_logic sc_logic_X(Log_X);
15912854Sgabeblack@google.com// #endif
16012854Sgabeblack@google.com
16112854Sgabeblack@google.comconst sc_logic SC_LOGIC_0(Log_0);
16212854Sgabeblack@google.comconst sc_logic SC_LOGIC_1(Log_1);
16312854Sgabeblack@google.comconst sc_logic SC_LOGIC_Z(Log_Z);
16412854Sgabeblack@google.comconst sc_logic SC_LOGIC_X(Log_X);
16512854Sgabeblack@google.com
16612854Sgabeblack@google.com} // namespace sc_dt
167