Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

_scv_ext_type.h

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003 
00004   The following code is derived, directly or indirectly, from the SystemC
00005   source code Copyright (c) 1996-2002 by all Contributors.
00006   All Rights reserved.
00007 
00008   The contents of this file are subject to the restrictions and limitations
00009   set forth in the SystemC Open Source License Version 2.3 (the "License");
00010   You may not use this file except in compliance with such restrictions and
00011   limitations. You may obtain instructions on how to receive a copy of the
00012   License at http://www.systemc.org/. Software distributed by Contributors
00013   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00014   ANY KIND, either express or implied. See the License for the specific
00015   language governing rights and limitations under the License.
00016 
00017  *****************************************************************************/
00018 
00019 /*****************************************************************************
00020 
00021   _scv_ext_type.h -- The implementation for the extension component "type".
00022 
00023   Original Authors (Cadence Design Systems, Inc):
00024   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00025   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey, Samir Agrawal
00026   2002-09-23
00027 
00028  *****************************************************************************/
00029 
00030 /*****************************************************************************
00031 
00032   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00033   changes you are making here.
00034 
00035       Name, Affiliation, Date:
00036   Description of Modification:
00037 
00038  *****************************************************************************/
00039 
00040 // ----------------------------------------
00041 // specialization for records
00042 // ----------------------------------------
00043 template<typename T>
00044 class scv_extension_type
00045  : public _SCV_INTROSPECTION_BASE {
00046 public:
00047   scv_extension_type() {}
00048   virtual ~scv_extension_type() {}
00049 
00050   virtual scv_extension_type_if::data_type get_type() const { return scv_extension_type_if::RECORD; }
00051 
00052   virtual int get_enum_size() const { return 0; }
00053   virtual void get_enum_details(list<const char *>&, list<int>&) const {}
00054   virtual const char * get_enum_string(int) const { return "_error"; }
00055 
00056   virtual int get_num_fields() const { return this->_get_num_fields(); }
00057   virtual scv_extensions_if * get_field(unsigned i) { return this->_get_field(i); }
00058   virtual const scv_extensions_if * get_field(unsigned i) const { return this->_get_field(i); }
00059 
00060   virtual scv_extensions_if * get_pointer() { return 0; }
00061   virtual const scv_extensions_if * get_pointer() const { return 0; }
00062 
00063   virtual int get_array_size() const { return 0; }
00064   virtual scv_extensions_if * get_array_elt(int) { return 0; }
00065   virtual const scv_extensions_if * get_array_elt(int) const { return 0; }
00066 
00067   virtual int get_bitwidth() const {
00068     list<_scv_extension_util*>::const_iterator f;
00069     int size = 0;
00070     for (f = this->_fields.begin(); f!= this->_fields.end(); ++f)
00071       { size += (*f)->get_bitwidth(); }
00072     return size;
00073   }
00074 
00075   virtual scv_extensions_if * get_parent() { return this->_parent; }
00076   virtual const scv_extensions_if * get_parent() const { return this->_parent; }
00077 };
00078 
00079 // ----------------------------------------
00080 // specialization for array
00081 // ----------------------------------------
00082 template<typename T, int N>
00083 class scv_extension_type<T[N]>
00084  : public _SCV_INTROSPECTION_BASE2 {
00085 public:
00086   scv_extension_type() {}
00087   virtual ~scv_extension_type() {}
00088 
00089   virtual const char * get_type_name() const {   
00090     static const char * s = _scv_ext_util_get_name("%s[%d]", 
00091      scv_extensions<T>().get_type_name(), N);
00092     return s;
00093   }
00094 
00095   virtual scv_extension_type_if::data_type get_type() const { return scv_extension_type_if::ARRAY; }
00096 
00097   virtual int get_enum_size() const { return 0; }
00098   virtual void get_enum_details(list<const char *>&, list<int>&) const {}
00099   virtual const char * get_enum_string(int) const { return "_error"; }
00100 
00101   virtual int get_num_fields() const { return 0; }
00102   virtual scv_extensions_if * get_field(unsigned i) { return 0; }
00103   virtual const scv_extensions_if * get_field(unsigned i) const { return 0; }
00104 
00105   virtual scv_extensions_if * get_pointer() { return 0; }
00106   virtual const scv_extensions_if * get_pointer() const { return 0; }
00107 
00108   virtual int get_array_size() const { return N; }
00109   virtual scv_extensions_if * get_array_elt(int i) { return this->_get_array_elt(i); }
00110   virtual const scv_extensions_if * get_array_elt(int i) const { return this->_get_array_elt(i); }
00111 
00112   virtual int get_bitwidth() const { return get_array_elt(0)->get_bitwidth() * get_array_size(); }
00113 
00114   virtual scv_extensions_if * get_parent() { return this->_parent; }
00115   virtual const scv_extensions_if * get_parent() const { return this->_parent; }
00116 
00117 };
00118 
00119 // ----------------------------------------
00120 // specialization for pointers
00121 // ----------------------------------------
00122 template<typename T>
00123 class scv_extension_type<T*>
00124  : public _SCV_INTROSPECTION_BASE1 {
00125 public:
00126   scv_extension_type() {}
00127   virtual ~scv_extension_type() {}
00128 
00129   virtual const char*  get_type_name() const { 
00130     static const char* s = _scv_ext_util_get_name("%s*", 
00131       scv_extensions<T>().get_type_name());
00132     return s;
00133   }
00134 
00135   virtual scv_extension_type_if::data_type get_type() const { return scv_extension_type_if::POINTER; }
00136 
00137   virtual int get_enum_size() const { return 0; }
00138   virtual void get_enum_details(list<const char *>&, list<int>&) const {}
00139   virtual const char * get_enum_string(int) const { return "_error"; }
00140 
00141   virtual int get_num_fields() const { return 0; }
00142   virtual scv_extensions_if * get_field(unsigned i) { return 0; }
00143   virtual const scv_extensions_if * get_field(unsigned i) const { return 0; }
00144 
00145   virtual scv_extensions_if * get_pointer() { return this->_get_pointer(); }
00146   virtual const scv_extensions_if * get_pointer() const { return this->_get_pointer(); }
00147 
00148   virtual int get_array_size() const { return 0; }
00149   virtual scv_extensions_if * get_array_elt(int) { return 0; }
00150   virtual const scv_extensions_if * get_array_elt(int) const { return 0; }
00151 
00152   virtual int get_bitwidth() const { return sizeof(T*); }
00153 
00154   virtual scv_extensions_if * get_parent() { return this->_parent; }
00155   virtual const scv_extensions_if * get_parent() const { return this->_parent; }
00156 };
00157 
00158 // ----------------------------------------
00159 // specialization for enums
00160 // ----------------------------------------
00161 class _scv_extension_type_enum
00162   : public _SCV_INTROSPECTION_BASE_ENUM {
00163 public:
00164   _scv_extension_type_enum() {}
00165   virtual ~_scv_extension_type_enum() {}
00166 
00167   // implemented in leaf classes
00168   // virtual const char *get_type_name() const;
00169 
00170   virtual scv_extension_type_if::data_type get_type() const;
00171 
00172   virtual int get_enum_size() const;
00173   virtual void get_enum_details(list<const char *>&, list<int>&) const;
00174   virtual const char * get_enum_string(int) const;
00175 
00176   virtual int get_num_fields() const;
00177   virtual scv_extensions_if * get_field(unsigned);
00178   virtual const scv_extensions_if * get_field(unsigned) const;
00179 
00180   virtual scv_extensions_if * get_pointer();
00181   virtual const scv_extensions_if * get_pointer() const;
00182 
00183   virtual int get_array_size() const;
00184   virtual scv_extensions_if * get_array_elt(int);
00185   virtual const scv_extensions_if * get_array_elt(int) const;
00186 
00187   // implemented in leaf classes
00188   // virtual int get_bitwidth() const;
00189 
00190   virtual scv_extensions_if * get_parent() { return this->_parent; }
00191   virtual const scv_extensions_if * get_parent() const { return this->_parent; }
00192 
00193 public:
00194   void _set_enum(int e, const char * name) {
00195     _get_names().push_back(name);
00196     _get_values().push_back(e);
00197   }
00198 };
00199 
00200 
00201 
00202 // ----------------------------------------
00203 // specialization for basic types
00204 // ----------------------------------------
00205 
00206 #define _SCV_EXT_TYPE_FC_D(type_name,type_id) \
00207 class _scv_extension_type_ ## type_id \
00208  : public scv_extension_util<type_name> { \
00209 public: \
00210   _scv_extension_type_ ## type_id() { } \
00211   virtual ~_scv_extension_type_ ## type_id() { } \
00212   \
00213   virtual int get_enum_size() const; \
00214   virtual void get_enum_details(list<const char *>&, list<int>&) const; \
00215   virtual const char * get_enum_string(int) const; \
00216   virtual int get_num_fields() const; \
00217   virtual scv_extensions_if * get_field(unsigned); \
00218   virtual const scv_extensions_if * get_field(unsigned) const; \
00219   virtual scv_extensions_if * get_pointer(); \
00220   virtual const scv_extensions_if * get_pointer() const; \
00221   virtual int get_array_size() const; \
00222   virtual scv_extensions_if * get_array_elt(int); \
00223   virtual const scv_extensions_if * get_array_elt(int) const; \
00224   virtual scv_extensions_if * get_parent(); \
00225   virtual const scv_extensions_if * get_parent() const; \
00226   \
00227   virtual const char* get_type_name() const; \
00228   virtual scv_extension_type_if::data_type get_type() const; \
00229   virtual int get_bitwidth() const; \
00230 }; \
00231 \
00232 template<> \
00233 class scv_extension_type<type_name> \
00234  : public _scv_extension_type_ ## type_id { \
00235 public:  \
00236   scv_extension_type() {} \
00237   virtual ~scv_extension_type() {} \
00238 }; \
00239 
00240 
00241 #define _SCV_EXT_TYPE_1_FC_D(type_name,type_id) \
00242   _SCV_EXT_TYPE_FC_D(type_name,type_id) \
00243 
00244 
00245 #define _SCV_EXT_TYPE_N_FC_D(type_name,id) \
00246 template<int N> \
00247 class scv_extension_type<type_name > \
00248  : public scv_extension_util<type_name > { \
00249 public:  \
00250   scv_extension_type() {} \
00251   virtual ~scv_extension_type() {} \
00252          \
00253   virtual int get_enum_size() const { return 0; } \
00254   virtual void get_enum_details(list<const char *>&, list<int>&) const {} \
00255   virtual const char * get_enum_string(int) const { return "_error"; } \
00256   virtual int get_num_fields() const { return 0; } \
00257   virtual scv_extensions_if * get_field(unsigned) { return 0; } \
00258   virtual const scv_extensions_if * get_field(unsigned) const { return 0; } \
00259   virtual scv_extensions_if * get_pointer() { return 0; } \
00260   virtual const scv_extensions_if * get_pointer() const { return 0; } \
00261   virtual int get_array_size() const { return 0; } \
00262   virtual scv_extensions_if * get_array_elt(int) { return 0; } \
00263   virtual const scv_extensions_if * get_array_elt(int) const { return 0; } \
00264   virtual scv_extensions_if * get_parent() { return this->_parent; } \
00265   virtual const scv_extensions_if * get_parent() const { return this->_parent; } \
00266         \
00267   virtual const char* get_type_name() const { \
00268     static const char* s = _scv_ext_util_get_name("%s<%d>",#type_name, N); \
00269     return s; \
00270   } \
00271   virtual scv_extension_type_if::data_type get_type() const { \
00272     return scv_extensions_if::id; \
00273   } \
00274   virtual int get_bitwidth() const { return N; } \
00275 }; \
00276 
00277 
00278 #define _SCV_EXT_TYPE_D_FC_D(type_name,type_id) \
00279 class _scv_extension_type_ ## type_id \
00280  : public scv_extension_util<type_name> { \
00281 public: \
00282   _scv_extension_type_ ## type_id(); \
00283   virtual ~_scv_extension_type_ ## type_id(); \
00284   \
00285   virtual int get_enum_size() const; \
00286   virtual void get_enum_details(list<const char *>&, list<int>&) const; \
00287   virtual const char * get_enum_string(int) const; \
00288   virtual int get_num_fields() const; \
00289   virtual scv_extensions_if * get_field(unsigned); \
00290   virtual const scv_extensions_if * get_field(unsigned) const; \
00291   virtual scv_extensions_if * get_pointer(); \
00292   virtual const scv_extensions_if * get_pointer() const; \
00293   virtual int get_array_size() const; \
00294   virtual scv_extensions_if * get_array_elt(int); \
00295   virtual const scv_extensions_if * get_array_elt(int) const; \
00296   virtual scv_extensions_if * get_parent(); \
00297   virtual const scv_extensions_if * get_parent() const; \
00298   \
00299   virtual const char* get_type_name() const; \
00300   virtual scv_extension_type_if::data_type get_type() const; \
00301   virtual int get_bitwidth() const; \
00302   int _bitwidth; \
00303 }; \
00304 \
00305 template<> \
00306 class scv_extension_type<type_name> \
00307  : public _scv_extension_type_ ## type_id { \
00308 public:  \
00309   scv_extension_type() {} \
00310   virtual ~scv_extension_type() {} \
00311 }; \
00312 
00313 _SCV_EXT_TYPE_FC_D(bool,bool);
00314 _SCV_EXT_TYPE_FC_D(char,char);
00315 _SCV_EXT_TYPE_FC_D(short,short);
00316 _SCV_EXT_TYPE_FC_D(int,int);
00317 _SCV_EXT_TYPE_FC_D(long,long);
00318 _SCV_EXT_TYPE_FC_D(long long,long_long);
00319 _SCV_EXT_TYPE_FC_D(unsigned char,unsigned_char);
00320 _SCV_EXT_TYPE_FC_D(unsigned short,unsigned_short);
00321 _SCV_EXT_TYPE_FC_D(unsigned int,unsigned_int);
00322 _SCV_EXT_TYPE_FC_D(unsigned long,unsigned_long);
00323 _SCV_EXT_TYPE_FC_D(unsigned long long,unsigned_long_long);
00324 _SCV_EXT_TYPE_FC_D(float,float);
00325 _SCV_EXT_TYPE_FC_D(double,double);
00326 _SCV_EXT_TYPE_FC_D(string,string);
00327 
00328 #ifdef TEST_NEST_TEMPLATE
00329 _SCV_EXT_TYPE_N_FC_D(test_uint<N>,UNSIGNED);
00330 #endif
00331 
00332 #ifdef SYSTEMC_H
00333 _SCV_EXT_TYPE_FC_D(sc_string,sc_string);
00334 _SCV_EXT_TYPE_N_FC_D(sc_int<N>,INTEGER);
00335 _SCV_EXT_TYPE_N_FC_D(sc_bigint<N>,INTEGER);
00336 _SCV_EXT_TYPE_N_FC_D(sc_uint<N>,UNSIGNED);
00337 _SCV_EXT_TYPE_N_FC_D(sc_biguint<N>,UNSIGNED);
00338 _SCV_EXT_TYPE_1_FC_D(sc_bit,sc_bit);
00339 _SCV_EXT_TYPE_N_FC_D(sc_bv<N>,BIT_VECTOR);
00340 _SCV_EXT_TYPE_1_FC_D(sc_logic,sc_logic);
00341 _SCV_EXT_TYPE_N_FC_D(sc_lv<N>,LOGIC_VECTOR);
00342 // SCV_EXT_TYPE_N_FC_D(sc_fixed,FIXED_POINTER_INTEGER);
00343 // SCV_EXT_TYPE_N_FC_D(sc_ufixed,UNSIGNED_FIXED_POINTER_INTEGER);
00344 _SCV_EXT_TYPE_D_FC_D(sc_signed,sc_signed);
00345 _SCV_EXT_TYPE_D_FC_D(sc_unsigned,sc_unsigned);
00346 _SCV_EXT_TYPE_D_FC_D(sc_int_base,sc_int_base);
00347 _SCV_EXT_TYPE_D_FC_D(sc_uint_base,sc_uint_base);
00348 _SCV_EXT_TYPE_D_FC_D(sc_lv_base,sc_lv_base);
00349 _SCV_EXT_TYPE_D_FC_D(sc_bv_base,sc_bv_base);
00350 #endif
00351 
00352 #undef _SCV_EXT_TYPE_FC_D
00353 #undef _SCV_EXT_TYPE_N_FC_D
00354 #undef _SCV_EXT_TYPE_1_FC_D
00355 
00356 
00357 // ----------------------------------------
00358 // wrap up this component
00359 // ----------------------------------------
00360 #undef _SCV_INTROSPECTION_BASE
00361 #define _SCV_INTROSPECTION_BASE scv_extension_type<T>
00362 #undef _SCV_INTROSPECTION_BASE1
00363 #define _SCV_INTROSPECTION_BASE1 scv_extension_type<T*>
00364 #undef _SCV_INTROSPECTION_BASE2
00365 #define _SCV_INTROSPECTION_BASE2 scv_extension_type<T[N]>
00366 
00367 #undef _SCV_INTROSPECTION_BASE_ENUM
00368 #define _SCV_INTROSPECTION_BASE_ENUM _scv_extension_type_enum

Generated on Fri Jan 14 08:28:55 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18