[1] | 1 | /*------------------------------------------------------------\ |
---|
| 2 | | | |
---|
| 3 | | Tool : systemcass | |
---|
| 4 | | | |
---|
| 5 | | File : sc_lv.h | |
---|
| 6 | | | |
---|
| 7 | | Author : Buchmann Richard | |
---|
| 8 | | | |
---|
| 9 | | Date : 19_04_2005 | |
---|
| 10 | | | |
---|
| 11 | \------------------------------------------------------------*/ |
---|
[52] | 12 | |
---|
[1] | 13 | #ifndef __SC_LV_H__ |
---|
| 14 | #define __SC_LV_H__ |
---|
| 15 | |
---|
| 16 | // ---------------------------------------------------------------------------- |
---|
| 17 | // CLASS : sc_lv |
---|
| 18 | // |
---|
| 19 | // ---------------------------------------------------------------------------- |
---|
| 20 | |
---|
[59] | 21 | //#include <stdint.h> |
---|
| 22 | |
---|
[27] | 23 | #include "sc_nbdefs.h" |
---|
| 24 | #include "sc_logic.h" |
---|
| 25 | #include "sc_unsigned.h" |
---|
| 26 | #include "sc_signed.h" |
---|
| 27 | #include "sc_uint.h" |
---|
| 28 | #include "sc_int.h" |
---|
[1] | 29 | |
---|
| 30 | |
---|
| 31 | namespace sc_dt { |
---|
| 32 | |
---|
[52] | 33 | template<int W> struct s_lv_type { typedef uint64 lv_type; }; |
---|
| 34 | |
---|
[1] | 35 | #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef smallest_uint lv_type; }// not declared as uint16 because << operator threats like a character |
---|
[52] | 36 | DECLAR_LV_TYPE(1); |
---|
| 37 | DECLAR_LV_TYPE(2); |
---|
| 38 | DECLAR_LV_TYPE(3); |
---|
| 39 | DECLAR_LV_TYPE(4); |
---|
| 40 | DECLAR_LV_TYPE(5); |
---|
| 41 | DECLAR_LV_TYPE(6); |
---|
| 42 | DECLAR_LV_TYPE(7); |
---|
| 43 | DECLAR_LV_TYPE(8); |
---|
[1] | 44 | #undef DECLAR_LV_TYPE |
---|
[52] | 45 | |
---|
[1] | 46 | #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef uint16 lv_type; } |
---|
[52] | 47 | DECLAR_LV_TYPE(9); |
---|
[1] | 48 | DECLAR_LV_TYPE(10); |
---|
| 49 | DECLAR_LV_TYPE(11); |
---|
| 50 | DECLAR_LV_TYPE(12); |
---|
| 51 | DECLAR_LV_TYPE(13); |
---|
| 52 | DECLAR_LV_TYPE(14); |
---|
| 53 | DECLAR_LV_TYPE(15); |
---|
| 54 | DECLAR_LV_TYPE(16); |
---|
| 55 | #undef DECLAR_LV_TYPE |
---|
[52] | 56 | |
---|
[1] | 57 | #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef uint32 lv_type; } |
---|
| 58 | DECLAR_LV_TYPE(17); |
---|
| 59 | DECLAR_LV_TYPE(18); |
---|
| 60 | DECLAR_LV_TYPE(19); |
---|
| 61 | DECLAR_LV_TYPE(20); |
---|
| 62 | DECLAR_LV_TYPE(21); |
---|
| 63 | DECLAR_LV_TYPE(22); |
---|
| 64 | DECLAR_LV_TYPE(23); |
---|
| 65 | DECLAR_LV_TYPE(24); |
---|
| 66 | DECLAR_LV_TYPE(25); |
---|
| 67 | DECLAR_LV_TYPE(26); |
---|
| 68 | DECLAR_LV_TYPE(27); |
---|
| 69 | DECLAR_LV_TYPE(28); |
---|
| 70 | DECLAR_LV_TYPE(29); |
---|
| 71 | DECLAR_LV_TYPE(30); |
---|
| 72 | DECLAR_LV_TYPE(31); |
---|
| 73 | DECLAR_LV_TYPE(32); |
---|
| 74 | #undef DECLAR_LV_TYPE |
---|
| 75 | |
---|
| 76 | |
---|
[52] | 77 | class sc_lv_base { |
---|
| 78 | |
---|
| 79 | public: |
---|
| 80 | // constructors |
---|
| 81 | sc_lv_base() {} // SYSTEMCASS SPECIFIC |
---|
| 82 | sc_lv_base(const char * a); |
---|
| 83 | sc_lv_base(const char * a, int length_); |
---|
[1] | 84 | template < class X > sc_lv_base (const sc_lv_base & a); |
---|
[52] | 85 | virtual ~sc_lv_base() {} |
---|
| 86 | // assignment operators |
---|
[1] | 87 | template < class X > sc_lv_base & operator = (const sc_lv_base & a); |
---|
[52] | 88 | sc_lv_base & operator = (const char * a); |
---|
[1] | 89 | sc_lv_base & operator = (const bool * a); |
---|
| 90 | sc_lv_base & operator = (const sc_logic * a); |
---|
| 91 | sc_lv_base & operator = (const sc_unsigned & a); |
---|
| 92 | sc_lv_base & operator = (const sc_signed & a); |
---|
| 93 | sc_lv_base & operator = (unsigned long a); |
---|
| 94 | sc_lv_base & operator = (long a); |
---|
| 95 | sc_lv_base & operator = (unsigned int a); |
---|
| 96 | sc_lv_base & operator = (int a); |
---|
| 97 | sc_lv_base & operator = (uint64 a); |
---|
| 98 | sc_lv_base & operator = (int64 a); |
---|
| 99 | |
---|
[52] | 100 | // methods |
---|
| 101 | int length() const; |
---|
| 102 | bool is_01() const; |
---|
[1] | 103 | }; |
---|
| 104 | |
---|
| 105 | |
---|
[52] | 106 | template < int W > class sc_lv : public sc_lv_base { |
---|
| 107 | |
---|
| 108 | /***********************/ |
---|
| 109 | /* SYSTEMCASS SPECIFIC */ |
---|
| 110 | /***********************/ |
---|
| 111 | |
---|
| 112 | typedef sc_lv<W> this_type; |
---|
| 113 | typedef typename s_lv_type<W>::lv_type data_type; |
---|
| 114 | data_type val; |
---|
| 115 | |
---|
| 116 | public: |
---|
| 117 | // constructors |
---|
| 118 | sc_lv() { val = 0; } |
---|
| 119 | explicit sc_lv(bool init_value) { val = 0; } |
---|
| 120 | explicit sc_lv (char init_value) { val = 0; } |
---|
| 121 | sc_lv(const char * a) { val = 0; write(atoi(a)); } |
---|
| 122 | sc_lv(const bool * a) { val = 0; write(a); } |
---|
| 123 | sc_lv(const sc_logic * a) { val = 0; write(a); } |
---|
| 124 | sc_lv(const sc_unsigned & a) { val = 0; write(a); } |
---|
| 125 | sc_lv(const sc_signed & a) { val = 0; write(a); } |
---|
[59] | 126 | sc_lv(unsigned int a) { val = 0; write(a); } |
---|
| 127 | sc_lv(unsigned long a) { val = 0; write(a); } |
---|
[52] | 128 | sc_lv(long a) { val = 0; write(a); } |
---|
| 129 | sc_lv(int a) { val = 0; write(a); } |
---|
| 130 | sc_lv(uint64 a) { val = 0; write(a); } |
---|
| 131 | sc_lv(int64 a) { val = 0; write(a); } |
---|
| 132 | sc_lv(const sc_lv_base & a) { val = 0; write(a); } |
---|
| 133 | sc_lv(const sc_lv < W > & a) { val = 0; write(a); } |
---|
| 134 | |
---|
| 135 | // assignment operators |
---|
[1] | 136 | #ifdef LRM |
---|
[52] | 137 | template < class X > sc_lv < W > & operator = (const sc_lv_base & a); |
---|
| 138 | sc_lv < W > & operator = (const sc_lv < W > &a); |
---|
| 139 | sc_lv < W > & operator = (const char *a); |
---|
| 140 | sc_lv < W > & operator = (const bool * a); |
---|
| 141 | sc_lv < W > & operator = (const sc_logic * a); |
---|
| 142 | sc_lv < W > & operator = (const sc_unsigned & a); |
---|
| 143 | sc_lv < W > & operator = (const sc_signed & a); |
---|
[1] | 144 | #endif // LRM |
---|
| 145 | |
---|
[59] | 146 | template < typename T > inline sc_lv& operator = (const T& val_) { |
---|
[52] | 147 | write (val_); |
---|
| 148 | return *this; |
---|
| 149 | } |
---|
| 150 | sc_lv < W > & operator = (unsigned long a); |
---|
| 151 | sc_lv < W > & operator = (long a); |
---|
| 152 | sc_lv < W > & operator = (unsigned int a); |
---|
| 153 | sc_lv < W > & operator = (int a) { val = a; return *this; } |
---|
| 154 | sc_lv < W > & operator = (uint64 a); |
---|
| 155 | sc_lv < W > & operator = (int64 a); |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | /***********************/ |
---|
| 159 | /* SYSTEMCASS SPECIFIC */ |
---|
| 160 | /***********************/ |
---|
| 161 | // read/write |
---|
| 162 | inline void write(data_type val_) { |
---|
| 163 | val = val_; |
---|
| 164 | } |
---|
| 165 | template <int W2> inline void write (const sc_lv<W2> val_) { |
---|
| 166 | write (val_.read()); |
---|
| 167 | } |
---|
| 168 | |
---|
[1] | 169 | }; |
---|
| 170 | |
---|
| 171 | } /* end of sc_dt namespace */ |
---|
| 172 | |
---|
| 173 | #endif /* __SC_LV_H__ */ |
---|
[52] | 174 | |
---|
| 175 | /* |
---|
| 176 | # Local Variables: |
---|
| 177 | # tab-width: 4; |
---|
| 178 | # c-basic-offset: 4; |
---|
| 179 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 180 | # indent-tabs-mode: nil; |
---|
| 181 | # End: |
---|
| 182 | # |
---|
| 183 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 184 | */ |
---|
| 185 | |
---|