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 | public: |
---|
35 | // constructors & destructor |
---|
36 | sc_bit () { val = false; } |
---|
37 | explicit sc_bit (bool a) { val = a; } |
---|
38 | explicit sc_bit (int a) { val = a > 0; } |
---|
39 | explicit sc_bit (char a) { val = (a == '1')?true:false; } |
---|
40 | explicit sc_bit (const sc_logic & a) { val = a.to_bool(); } |
---|
41 | ~sc_bit () { }; |
---|
42 | // copy constructor |
---|
43 | sc_bit (const sc_bit & a) { val = a; } |
---|
44 | // assignment operators |
---|
45 | sc_bit & operator = (const sc_bit & b) { val = b.to_bool(); return *this; } |
---|
46 | sc_bit & operator = (int b) { val = b > 0; return *this; } |
---|
47 | sc_bit & operator = (bool b) { val = b; return *this; } |
---|
48 | sc_bit & operator = (char b) { val = (b == '1')?true:false; return *this; } |
---|
49 | sc_bit & operator = (const sc_logic & b) { val = b.to_bool(); return *this; } |
---|
50 | |
---|
51 | // bitwise assignment operators |
---|
52 | sc_bit & operator &= (const sc_bit & b) { val &= b.to_bool(); return *this; } |
---|
53 | sc_bit & operator &= (int b) { val &= b > 0; return *this; } |
---|
54 | sc_bit & operator &= (bool b) { val &= b; return *this; } |
---|
55 | sc_bit & operator &= (char b) { val &= (b == '1')?true:false; return *this; } |
---|
56 | sc_bit & operator |= (const sc_bit & b) { val |= b.val; return *this; } |
---|
57 | sc_bit & operator |= (int b) { val |= b > 0; return *this; } |
---|
58 | sc_bit & operator |= (bool b) { val |= b; return *this; } |
---|
59 | sc_bit & operator |= (char b) { val |= (b == '1')?true:false; return *this; } |
---|
60 | sc_bit & operator ^= (const sc_bit & b) { val ^= b.val; return *this; } |
---|
61 | sc_bit & operator ^= (int b) { val ^= b > 0; return *this; } |
---|
62 | sc_bit & operator ^= (bool b) { val ^= b; return *this; } |
---|
63 | sc_bit & operator ^= (char b) { val ^= (b == '1')?true:false; return *this; } |
---|
64 | |
---|
65 | // implicit conversion to bool |
---|
66 | operator bool () const { return val; } |
---|
67 | bool operator ! () const { return !val; } |
---|
68 | |
---|
69 | // explicit conversion to character string |
---|
70 | const sc_string to_string ( sc_numrep numrep = SC_DEC ) const |
---|
71 | { return sc_string ((val)?"1":"0"); } |
---|
72 | const sc_string to_dec() const { return to_string (SC_DEC); } |
---|
73 | const sc_string to_bin() const { return to_string (SC_BIN); } |
---|
74 | const sc_string to_oct() const { return to_string (SC_OCT); } |
---|
75 | const sc_string to_hex() const { return to_string (SC_HEX); } |
---|
76 | |
---|
77 | // others explicit conversions |
---|
78 | bool to_bool () const { return val; } |
---|
79 | char to_char () const { return (val)?'1':'0'; } |
---|
80 | |
---|
81 | // relational operators and functions |
---|
82 | friend bool operator == (const sc_bit & a, const sc_bit & b) { return a == |
---|
83 | b; } |
---|
84 | friend bool operator == (const sc_bit & a, int b); |
---|
85 | friend bool operator == (const sc_bit & a, bool b); |
---|
86 | friend bool operator == (const sc_bit & a, char b); |
---|
87 | friend bool operator == (int a, const sc_bit & b); |
---|
88 | |
---|
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 | // other functions |
---|
187 | void print (std::ostream & os = std::cout) const; |
---|
188 | void scan (std::istream & = std::cin); |
---|
189 | */ |
---|
190 | }; |
---|
191 | |
---|
192 | } /* end of sc_dt namespace */ |
---|
193 | |
---|
194 | #endif /* __SC_BIT_H__ */ |
---|