scc 2025.09
SystemC components library
sc_logic_7.cpp
1/*******************************************************************************
2 * Copyright 2017, 2018 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#include "sc_logic_7.h"
18#include "sysc/datatypes/bit/sc_bit_ids.h"
19#include <array>
20
21namespace scc {
22namespace dt {
23
24void sc_logic_7::invalid_value(sc_logic_7_value_t v) {
25 std::array<char, BUFSIZ> msg{};
26 std::sprintf(msg.data(), "sc_logic_7( %d )", v);
27 SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.data());
28}
29
30void sc_logic_7::invalid_value(char c) {
31 std::array<char, BUFSIZ> msg{};
32 std::sprintf(msg.data(), "sc_logic_7( '%c' )", c);
33 SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.data());
34}
35
36void sc_logic_7::invalid_value(int i) {
37 std::array<char, BUFSIZ> msg{};
38 std::sprintf(msg.data(), "sc_logic_7( %d )", i);
39 SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.data());
40}
41
42void sc_logic_7::invalid_01() const {
43 if((int)m_val == Log_Z) {
44 SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_Z_TO_BOOL_, "");
45 } else {
46 SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_X_TO_BOOL_, "");
47 }
48}
49
50// conversion tables
51
52std::array<const sc_logic_7_value_t, 128> sc_logic_7::char_to_logic = {
53 {Log_0, Log_1, Log_L, Log_H, Log_Z, Log_X, Log_U, Log_X, // 0
54 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, // 1
55 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, // 2
56 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, // 3
57 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, // 4
58 Log_H, Log_X, Log_X, Log_X, Log_L, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_U, Log_X, Log_X, // 5
59 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, // 6
60 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, // 9
61 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X}};
62
63std::array<const char, 7> sc_logic_7::logic_to_char = {{'0', '1', 'L', 'H', 'Z', 'X', 'U'}};
64
65std::array<std::array<const sc_logic_7_value_t, 7>, 7> sc_logic_7::and_table = {{// 0 1 L H Z X U
66 /*0*/ {Log_0, Log_0, Log_0, Log_0, Log_0, Log_0, Log_0},
67 /*1*/ {Log_0, Log_1, Log_L, Log_1, Log_X, Log_X, Log_X},
68 /*L*/ {Log_0, Log_L, Log_L, Log_L, Log_L, Log_L, Log_L},
69 /*H*/ {Log_0, Log_1, Log_L, Log_H, Log_X, Log_X, Log_X},
70 /*Z*/ {Log_0, Log_X, Log_L, Log_X, Log_X, Log_X, Log_X},
71 /*X*/ {Log_0, Log_X, Log_L, Log_X, Log_X, Log_X, Log_X},
72 /*U*/ {Log_0, Log_X, Log_L, Log_X, Log_X, Log_X, Log_X}}};
73
74std::array<std::array<const sc_logic_7_value_t, 7>, 7> sc_logic_7::or_table = {{// 0 1 L H Z X U
75 /*0*/ {Log_0, Log_1, Log_L, Log_H, Log_Z, Log_X, Log_U},
76 /*1*/ {Log_1, Log_1, Log_1, Log_1, Log_1, Log_1, Log_1},
77 /*L*/ {Log_L, Log_1, Log_L, Log_H, Log_Z, Log_X, Log_U},
78 /*H*/ {Log_H, Log_1, Log_H, Log_H, Log_H, Log_H, Log_H},
79 /*Z*/ {Log_Z, Log_1, Log_Z, Log_H, Log_X, Log_X, Log_X},
80 /*X*/ {Log_X, Log_1, Log_X, Log_H, Log_X, Log_X, Log_X},
81 /*U*/ {Log_U, Log_1, Log_U, Log_H, Log_X, Log_X, Log_X}}};
82
83std::array<std::array<const sc_logic_7_value_t, 7>, 7> sc_logic_7::xor_table = {{// 0 1 L H Z X U
84 /*0*/ {Log_0, Log_1, Log_0, Log_1, Log_X, Log_X, Log_X},
85 /*1*/ {Log_1, Log_0, Log_1, Log_0, Log_X, Log_X, Log_X},
86 /*L*/ {Log_0, Log_1, Log_H, Log_L, Log_X, Log_X, Log_X},
87 /*H*/ {Log_1, Log_0, Log_L, Log_H, Log_X, Log_X, Log_X},
88 /*Z*/ {Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X},
89 /*X*/ {Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X},
90 /*U*/ {Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X}}};
91
92std::array<const sc_logic_7_value_t, 7> sc_logic_7::not_table = {{Log_1, Log_0, Log_H, Log_L, Log_X, Log_X, Log_X}};
93
94// other methods
95
96void sc_logic_7::scan(::std::istream& is) {
97 char c;
98 is >> c;
99 *this = c;
100}
101
102const sc_logic_7 SC_LOGIC7_0(Log_0);
103const sc_logic_7 SC_LOGIC7_1(Log_1);
104const sc_logic_7 SC_LOGIC7_Z(Log_Z);
105const sc_logic_7 SC_LOGIC7_X(Log_X);
106
107} // namespace dt
108} // namespace scc
SCC TLM utilities.