17 #ifndef INCL_SYSC_CORE_SC_LOGIC_7_H_
18 #define INCL_SYSC_CORE_SC_LOGIC_7_H_
22 #include "sysc/datatypes/bit/sc_bit.h"
23 #include "sysc/kernel/sc_macros.h"
24 #include "sysc/utils/sc_mempool.h"
43 enum 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;
109 : m_val(to_value(v)) {}
112 : m_val(to_value(a)) {}
115 : m_val(to_value(a)) {}
118 : m_val(to_value(a)) {}
121 : m_val(to_value(a.to_bool())) {}
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&)
145 m_val = and_table[m_val][b.m_val];
150 m_val = or_table[m_val][b.m_val];
155 m_val = xor_table[m_val][b.m_val];
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;
238 inline const sc_logic_7
operator|(
const sc_logic_7& a,
const sc_logic_7& b) {
return sc_logic_7(sc_logic_7::or_table[a.m_val][b.m_val]); }
240 inline const sc_logic_7 operator^(
const sc_logic_7& a,
const sc_logic_7& b) {
return sc_logic_7(sc_logic_7::xor_table[a.m_val][b.m_val]); }
242 #define DEFN_BIN_OP_T(ret, op, tp) \
243 inline ret operator op(const sc_logic_7& a, tp b) { return (a op sc_logic_7(b)); } \
244 inline ret operator op(tp a, const sc_logic_7& b) { return (sc_logic_7(a) op b); }
246 #define DEFN_BIN_OP(ret, op) \
247 DEFN_BIN_OP_T(ret, op, sc_logic_7_value_t) \
248 DEFN_BIN_OP_T(ret, op, bool) \
249 DEFN_BIN_OP_T(ret, op, char) \
250 DEFN_BIN_OP_T(ret, op, int)
252 DEFN_BIN_OP(
const sc_logic_7, &)
253 DEFN_BIN_OP(const sc_logic_7, |)
254 DEFN_BIN_OP(const sc_logic_7, ^)
258 inline
bool operator==(const sc_logic_7& a, const sc_logic_7& b) {
return ((
int)a.m_val == b.m_val); }
260 inline bool operator!=(
const sc_logic_7& a,
const sc_logic_7& b) {
return ((
int)a.m_val != b.m_val); }
262 DEFN_BIN_OP(
bool, ==)
263 DEFN_BIN_OP(
bool, !=)
270 inline ::std::ostream&
operator<<(::std::ostream& os,
const sc_logic_7& a) {
275 inline ::std::istream&
operator>>(::std::istream& is, sc_logic_7& a) {
280 extern const sc_logic_7 SC_LOGIC7_0;
281 extern const sc_logic_7 SC_LOGIC7_1;
282 extern const sc_logic_7 SC_LOGIC7_Z;
283 extern const sc_logic_7 SC_LOGIC7_X;
std::istream & operator>>(std::istream &is, log &val)
read a log level from input stream e.g. used by boost::lexical_cast
trace_types operator&(trace_types lhs, trace_types rhs)
operator overload to allow boolean and operations on trace_types
std::ostream & operator<<(std::ostream &os, log const &val)
output the textual representation of the log level
trace_types operator|(trace_types lhs, trace_types rhs)
operator overload to allow boolean or operations on trace_types