source: sources/src/sc_signal.h @ 47

Last change on this file since 47 was 47, checked in by buchmann, 15 years ago

This patch simplifies SystemCASS.

Remove:

  • ckeckings about multiwriting on registers and ports
  • checkings related to FSM modeling
  • regression tests related to the checkings
File size: 8.0 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                   sc_signal.h                     |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                           Taktak Sami                       |
9|                                                             |
10| Date    :                   09_07_2004                      |
11|                                                             |
12\------------------------------------------------------------*/
13#ifndef __SC_SIGNAL_H__
14#define __SC_SIGNAL_H__
15
16// Define registers writing method
17#include <iostream>
18#include <cstdlib>
19#include "sc_fwd.h"
20#include "sc_nbdefs.h"
21//#include "sc_event_finder.h"
22//#include "sc_event.h"
23#include "sc_time.h" // SC_ZERO_TIME
24#include "sc_object.h"
25#include "sc_interface.h"
26#include "internal_ext.h"
27
28namespace sc_core {
29
30//
31#if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4))
32#define INLINE __attribute__((always_inline))
33#else
34/* gcc3.4 doesn't support */ 
35#define INLINE
36#endif
37
38#define READ_SIGNAL(value_type_,pointer_) \
39        ((value_type_&) (*((value_type_*) (pointer_))))
40
41        ///////////////////// DEPRECATED
42// C ANSI-only since it is needed to link with extern "C"
43
44extern void bind (sc_port_base&,sc_port_base&);
45extern void bind (sc_port_base&,sc_signal_base&);
46extern void bind (sc_signal_base &x);
47extern void bind (sc_port_base   &x);
48typedef tab_t base_type;
49struct pending_write_t {
50        base_type   *pointer;
51        base_type    value;
52        //pending_write_t (base_type *const pointer_, const base_type value_)
53        //{     pointer = pointer_; value = value_; }
54        friend std::ostream& operator << (std::ostream &o, const pending_write_t &p)
55        { return o << "(pointer = " << p.pointer << "; value = " << p.value << ")\n"; }
56};
57
58// Check pending_writing to register
59extern void pending_writing2register_clear  ();
60extern void pending_writing2register_record_and_check (const tab_t *);
61
62// Pending write to register (simple stack)
63typedef pending_write_t *pending_write_vector_t;
64extern pending_write_vector_t pending_write_vector;
65extern "C" unsigned int pending_write_vector_nb;
66extern unsigned int pending_write_vector_capacity;
67
68
69template <typename T>
70inline void post_write (base_type *const pointer_,
71                        const T          value_) /*INLINE*/;
72template <typename T>
73inline void post_multiwrite (base_type *const pointer_,
74                             const T          value_)
75{
76        size_t size = (sizeof (T)-1) / sizeof (base_type);
77        size_t i = 0;
78        const base_type *pvalue = (const base_type*)(void*)(&value_);
79        do {
80#if 0
81    cout << "post_multiwrite 0x" << hex << pvalue[i] << " @" << (pointer_ + i) << "\n";
82#endif
83                post_write (pointer_ + i, pvalue[i]);
84        } while (i++ < size);
85}
86template <typename T>
87inline void post_write (base_type *const pointer_, 
88                        const T          value_)
89{
90  if (sizeof (T) > sizeof (base_type)) {
91#if 0
92    std::cout << "sizeof (T) = " << sizeof (T)
93            << " (base_type = " << sizeof (base_type) << "\n";
94#endif
95    post_multiwrite (pointer_,value_);
96  } else {
97#if defined(CONFIG_DEBUG)
98    if (pending_write_vector_nb >= pending_write_vector_capacity) {
99      //if (pending_write_vector_nb >= pending_write_vector_capacity * sizeof(pending_write_t)) {
100      std::cerr << "Error : The array for posted writing on register is too small.\n";
101      std::cerr << "Up to 1 writing per register is allowed during a cycle.\n";
102      std::cerr << "Please check the hardware description.\n";
103      exit (-1);
104    }
105#endif // CONFIG_DEBUG
106    pending_write_vector[pending_write_vector_nb].pointer = pointer_;
107//      pending_write_vector[pending_write_vector_nb++].value = *(reinterpret_cast<const base_type*const>(&value_)); => bug !
108    pending_write_vector[pending_write_vector_nb++].value = value_; // => bug avec blues !
109
110        // -> fix to use user-defined struct in sc_signal/sc_in/sc_out/sc_inout
111        // pending_write_vector[pending_write_vector_nb++].value = *((base_type*)&value_); => bug !
112#if 0
113        std::cerr << "posted write : ptr = " << pointer_ << ", val = " << value_ << "\n";
114#endif
115#if 0 
116        // introduce bug on using trace functions
117        if (value_ == READ_SIGNAL(T,pointer_))
118                return;
119#endif
120  };
121}
122
123inline bool is_posted_write ()
124{
125  return pending_write_vector_nb > 0;
126}
127
128extern "C" void update (void);
129
130// ----------------------------------------------------------------------------
131//  CLASS : sc_signal_base
132//
133//  The sc_signal_base<T> primitive channel class.
134// ----------------------------------------------------------------------------
135
136class sc_signal_base : public sc_object, public sc_interface
137{
138  //////
139  // Internal
140  friend class sc_clock;
141  friend class sc_port_base;
142  void init ();
143  //////                                 
144 
145
146public: 
147  // LRM (?)
148  //virtual const sc_event /*&*/ default_event () const;
149  static const char* const kind_string;
150  //virtual const char *kind () const;
151
152  //
153public:
154  sc_signal_base();
155  sc_signal_base(const char* name_);
156  sc_signal_base(const char* name_, void*);
157  ~sc_signal_base();
158};
159
160template <typename T>
161class sc_signal : public sc_signal_base
162{
163private:
164  T val;
165  typedef T                data_type;
166  typedef sc_signal < T >  this_type;
167
168  ///////////
169  // Internal
170public: void init ();
171  ///////////
172
173  //  virtual void update ();
174  void check_writer ();
175public:
176  // constructors, destructor
177  sc_signal () 
178  { init (); }
179  explicit sc_signal (const char *name_): sc_signal_base(name_)
180  { init (); }
181  /*virtual */~ sc_signal () 
182  {}
183  // methods
184  /*
185  virtual void register_port (sc_port_base &, const char *)
186  {}
187  virtual const sc_event & default_event () const
188  {}
189  virtual const sc_event & value_changed_event () const
190  {}
191  */
192  /*virtual*/ inline const data_type & read () const INLINE;
193/*
194  virtual const T & get_data_ref () const
195  {}
196  virtual bool event () const
197  {}
198  */
199  /*virtual*/ inline void write (const data_type &) /*INLINE*/;
200  inline operator const data_type & () const
201  { return this->read(); }
202  inline this_type& operator = (const data_type & a)
203  { sc_signal<T>::write (a); return *this; }
204  inline this_type& operator = (const sc_signal < T > &a)
205  { sc_signal<T>::write (a.read()); return *this; }
206  inline this_type& operator += (const data_type & a)
207  { sc_signal<T>::write (read() + a); return *this; }
208  inline this_type& operator += (const sc_signal < T > &a)
209  { sc_signal<T>::write (read()+a.read()); return *this; }
210  const data_type & get_new_value () const;
211//  void trace (sc_trace_file * tf) const;
212  /*
213        virtual void print (std::ostream &o) const
214  { o << *this; }
215  virtual void dump (std::ostream &o) const
216  { o << *this; }
217        */
218private:
219  // disabled
220  sc_signal (const sc_signal < T > &);
221
222};
223
224template <typename T>
225void
226sc_signal<T>::init()
227{
228        set_pointer ((tab_t*)(void*)&val);
229  set_kind    (kind_string);
230  sc_interface::init (sizeof (data_type)); 
231  val = 0; /* The simulator initializes the signal/register to 0.    */
232           /* However, hardware initialization still has to be done. */
233           /* This kind of initialization is for trace diffing.      */
234}
235// read the value
236template <typename T>
237/*virtual*/ 
238inline 
239const T & 
240sc_signal<T>::read() const
241{
242#ifdef DUMP_READ
243  std::cerr << "read " << READ_SIGNAL(const T, get_pointer())
244                << " on signal " << name () << "\n";
245#endif
246    return READ_SIGNAL(const T, get_pointer());
247}
248
249// write the new value
250template <typename T>
251inline
252void
253sc_signal<T>::write( const data_type& value_ )
254{
255#ifdef CONFIG_DEBUG
256  if (get_pointer() == NULL)
257  {
258    std::cerr << "Error : Unable to write into '" << name () << "'.";
259    exit (24032005);
260  }
261#endif
262#ifdef DUMP_WRITE
263  if (sc_signal<T>::read() == value_)
264    return;
265  std::cerr << "write (posted) " << value_
266                << " on sc_signal (writing into register) '" << name () << "'\n";
267#endif
268  post_write (/*(tab_t*)&val*/ get_pointer(), value_);
269}
270
271#undef INLINE
272
273#undef READ_SIGNAL
274
275} // end of namespace sc_core
276
277#endif /* __SC_SIGNAL_H__ */
278
Note: See TracBrowser for help on using the repository browser.