| 1 | /*------------------------------------------------------------\ | 
|---|
| 2 | |                                                             | | 
|---|
| 3 | | Tool    :                  systemcass                       | | 
|---|
| 4 | |                                                             | | 
|---|
| 5 | | File    :                 sc_bit.h                          | | 
|---|
| 6 | |                                                             | | 
|---|
| 7 | | Author  :                 Buchmann Richard                  | | 
|---|
| 8 | |                                                             | | 
|---|
| 9 | | Date    :                   14_04_2005                      | | 
|---|
| 10 | |                                                             | | 
|---|
| 11 | \------------------------------------------------------------*/ | 
|---|
| 12 | #ifndef __SC_BIT_H__ | 
|---|
| 13 | #define __SC_BIT_H__ | 
|---|
| 14 |  | 
|---|
| 15 | #include "sc_nbdefs.h" | 
|---|
| 16 | #include "sc_fwd.h" | 
|---|
| 17 | #include "sc_logic.h" | 
|---|
| 18 | #include "sc_string.h" | 
|---|
| 19 | #include "sc_numrep.h" | 
|---|
| 20 |  | 
|---|
| 21 | // ---------------------------------------------------------------------------- | 
|---|
| 22 | //  CLASS : sc_bit | 
|---|
| 23 | // | 
|---|
| 24 | // ---------------------------------------------------------------------------- | 
|---|
| 25 |  | 
|---|
| 26 | namespace sc_dt { | 
|---|
| 27 |  | 
|---|
| 28 | class sc_bit { | 
|---|
| 29 |  | 
|---|
| 30 | ///////////////////////// | 
|---|
| 31 | ///// SYSTEMCASS SPECIFIC | 
|---|
| 32 | bool val; | 
|---|
| 33 | ///////////////////////// | 
|---|
| 34 |  | 
|---|
| 35 | public: | 
|---|
| 36 | // constructors  & destructor | 
|---|
| 37 | sc_bit()                            { val = false; } | 
|---|
| 38 | explicit sc_bit(bool a)             { val = a; } | 
|---|
| 39 | explicit sc_bit(int a)              { val = a > 0; } | 
|---|
| 40 | explicit sc_bit(char a)             { val = (a == '1') ? true : false; } | 
|---|
| 41 | explicit sc_bit(const sc_logic & a) { val = a.to_bool(); } | 
|---|
| 42 | ~sc_bit()                           {} | 
|---|
| 43 | // copy constructor | 
|---|
| 44 | sc_bit(const sc_bit & a)            { val = a; } | 
|---|
| 45 | // assignment operators | 
|---|
| 46 | sc_bit & operator = (const sc_bit & b)   { val = b.to_bool(); return *this; } | 
|---|
| 47 | sc_bit & operator = (int b)              { val = b > 0; return *this; } | 
|---|
| 48 | sc_bit & operator = (bool b)             { val = b; return *this; } | 
|---|
| 49 | sc_bit & operator = (char b)             { val = (b == '1') ? true : false; return *this; } | 
|---|
| 50 | sc_bit & operator = (const sc_logic & b) { val = b.to_bool(); return *this; } | 
|---|
| 51 |  | 
|---|
| 52 | // bitwise assignment operators | 
|---|
| 53 | sc_bit & operator &= (const sc_bit & b)  { val &= b.to_bool(); return *this; } | 
|---|
| 54 | sc_bit & operator &= (int b)             { val &= b > 0; return *this; } | 
|---|
| 55 | sc_bit & operator &= (bool b)            { val &= b; return *this; } | 
|---|
| 56 | sc_bit & operator &= (char b)            { val &= (b == '1') ? true : false; return *this; } | 
|---|
| 57 | sc_bit & operator |= (const sc_bit & b)  { val |= b.val; return *this; } | 
|---|
| 58 | sc_bit & operator |= (int b)             { val |= b > 0; return *this; } | 
|---|
| 59 | sc_bit & operator |= (bool b)            { val |= b; return *this; } | 
|---|
| 60 | sc_bit & operator |= (char b)            { val |= (b == '1') ? true : false; return *this; } | 
|---|
| 61 | sc_bit & operator ^= (const sc_bit & b)  { val ^= b.val; return *this; } | 
|---|
| 62 | sc_bit & operator ^= (int b)             { val ^= b > 0; return *this; } | 
|---|
| 63 | sc_bit & operator ^= (bool b)            { val ^= b; return *this; } | 
|---|
| 64 | sc_bit & operator ^= (char b)            { val ^= (b == '1') ? true : false; return *this; } | 
|---|
| 65 |  | 
|---|
| 66 | // implicit conversion to bool | 
|---|
| 67 | operator bool () const   { return val;  } | 
|---|
| 68 | bool operator ! () const { return !val; } | 
|---|
| 69 |  | 
|---|
| 70 | // explicit conversion to character string | 
|---|
| 71 | const sc_string to_string(sc_numrep numrep = SC_DEC ) const  { | 
|---|
| 72 | return sc_string ((val) ? "1" : "0"); | 
|---|
| 73 | } | 
|---|
| 74 | const sc_string to_dec() const { return to_string (SC_DEC); } | 
|---|
| 75 | const sc_string to_bin() const { return to_string (SC_BIN); } | 
|---|
| 76 | const sc_string to_oct() const { return to_string (SC_OCT); } | 
|---|
| 77 | const sc_string to_hex() const { return to_string (SC_HEX); } | 
|---|
| 78 |  | 
|---|
| 79 | // others explicit conversions | 
|---|
| 80 | bool to_bool() const { return val;  } | 
|---|
| 81 | char to_char() const { return (val) ? '1' : '0'; } | 
|---|
| 82 |  | 
|---|
| 83 | // relational operators and functions | 
|---|
| 84 | friend bool operator == (const sc_bit & a, const sc_bit & b) { return a == b; } | 
|---|
| 85 | friend bool operator == (const sc_bit & a, int b); | 
|---|
| 86 | friend bool operator == (const sc_bit & a, bool b); | 
|---|
| 87 | friend bool operator == (const sc_bit & a, char b); | 
|---|
| 88 | friend bool operator == (int a, const sc_bit & b); | 
|---|
| 89 | friend bool operator == (bool a, const sc_bit & b); | 
|---|
| 90 | friend bool operator == (char a, const sc_bit & b); | 
|---|
| 91 | friend bool equal (const sc_bit & a, const sc_bit & b); | 
|---|
| 92 | friend bool equal (const sc_bit & a, int b); | 
|---|
| 93 | friend bool equal (const sc_bit & a, bool b); | 
|---|
| 94 | friend bool equal (const sc_bit & a, char b); | 
|---|
| 95 | friend bool equal (int a, const sc_bit & b); | 
|---|
| 96 | friend bool equal (bool a, const sc_bit & b); | 
|---|
| 97 | friend bool equal (char a, const sc_bit & b); | 
|---|
| 98 | friend bool operator != (const sc_bit & a, const sc_bit & b); | 
|---|
| 99 | friend bool operator != (const sc_bit & a, int b); | 
|---|
| 100 | friend bool operator != (const sc_bit & a, bool b); | 
|---|
| 101 | friend bool operator != (const sc_bit & a, char b); | 
|---|
| 102 | friend bool operator != (int a, const sc_bit & b); | 
|---|
| 103 | friend bool operator != (bool a, const sc_bit & b); | 
|---|
| 104 | friend bool operator != (char a, const sc_bit & b); | 
|---|
| 105 | friend bool not_equal (const sc_bit & a, const sc_bit & b); | 
|---|
| 106 | friend bool not_equal (const sc_bit & a, int b); | 
|---|
| 107 | friend bool not_equal (const sc_bit & a, bool b); | 
|---|
| 108 | friend bool not_equal (const sc_bit & a, char b); | 
|---|
| 109 | friend bool not_equal (int a, const sc_bit & b); | 
|---|
| 110 | friend bool not_equal (bool a, const sc_bit & b); | 
|---|
| 111 | friend bool not_equal (char a, const sc_bit & b); | 
|---|
| 112 | // bitwise complement | 
|---|
| 113 | friend const sc_bit operator ~ (const sc_bit & a); | 
|---|
| 114 | sc_bit & b_not(); | 
|---|
| 115 | friend void b_not (sc_bit & r, const sc_bit & a); | 
|---|
| 116 | friend const sc_bit b_not (const sc_bit & a); | 
|---|
| 117 | // bitwise or | 
|---|
| 118 | friend const sc_bit operator | (const sc_bit & a, const sc_bit & b); | 
|---|
| 119 | friend const sc_bit operator | (const sc_bit & a, int b); | 
|---|
| 120 | friend const sc_bit operator | (const sc_bit & a, bool b); | 
|---|
| 121 | friend const sc_bit operator | (const sc_bit & a, char b); | 
|---|
| 122 | friend const sc_bit operator | (int a, const sc_bit & b); | 
|---|
| 123 | friend const sc_bit operator | (bool a, const sc_bit & b); | 
|---|
| 124 | friend const sc_bit operator | (char a, const sc_bit & b); | 
|---|
| 125 | friend const sc_bit b_or (const sc_bit & a, const sc_bit & b); | 
|---|
| 126 | friend const sc_bit b_or (const sc_bit & a, int b); | 
|---|
| 127 | friend const sc_bit b_or (const sc_bit & a, bool b); | 
|---|
| 128 | friend const sc_bit b_or (const sc_bit & a, char b); | 
|---|
| 129 | friend const sc_bit b_or (int a, const sc_bit & b); | 
|---|
| 130 | friend const sc_bit b_or (bool a, const sc_bit & b); | 
|---|
| 131 |  | 
|---|
| 132 | friend const sc_bit b_or (char a, const sc_bit & b); | 
|---|
| 133 | friend void b_or (sc_bit & r, const sc_bit & a, const sc_bit & b); | 
|---|
| 134 | friend void b_or (sc_bit & r, const sc_bit & a, int b); | 
|---|
| 135 | friend void b_or (sc_bit & r, const sc_bit & a, bool b); | 
|---|
| 136 | friend void b_or (sc_bit & r, const sc_bit & a, char b); | 
|---|
| 137 | friend void b_or (sc_bit & r, int a, const sc_bit & b); | 
|---|
| 138 | friend void b_or (sc_bit & r, bool a, const sc_bit & b); | 
|---|
| 139 | friend void b_or (sc_bit & r, char a, const sc_bit & b); | 
|---|
| 140 | // bitwise and | 
|---|
| 141 | friend const sc_bit operator & (const sc_bit & a, const sc_bit & b); | 
|---|
| 142 | friend const sc_bit operator & (const sc_bit & a, int b); | 
|---|
| 143 | friend const sc_bit operator & (const sc_bit & a, bool b); | 
|---|
| 144 | friend const sc_bit operator & (const sc_bit & a, char b); | 
|---|
| 145 | friend const sc_bit operator & (int a, const sc_bit & b); | 
|---|
| 146 | friend const sc_bit operator & (bool a, const sc_bit & b); | 
|---|
| 147 | friend const sc_bit operator & (char a, const sc_bit & b); | 
|---|
| 148 | friend const sc_bit b_and (const sc_bit & a, const sc_bit & b); | 
|---|
| 149 | friend const sc_bit b_and (const sc_bit & a, int b); | 
|---|
| 150 | friend const sc_bit b_and (const sc_bit & a, bool b); | 
|---|
| 151 | friend const sc_bit b_and (const sc_bit & a, char b); | 
|---|
| 152 | friend const sc_bit b_and (int a, const sc_bit & b); | 
|---|
| 153 | friend const sc_bit b_and (bool a, const sc_bit & b); | 
|---|
| 154 | friend const sc_bit b_and (char a, const sc_bit & b); | 
|---|
| 155 | friend void b_and (sc_bit & r, const sc_bit & a, const sc_bit & b); | 
|---|
| 156 | friend void b_and (sc_bit & r, const sc_bit & a, int b); | 
|---|
| 157 | friend void b_and (sc_bit & r, const sc_bit & a, bool b); | 
|---|
| 158 | friend void b_and (sc_bit & r, const sc_bit & a, char b); | 
|---|
| 159 | friend void b_and (sc_bit & r, int a, const sc_bit & b); | 
|---|
| 160 | friend void b_and (sc_bit & r, bool a, const sc_bit & b); | 
|---|
| 161 | friend void b_and (sc_bit & r, char a, const sc_bit & b); | 
|---|
| 162 | // bitwise exor | 
|---|
| 163 | friend const sc_bit operator ^ (const sc_bit & a, const sc_bit & b); | 
|---|
| 164 | friend const sc_bit operator ^ (const sc_bit & a, int b); | 
|---|
| 165 | friend const sc_bit operator ^ (const sc_bit & a, bool b); | 
|---|
| 166 | friend const sc_bit operator ^ (const sc_bit & a, char b); | 
|---|
| 167 | friend const sc_bit operator ^ (int a, const sc_bit & b); | 
|---|
| 168 |  | 
|---|
| 169 | friend const sc_bit operator ^ (bool a, const sc_bit & b); | 
|---|
| 170 | friend const sc_bit operator ^ (char a, const sc_bit & b); | 
|---|
| 171 | friend const sc_bit b_xor (const sc_bit & a, const sc_bit & b); | 
|---|
| 172 | friend const sc_bit b_xor (const sc_bit & a, int b); | 
|---|
| 173 | friend const sc_bit b_xor (const sc_bit & a, bool b); | 
|---|
| 174 | friend const sc_bit b_xor (const sc_bit & a, char b); | 
|---|
| 175 | friend const sc_bit b_xor (int a, const sc_bit & b); | 
|---|
| 176 | friend const sc_bit b_xor (bool a, const sc_bit & b); | 
|---|
| 177 | friend const sc_bit b_xor (char a, const sc_bit & b); | 
|---|
| 178 | friend void b_xor (sc_bit & r, const sc_bit & a, const sc_bit & b); | 
|---|
| 179 | friend void b_xor (sc_bit & r, const sc_bit & a, int b); | 
|---|
| 180 | friend void b_xor (sc_bit & r, const sc_bit & a, bool b); | 
|---|
| 181 | friend void b_xor (sc_bit & r, const sc_bit & a, char b); | 
|---|
| 182 | friend void b_xor (sc_bit & r, int a, const sc_bit & b); | 
|---|
| 183 | friend void b_xor (sc_bit & r, bool a, const sc_bit & b); | 
|---|
| 184 | friend void b_xor (sc_bit & r, char a, const sc_bit & b); | 
|---|
| 185 |  | 
|---|
| 186 | }; | 
|---|
| 187 |  | 
|---|
| 188 | } /* end of sc_dt namespace */ | 
|---|
| 189 |  | 
|---|
| 190 | #endif /* __SC_BIT_H__ */ | 
|---|
| 191 |  | 
|---|
| 192 | /* | 
|---|
| 193 | # Local Variables: | 
|---|
| 194 | # tab-width: 4; | 
|---|
| 195 | # c-basic-offset: 4; | 
|---|
| 196 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); | 
|---|
| 197 | # indent-tabs-mode: nil; | 
|---|
| 198 | # End: | 
|---|
| 199 | # | 
|---|
| 200 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
| 201 | */ | 
|---|
| 202 |  | 
|---|