43enum sc_logic_7_value_t { Log_0 = 0, Log_1, Log_L, Log_H, Log_Z, Log_X, Log_U };
55 static void invalid_value(sc_logic_7_value_t);
56 static void invalid_value(
char);
57 static void invalid_value(
int);
59 static sc_logic_7_value_t to_value(sc_logic_7_value_t v) {
60 if(v < Log_0 || v > Log_X) {
66 static sc_logic_7_value_t to_value(
bool b) {
return (b ? Log_1 : Log_0); }
68 static sc_logic_7_value_t to_value(
char c) {
70 unsigned int index = (int)c;
75 v = char_to_logic[index];
76 if(v < Log_0 || v > Log_X) {
83 static sc_logic_7_value_t to_value(
int i) {
87 return sc_logic_7_value_t(i);
90 void invalid_01()
const;
95 static std::array<const sc_logic_7_value_t, 128> char_to_logic;
96 static std::array<const char, 7> logic_to_char;
97 static std::array<std::array<const sc_logic_7_value_t, 7>, 7> and_table;
98 static std::array<std::array<const sc_logic_7_value_t, 7>, 7> or_table;
99 static std::array<std::array<const sc_logic_7_value_t, 7>, 7> xor_table;
100 static std::array<const sc_logic_7_value_t, 7> not_table;
104 sc_logic_7() =
default;
106 sc_logic_7(
const sc_logic_7& a) =
default;
108 sc_logic_7(sc_logic_7_value_t v)
109 : m_val(to_value(v)) {}
111 explicit sc_logic_7(
bool a)
112 : m_val(to_value(a)) {}
114 explicit sc_logic_7(
char a)
115 : m_val(to_value(a)) {}
117 explicit sc_logic_7(
int a)
118 : m_val(to_value(a)) {}
120 explicit sc_logic_7(const ::sc_dt::sc_bit& a)
121 : m_val(to_value(a.to_bool())) {}
125 ~sc_logic_7() =
default;
129#define DEFN_ASN_OP_T(op, tp) \
130 sc_logic_7& operator op(tp v) { \
131 *this op sc_logic_7(v); \
135#define DEFN_ASN_OP(op) \
136 DEFN_ASN_OP_T(op, sc_logic_7_value_t) \
137 DEFN_ASN_OP_T(op, bool) \
138 DEFN_ASN_OP_T(op, char) \
139 DEFN_ASN_OP_T(op, int) \
140 DEFN_ASN_OP_T(op, const ::sc_dt::sc_bit&)
142 sc_logic_7& operator=(
const sc_logic_7& a) =
default;
144 sc_logic_7& operator&=(
const sc_logic_7& b) {
145 m_val = and_table[m_val][b.m_val];
149 sc_logic_7& operator|=(
const sc_logic_7& b) {
150 m_val = or_table[m_val][b.m_val];
154 sc_logic_7& operator^=(
const sc_logic_7& b) {
155 m_val = xor_table[m_val][b.m_val];
169 friend const sc_logic_7 operator&(
const sc_logic_7&,
const sc_logic_7&);
170 friend const sc_logic_7 operator|(
const sc_logic_7&,
const sc_logic_7&);
171 friend const sc_logic_7 operator^(
const sc_logic_7&,
const sc_logic_7&);
175 friend bool operator==(
const sc_logic_7&,
const sc_logic_7&);
176 friend bool operator!=(
const sc_logic_7&,
const sc_logic_7&);
180 const sc_logic_7 operator~()
const {
return sc_logic_7(not_table[m_val]); }
182 sc_logic_7& b_not() {
183 m_val = not_table[m_val];
189 sc_logic_7_value_t value()
const {
return m_val; }
191 bool is_01()
const {
return ((
int)m_val == Log_0 || (
int)m_val == Log_1); }
193 bool to_bool()
const {
197 return ((
int)m_val != Log_0);
200 char to_char()
const {
return logic_to_char[m_val]; }
204 void print(::std::ostream& os = ::std::cout)
const { os << to_char(); }
206 void scan(::std::istream& is = ::std::cin);
210 static void*
operator new(std::size_t,
void* p)
215 static void*
operator new(std::size_t sz) {
return sc_core::sc_mempool::allocate(sz); }
217 static void operator delete(
void* p, std::size_t sz) { sc_core::sc_mempool::release(p, sz); }
219 static void*
operator new[](std::size_t sz) {
return sc_core::sc_mempool::allocate(sz); }
221 static void operator delete[](
void* p, std::size_t sz) { sc_core::sc_mempool::release(p, sz); }
224 sc_logic_7_value_t m_val = Log_U;
228 explicit sc_logic_7(
const char*);
229 sc_logic_7& operator=(
const char*);