source: latest/src/sc_port_ext.h @ 1

Last change on this file since 1 was 1, checked in by buchmann, 17 years ago

Initial import from CVS repository

File size: 11.8 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                   sc_port_ext.h                   |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                           Taktak Sami                       |
9|                                                             |
10| Date    :                   09_07_2004                      |
11|                                                             |
12\------------------------------------------------------------*/
13#ifndef __SC_PORT_EXT_H__
14#define __SC_PORT_EXT_H__
15
16// Define registers writing method
17#include<iostream>
18#include"sc_fwd.h"
19#include"sc_nbdefs.h"
20//#include"sc_event_finder.h"
21#include"sc_event.h"
22#include"sc_object.h"
23#include"sc_interface.h"
24#include"internal_ext.h"
25#include"port_dependency_ext.h"
26#include"fsm_rules.h"
27
28
29//__GNUC__
30//__GNUC_MINOR__
31//__GNUC_PATCHLEVEL__
32//
33#if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4))
34#define INLINE __attribute__((always_inline))
35#else
36/* gcc3.4 doesn't support */ 
37#define INLINE
38#endif
39
40#include <list>
41
42//
43namespace sc_core {
44//
45const char *get_name        (const tab_t *pointer);
46
47#define READ_SIGNAL(value_type_,pointer_) \
48        ((value_type_&) (*((value_type_*) (pointer_))))
49
50        ///////////////////// DEPRECATED
51// C ANSI-only since it is needed to link with extern "C"
52// this declaration is not in casc.h since the CHECK_FSM_RULES macro
53// is not defined.
54
55extern void bind (sc_port_base&,sc_port_base&);
56extern void bind (sc_port_base&,sc_signal_base&);
57extern void bind (sc_signal_base &x);
58extern void bind (sc_port_base   &x);
59
60// KIND STRING
61extern const char * const sc_inout_string;
62extern const char * const sc_in_string;
63extern const char * const sc_out_string; 
64
65extern "C" void update (void);
66
67class sc_port_base : public sc_object, public sc_interface
68{
69protected:
70  typedef sc_port_base                        base_type;
71public:
72        ///////////
73        // Internal
74        const sc_module &get_module () const;
75        void             init ();
76  void             check_multiwriting2port () const;
77        ///////////             
78 
79  friend std::ostream& operator << (std::ostream &, const sc_port_base &);
80 
81  // LRM
82  //virtual const sc_event /*&*/ default_event () const;
83  static const char* const kind_string;
84//  virtual const char *kind () const;
85  //
86  sc_port_base();
87  sc_port_base(const char* name_);
88  explicit sc_port_base(const sc_port_base& parent_);
89  /*virtual */~sc_port_base () {};
90  // bind to a handle
91  void operator () (method_process_t &func) const;
92};
93
94template < typename T > class sc_port_b:public sc_port_base
95{
96};
97
98// ----------------------------------------------------------------------------
99//  CLASS : sc_in<T>
100//
101// ----------------------------------------------------------------------------
102
103template <typename T>
104class sc_in : public sc_port_base
105{
106private:
107  typedef T  data_type;
108  typedef sc_port_base                  base_type;
109  typedef sc_in<data_type>              this_type;
110  typedef sc_signal<data_type>          signal_type;
111
112        ///////////
113        // Internal
114  void init ();
115        /*
116        public: virtual size_t data_size () const
117        { return sizeof (data_type); }
118        */
119        ///////////
120public:
121  // constructors
122  sc_in(): base_type() { init (); }
123
124  explicit sc_in(const char* name_): base_type(name_) { init (); }
125
126  explicit sc_in(const base_type& parent_ ): base_type( parent_ ) { init (); }
127
128        /*
129  // LRM error !
130  //static const char *const kind_string; this is a template !
131        */
132//  virtual const char *kind () const
133//  { return "sc_in"; };
134 
135#if 0
136  // LRM
137  sc_event_finder& neg () const { return *new sc_event_finder (*(sc_port_base*)this);};
138  sc_event_finder& pos () const { return *new sc_event_finder (*(sc_port_base*)this);};
139#endif
140
141  sc_event         neg () const { return sc_event (*this, sc_event::NEG);};
142  sc_event         pos () const { return sc_event (*this, sc_event::POS);};
143  // read the current value
144  inline const T& read() const INLINE; 
145  inline operator const T& () const INLINE;
146
147  // operateur ==
148  inline bool operator == (const T& v) INLINE;
149
150  // bind to in interface
151  void operator () (sc_signal<data_type> &s)
152  { sc_core::bind (*this,s); }
153 
154  // binding for hierarchical description
155  void operator () (this_type &parent_) 
156  { sc_core::bind (*this,parent_); }
157
158  void operator () (sc_out<data_type> &o) 
159  { sc_core::bind (*this,o); }
160
161  /*virtual */~sc_in() {};
162
163};
164
165template <typename T>
166void
167sc_in<T>::init()
168{ 
169        set_kind (sc_in_string);
170        sc_interface::init (sizeof (data_type)); 
171}
172
173// read
174template <typename T> inline 
175const T& 
176sc_in<T>::read() const
177{ 
178#ifdef DUMP_READ
179  std::cerr << "read " << READ_SIGNAL(const T&, get_pointer())
180                << " on signal " << name () << "\n";
181#endif
182#ifdef CHECK_FSM_RULES
183        if (casc_fsm_step == GEN_MOORE) {
184                std::cerr << "FSM rules error : trying to read on input port '" 
185                          << name ()
186                          << "' from " <<  get_step_name () << " function.\n";
187                exit (-1);
188        }               
189#endif
190  return READ_SIGNAL(const T, get_pointer());
191}
192 
193template <typename T> inline 
194sc_in<T>::operator const T& () const
195{ return sc_in<T>::read (); }
196
197template <typename T> inline 
198bool sc_in<T>::operator == (const T& v) {
199  return sc_in<T>::read() == v;
200}
201
202// ----------------------------------------------------------------------------
203//  CLASS : sc_inout<T>
204//
205// ----------------------------------------------------------------------------
206
207template <typename T>
208class sc_inout : public sc_port_base
209{
210        ///////////
211        // Internal
212protected:
213  void init ();
214        T val;
215private:
216  typedef T                                   data_type;
217
218  typedef sc_inout<data_type>                 this_type;
219  typedef sc_signal<data_type>                signal_type;
220
221        /*
222        public: virtual size_t data_size () const
223        { return sizeof (data_type); }
224        */
225        ///////////
226public:
227  // contructeurs
228  sc_inout(): base_type() { init (); };
229
230  explicit sc_inout(const char* name_): base_type(name_) { init (); };
231
232        /*
233  // LRM error !
234  //static const char *const kind_string; this is a template !
235        */
236  //virtual const char *kind () const
237  //{ return "sc_inout"; };
238 
239  // read the current value
240  inline const T& read() const INLINE;
241  // write the new value
242  inline void write( const T& ) INLINE;
243  template <int W> inline void write( const sc_uint<W>& v) 
244  { sc_inout<T>::write (v.read()); }
245
246  inline operator const T& () const INLINE;
247
248  inline sc_inout<T>& operator = ( const T& a ) INLINE;
249 
250  inline sc_inout<T>& operator = ( const sc_signal<T>& a ) INLINE;
251
252//  inline sc_inout<T>& operator = ( const sc_port_base& a ) INLINE;
253
254  // operateur ==
255  inline bool operator == (const bool& v) INLINE;
256
257  // bind to in interface
258  void operator () (sc_signal<data_type> &s)
259  { bind (*this); bind (*this,s); }
260 
261  void operator () (this_type &parent_) 
262  { bind (*this,parent_); }
263
264  /*virtual */~sc_inout() {};
265};
266
267template <typename T>
268void
269sc_inout<T>::init ()
270{
271        set_pointer ((tab_t*)&val);
272        sc_object::set_kind    (sc_inout_string);
273        sc_interface::init (sizeof (data_type)); 
274  /*ref*/ val = (0);
275  //sc_inout::write (0);
276    /* Fix :
277     * FSM checker generates an error at runtime
278     */
279
280}
281
282// read
283template <typename T>
284inline 
285const T& 
286sc_inout<T>::read() const
287{ 
288#ifdef DUMP_READ
289  std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) // val
290                << " on signal " << name () << "\n";
291#endif
292#ifdef CHECK_FSM_RULES
293        if (casc_fsm_step == GEN_MOORE) {
294                std::cerr << "FSM rules error : trying to read on input/output port " 
295                        << name () //get_name (get_pointer())
296                        << " from " << get_step_name () << " function.\n";
297                exit (-1);
298        }               
299#endif
300//  return val;
301  return READ_SIGNAL(const T, get_pointer());
302}
303
304// write the new value
305template <typename T>
306inline
307void
308sc_inout<T>::write( const T& value_ )
309{
310#ifdef DUMP_WRITE
311  std::cerr << "write " << value_
312            << " on in/out port (writing into a signal) '" << name () << "'\n";
313#endif
314#ifdef CHECK_FSM_RULES
315        if ((casc_fsm_step != GEN_MOORE) && ( casc_fsm_step != GEN_MEALY)) {
316                std::cerr << "FSM rules error : trying to write on output port " 
317                        << name () 
318                        << " from an " << get_step_name () << " function.\n";
319                exit (-1);
320        }               
321#endif
322//      T& ref = *(T*)(get_pointer());
323#if defined(CHECK_MULTIWRITING2PORT)
324  check_multiwriting2port ();
325#endif
326#ifndef USE_PORT_DEPENDENCY
327  unstable |= (value_) != val; //ref;
328#endif
329  /*ref*/ val = (value_);
330}
331
332template <typename T>
333inline 
334sc_inout<T>::operator const T& () const
335{ return sc_inout<T>::read(); }
336
337template <typename T>
338inline sc_inout<T>& sc_inout<T>::operator = ( const T& a )
339{ sc_inout<T>::write( a ); return *this; }
340
341template <typename T>
342inline 
343sc_inout<T>& sc_inout<T>::operator = ( const sc_signal<T>& a )
344{ sc_inout<T>::write( a.read() ); return *this; }
345/*
346template <typename T>
347inline
348sc_inout<T>& sc_inout<T>::operator = ( const sc_port_base& a )
349{ write( a.read() ); return *this; }
350*/
351template <typename T>
352inline 
353bool sc_inout<T>::operator == (const bool& v) 
354{ return sc_inout<T>::read() == v; }
355
356// ----------------------------------------------------------------------------
357//  CLASS : sc_out<T>
358//
359// ----------------------------------------------------------------------------
360// Official SystemC implementation notes :
361// "sc_out can also read from its port, hence no difference with sc_inout.
362// For debugging reasons, a class is provided instead of a define."
363
364template <typename T>
365class sc_out : public sc_inout<T>
366{
367        ///////////
368        // Internal
369  void init ();
370        ///////////
371public:
372  // typedefs
373  typedef T data_type;
374  typedef sc_inout<T> base_type;
375  typedef sc_out<data_type>      this_type;
376  typedef sc_signal<data_type>   signal_type;
377public:
378  // constructors & destructor
379  sc_out(): base_type() { init (); };
380  explicit sc_out(const char* name_): base_type(name_) { init (); };
381  sc_out (this_type & parent_);
382  sc_out (const char *name_, this_type & parent_);
383
384        /*
385  // LRM error !
386  //static const char *const kind_string; this is a template !
387        */
388  //virtual const char *kind () const
389  //{ return "sc_out"; };
390 
391
392  inline this_type& operator = ( const data_type& a ) INLINE;
393  inline bool operator == (const bool& v) INLINE;
394
395  // bind to in interface
396  void operator () (sc_signal<data_type> &s)
397  { bind (*this,s); }
398 
399  void operator () (this_type &parent_) 
400  { bind (*this,parent_); }
401
402        //////////////////////
403        // Systemcass specific
404  void operator () (sc_port_base &o)
405  { set_port_dependency (&o, (sc_port_base&)(*this)); }
406/*
407  void operator () () // n'a pas de sens...
408  { set_port_dependency (NULL, (sc_port_base&)(*this)); }
409*/
410        //////////////////////
411
412
413  /*virtual */~ sc_out () {};
414
415private:
416  // disabled
417  sc_out (const this_type &);
418};
419
420//
421template<typename T>
422void
423sc_out<T>::init ()
424{
425  sc_inout<T>::init ();
426//      tab_t *t = &(sc_inout<T>::val);
427//      sc_interface::set_pointer (t);
428        sc_object::set_kind (sc_out_string);
429//      sc_interface::init (sizeof (data_type));
430//  /*ref*/ sc_inout<T>::val = 0;
431  //sc_inout<T>::write (0);
432    /* Fix :
433     * FSM checker generates an error at runtime
434     */
435}
436
437template<typename T> inline 
438sc_out<T>& 
439sc_out<T>::operator = ( const data_type& a )
440{ sc_out<T>::write( a ); return *this; }
441
442template<typename T> inline 
443bool 
444sc_out<T>::operator == (const bool& v) 
445{ return sc_out<T>::read() == v; }
446
447// Dumps
448template<typename T> inline 
449std::ostream& operator<<( std::ostream& os, const sc_in<T> &r) 
450{ return os << r.read (); }
451
452// Add '&'
453template<class T> inline 
454std::ostream& operator<<( std::ostream& os, const sc_inout<T> &r) 
455{ return os << r.read (); }
456
457template<class T> inline 
458std::ostream& operator<<( std::ostream& os, const sc_signal<T> &r)
459{ return os << r.read (); }
460
461// Declarations
462typedef sc_in<bool> sc_in_clk;
463
464#undef INLINE
465
466#undef READ_SIGNAL
467
468} // end of sc_core namespace
469
470using sc_core::sc_in_clk;
471
472#endif /* __SC_PORT_EXT_H__ */
Note: See TracBrowser for help on using the repository browser.