Changeset 22


Ignore:
Timestamp:
Apr 16, 2009, 2:46:01 PM (15 years ago)
Author:
buchmann
Message:

Fix:

  • add missing system header include
  • add a namespace path to atoi

And... code cleanup:

  • bunch of various operators that share the same implementation now are using the same #define.
  • indent and tab/space
Location:
sources/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sources/src/sc_int.h

    r1 r22  
    1818#include <sc_logic.h>
    1919#include <sc_bv.h>
     20#include <cstdlib>
    2021
    2122// ----------------------------------------------------------------------------
     
    135136  sc_int()                 { val = 0; }
    136137//  sc_int(data_type val_)  { val = 0; write (val_); }
    137   sc_int (const char *a)   { val = 0; write (atoi (a)); }
     138  sc_int (const char *a)   { val = 0; write (std::atoi (a)); }
    138139  sc_int (unsigned short a){ val = 0; write (a); }
    139140  sc_int (short a)         { val = 0; write (a); }
     
    197198
    198199  // arithmetic
    199   template <typename T>
    200   inline sc_int& operator <<= (T v)
    201   { vf.valW <<= v; return *this; }
    202   template <typename T>
    203   inline sc_int& operator >>= (T v)
    204   { vf.valW >>= v; return *this; }
    205   template <typename T>
    206   inline sc_int& operator += (T v)
    207   { vf.valW += v; return *this; }
    208   template <typename T>
    209   inline sc_int& operator -= (T v)
    210   { vf.valW -= v; return *this; }
    211   template <typename T>
    212   inline sc_int& operator *= (T v)
    213   { vf.valW *= v; return *this; }
    214   template <typename T>
    215   inline sc_int& operator /= (T v)
    216   { vf.valW /= v; return *this; }
    217   template <typename T>
    218   inline sc_int& operator %= (T v)
    219   { vf.valW %= v; return *this; }
    220   template <typename T>
    221   inline sc_int& operator &= (T v)
    222   { vf.valW &= v; return *this; }
    223   template <typename T>
    224   inline sc_int& operator |= (T v)
    225   { vf.valW |= v; return *this; }
    226   template <typename T>
    227   inline sc_int& operator ^= (T v)
    228   { vf.valW ^= v; return *this; }
     200#define DEFINE_OPERATOR(OPER)        \
     201  template <typename T>              \
     202  inline sc_int& operator OPER (T v) \
     203  { vf.valW OPER v; return *this; }
     204
     205  DEFINE_OPERATOR(<<=)
     206  DEFINE_OPERATOR(>>=)
     207  DEFINE_OPERATOR(+=)
     208  DEFINE_OPERATOR(-=)
     209  DEFINE_OPERATOR(*=)
     210  DEFINE_OPERATOR(/=)
     211  DEFINE_OPERATOR(%=)
     212  DEFINE_OPERATOR(&=)
     213  DEFINE_OPERATOR(|=)
     214  DEFINE_OPERATOR(^=)
     215#undef DEFINE_OPERATOR
     216
    229217  inline sc_int_bit_ref& operator [] (int v)
    230218  { return (vf.valW >> v) & 1; }
  • sources/src/sc_signal.h

    r17 r22  
    9191                        const T          value_)
    9292{
    93         if (sizeof (T) > sizeof (base_type)) {
     93  if (sizeof (T) > sizeof (base_type)) {
    9494#if 0
    95     cout << "sizeof (T) = " << sizeof (T) << " (base_type = " << sizeof
    96 (base_type) << "\n";
    97 #endif
    98                 post_multiwrite (pointer_,value_);
    99         } else {
     95  std::cout << "sizeof (T) = " << sizeof (T)
     96            << " (base_type = " << sizeof (base_type) << "\n";
     97#endif
     98  post_multiwrite (pointer_,value_);
     99  } else {
    100100#if defined(DEBUG)
    101         if (pending_write_vector_nb >= pending_write_vector_capacity) {
    102         //if (pending_write_vector_nb >= pending_write_vector_capacity * sizeof(pending_write)) {
    103                 std::cerr << "Error : The array for posted writing on register is too small.\n";
    104                 std::cerr << "Up to 1 writing per register is allowed during a cycle.\n";
    105                 std::cerr << "Please check the hardware description.\n";
    106                 exit (-1);
    107         }
     101    if (pending_write_vector_nb >= pending_write_vector_capacity) {
     102      //if (pending_write_vector_nb >= pending_write_vector_capacity * sizeof(pending_write)) {
     103      std::cerr << "Error : The array for posted writing on register is too small.\n";
     104      std::cerr << "Up to 1 writing per register is allowed during a cycle.\n";
     105      std::cerr << "Please check the hardware description.\n";
     106      exit (-1);
     107    }
    108108#endif // DEBUG
    109   pending_write_vector[pending_write_vector_nb].pointer = pointer_;
     109    pending_write_vector[pending_write_vector_nb].pointer = pointer_;
    110110//      pending_write_vector[pending_write_vector_nb++].value = *(reinterpret_cast<const base_type*const>(&value_)); => bug !
    111   pending_write_vector[pending_write_vector_nb++].value = value_; // => bug avec blues !
     111    pending_write_vector[pending_write_vector_nb++].value = value_; // => bug avec blues !
    112112
    113113        // -> fix to use user-defined struct in sc_signal/sc_in/sc_out/sc_inout
     
    121121                return;
    122122#endif
    123         };
     123  };
    124124}
    125125
    126126inline bool is_posted_write ()
    127127{
    128                 return pending_write_vector_nb > 0;
     128  return pending_write_vector_nb > 0;
    129129}
    130130
     
    139139class sc_signal_base : public sc_object, public sc_interface
    140140{
    141         //////
    142         // Internal
     141  //////
     142  // Internal
    143143  friend class sc_clock;
    144144  friend class sc_port_base;
    145145  void init ();
    146         //////                           
     146  //////                                 
    147147 
    148148
     
    158158  sc_signal_base(const char* name_);
    159159  sc_signal_base(const char* name_, void*);
    160         ~sc_signal_base();
     160  ~sc_signal_base();
    161161};
    162162
     
    165165{
    166166private:
    167         T val;
    168   typedef T  data_type;
     167  T val;
     168  typedef T                data_type;
    169169  typedef sc_signal < T >  this_type;
    170         ///////////
    171         // Internal
    172         public: void init ();
    173         ///////////
    174 //  virtual void update ();
     170
     171  ///////////
     172  // Internal
     173public: void init ();
     174  ///////////
     175
     176  //  virtual void update ();
    175177  void check_writer ();
    176178public:
    177179  // constructors, destructor
    178180  sc_signal ()
    179         { init (); }
     181  { init (); }
    180182  explicit sc_signal (const char *name_): sc_signal_base(name_)
    181         { init (); }
     183  { init (); }
    182184  /*virtual */~ sc_signal ()
    183185  {}
     
    229231  set_pointer ((tab_t*)&val);
    230232  set_kind    (kind_string);
    231         sc_interface::init (sizeof (data_type));
     233  sc_interface::init (sizeof (data_type));
    232234  val = 0; /* The simulator initializes the signal/register to 0.    */
    233235           /* However, hardware initialization still has to be done. */
  • sources/src/sc_uint.h

    r11 r22  
    183183
    184184  // arithmetic
    185   template <typename T>
    186   inline sc_uint& operator <<= (T v)
    187   { vf.valW <<= v; return *this; }
    188   template <typename T>
    189   inline sc_uint& operator >>= (T v)
    190   { vf.valW >>= v; return *this; }
    191   template <typename T>
    192   inline sc_uint& operator += (T v)
    193   { vf.valW += v; return *this; }
    194   template <typename T>
    195   inline sc_uint& operator -= (T v)
    196   { vf.valW -= v; return *this; }
    197   template <typename T>
    198   inline sc_uint& operator *= (T v)
    199   { vf.valW *= v; return *this; }
    200   template <typename T>
    201   inline sc_uint& operator /= (T v)
    202   { vf.valW /= v; return *this; }
    203   template <typename T>
    204   inline sc_uint& operator %= (T v)
    205   { vf.valW %= v; return *this; }
    206   template <typename T>
    207   inline sc_uint& operator &= (T v)
    208   { vf.valW &= v; return *this; }
    209   template <typename T>
    210   inline sc_uint& operator |= (T v)
    211   { vf.valW |= v; return *this; }
    212   template <typename T>
    213   inline sc_uint& operator ^= (T v)
    214   { vf.valW ^= v; return *this; }
     185#define DEFINE_OPERATOR(OPER)        \
     186  template <typename T>              \
     187  inline sc_uint& operator OPER (T v)\
     188  { vf.valW OPER v; return *this; }
     189
     190  DEFINE_OPERATOR(<<=)
     191  DEFINE_OPERATOR(>>=)
     192  DEFINE_OPERATOR(+=)
     193  DEFINE_OPERATOR(-=)
     194  DEFINE_OPERATOR(*=)
     195  DEFINE_OPERATOR(/=)
     196  DEFINE_OPERATOR(%=)
     197  DEFINE_OPERATOR(&=)
     198  DEFINE_OPERATOR(|=)
     199  DEFINE_OPERATOR(^=)
     200#undef DEFINE_OPERATOR
     201
     202#if 0
     203#define DEFINE_OPERATOR(OPER)                                              \
     204  friend bool operator OPER (const data_type& a, const data_type& b);
     205//  { return (a.valW) OPER (b.valW); }
     206
     207  DEFINE_OPERATOR(==)
     208  DEFINE_OPERATOR(!=)
     209  DEFINE_OPERATOR(>=)
     210  DEFINE_OPERATOR(<=)
     211#undef DEFINE_OPERATOR
     212#endif
    215213  inline sc_uint_bit_ref operator [] (int v)
    216214  { return (vf.valW >> v) & 1; }
Note: See TracChangeset for help on using the changeset viewer.