[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 | \------------------------------------------------------------*/ |
---|
| 12 | #ifndef __SC_LV_H__ |
---|
| 13 | #define __SC_LV_H__ |
---|
| 14 | |
---|
| 15 | // ---------------------------------------------------------------------------- |
---|
| 16 | // CLASS : sc_lv |
---|
| 17 | // |
---|
| 18 | // ---------------------------------------------------------------------------- |
---|
| 19 | |
---|
[8] | 20 | #include "sc_nbdefs.h" |
---|
| 21 | #include "sc_logic.h" |
---|
| 22 | #include "sc_unsigned.h" |
---|
| 23 | #include "sc_signed.h" |
---|
| 24 | #include "sc_uint.h" |
---|
| 25 | #include "sc_int.h" |
---|
[1] | 26 | |
---|
| 27 | |
---|
| 28 | namespace sc_dt { |
---|
| 29 | |
---|
| 30 | template<int W> struct s_lv_type { typedef uint64 lv_type;}; |
---|
| 31 | #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 |
---|
| 32 | DECLAR_LV_TYPE( 1); |
---|
| 33 | DECLAR_LV_TYPE( 2); |
---|
| 34 | DECLAR_LV_TYPE( 3); |
---|
| 35 | DECLAR_LV_TYPE( 4); |
---|
| 36 | DECLAR_LV_TYPE( 5); |
---|
| 37 | DECLAR_LV_TYPE( 6); |
---|
| 38 | DECLAR_LV_TYPE( 7); |
---|
| 39 | DECLAR_LV_TYPE( 8); |
---|
| 40 | #undef DECLAR_LV_TYPE |
---|
| 41 | #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef uint16 lv_type; } |
---|
| 42 | DECLAR_LV_TYPE( 9); |
---|
| 43 | DECLAR_LV_TYPE(10); |
---|
| 44 | DECLAR_LV_TYPE(11); |
---|
| 45 | DECLAR_LV_TYPE(12); |
---|
| 46 | DECLAR_LV_TYPE(13); |
---|
| 47 | DECLAR_LV_TYPE(14); |
---|
| 48 | DECLAR_LV_TYPE(15); |
---|
| 49 | DECLAR_LV_TYPE(16); |
---|
| 50 | #undef DECLAR_LV_TYPE |
---|
| 51 | #define DECLAR_LV_TYPE(W) template<> struct s_lv_type<W> { typedef uint32 lv_type; } |
---|
| 52 | DECLAR_LV_TYPE(17); |
---|
| 53 | DECLAR_LV_TYPE(18); |
---|
| 54 | DECLAR_LV_TYPE(19); |
---|
| 55 | DECLAR_LV_TYPE(20); |
---|
| 56 | DECLAR_LV_TYPE(21); |
---|
| 57 | DECLAR_LV_TYPE(22); |
---|
| 58 | DECLAR_LV_TYPE(23); |
---|
| 59 | DECLAR_LV_TYPE(24); |
---|
| 60 | DECLAR_LV_TYPE(25); |
---|
| 61 | DECLAR_LV_TYPE(26); |
---|
| 62 | DECLAR_LV_TYPE(27); |
---|
| 63 | DECLAR_LV_TYPE(28); |
---|
| 64 | DECLAR_LV_TYPE(29); |
---|
| 65 | DECLAR_LV_TYPE(30); |
---|
| 66 | DECLAR_LV_TYPE(31); |
---|
| 67 | DECLAR_LV_TYPE(32); |
---|
| 68 | #undef DECLAR_LV_TYPE |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | class sc_lv_base |
---|
| 72 | { |
---|
| 73 | public: |
---|
| 74 | // constructors |
---|
| 75 | /* |
---|
| 76 | explicit sc_lv_base (int length_ = sc_length_param ().len ()); |
---|
| 77 | explicit sc_lv_base (bool a, int length_ = sc_length_param ().len ()); |
---|
| 78 | */ |
---|
| 79 | sc_lv_base () { } // SYSTEMCASS SPECIFIC |
---|
| 80 | sc_lv_base (const char *a); |
---|
| 81 | sc_lv_base (const char *a, int length_); |
---|
| 82 | template < class X > sc_lv_base (const sc_lv_base & a); |
---|
| 83 | virtual ~ sc_lv_base () {} |
---|
| 84 | // assignment operators |
---|
| 85 | template < class X > sc_lv_base & operator = (const sc_lv_base & a); |
---|
| 86 | sc_lv_base & operator = (const char *a); |
---|
| 87 | sc_lv_base & operator = (const bool * a); |
---|
| 88 | sc_lv_base & operator = (const sc_logic * a); |
---|
| 89 | sc_lv_base & operator = (const sc_unsigned & a); |
---|
| 90 | sc_lv_base & operator = (const sc_signed & a); |
---|
| 91 | /* |
---|
| 92 | sc_lv_base & operator = (const sc_uint_base & a); |
---|
| 93 | sc_lv_base & operator = (const sc_int_base & a); |
---|
| 94 | */ |
---|
| 95 | sc_lv_base & operator = (unsigned long a); |
---|
| 96 | sc_lv_base & operator = (long a); |
---|
| 97 | sc_lv_base & operator = (unsigned int a); |
---|
| 98 | sc_lv_base & operator = (int a); |
---|
| 99 | sc_lv_base & operator = (uint64 a); |
---|
| 100 | sc_lv_base & operator = (int64 a); |
---|
| 101 | |
---|
| 102 | // methods |
---|
| 103 | int length () const; |
---|
| 104 | bool is_01 () const; |
---|
| 105 | }; |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | template < int W > class sc_lv:public sc_lv_base |
---|
| 109 | { |
---|
| 110 | /***********************/ |
---|
| 111 | /* SYSTEMCASS SPECIFIC */ |
---|
| 112 | /***********************/ |
---|
| 113 | typedef sc_lv<W> this_type; |
---|
| 114 | typedef typename s_lv_type<W>::lv_type data_type; |
---|
| 115 | data_type val; |
---|
| 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); } |
---|
| 126 | /* |
---|
| 127 | sc_lv (const sc_uint_base & a); |
---|
| 128 | sc_lv (const sc_int_base & a); |
---|
| 129 | */ |
---|
| 130 | sc_lv (unsigned long a) { val = 0; write (a); } |
---|
| 131 | sc_lv (long a) { val = 0; write (a); } |
---|
| 132 | sc_lv (unsigned int a) { val = 0; write (a); } |
---|
| 133 | sc_lv (int a) { val = 0; write (a); } |
---|
| 134 | sc_lv (uint64 a) { val = 0; write (a); } |
---|
| 135 | sc_lv (int64 a) { val = 0; write (a); } |
---|
| 136 | sc_lv (const sc_lv_base & a) { val = 0; write (a); } |
---|
| 137 | sc_lv (const sc_lv < W > &a) { val = 0; write (a); } |
---|
| 138 | // assignment operators |
---|
| 139 | #ifdef LRM |
---|
| 140 | template < class X > sc_lv < W > &operator = (const sc_lv_base & a) |
---|
| 141 | sc_lv < W > &operator = (const sc_lv < W > &a) |
---|
| 142 | sc_lv < W > &operator = (const char *a) |
---|
| 143 | sc_lv < W > &operator = (const bool * a) |
---|
| 144 | sc_lv < W > &operator = (const sc_logic * a) |
---|
| 145 | sc_lv < W > &operator = (const sc_unsigned & a) |
---|
| 146 | sc_lv < W > &operator = (const sc_signed & a) |
---|
| 147 | #endif // LRM |
---|
| 148 | template <typename T> inline sc_lv& operator = (const T& val_) |
---|
| 149 | { write (val_); return *this; } |
---|
| 150 | /* |
---|
| 151 | sc_lv < W > &operator = (const sc_uint_base & a); |
---|
| 152 | sc_lv < W > &operator = (const sc_int_base & a); |
---|
| 153 | */ |
---|
| 154 | sc_lv < W > &operator = (unsigned long a); |
---|
| 155 | sc_lv < W > &operator = (long a); |
---|
| 156 | sc_lv < W > &operator = (unsigned int a); |
---|
| 157 | sc_lv < W > &operator = (int a) { val = a; return *this; } |
---|
| 158 | sc_lv < W > &operator = (uint64 a); |
---|
| 159 | sc_lv < W > &operator = (int64 a); |
---|
| 160 | /***********************/ |
---|
| 161 | /* SYSTEMCASS SPECIFIC */ |
---|
| 162 | /***********************/ |
---|
| 163 | // read/write |
---|
| 164 | inline void write(data_type val_) { val = val_; } |
---|
| 165 | template <int W2> inline void write (const sc_lv<W2> val_) { write (val_.read()); } |
---|
| 166 | |
---|
| 167 | }; |
---|
| 168 | |
---|
| 169 | } /* end of sc_dt namespace */ |
---|
| 170 | |
---|
| 171 | #endif /* __SC_LV_H__ */ |
---|