source: sources/src/sc_port_ext.h @ 27

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

SystemCASS now uses autoconf/automake to build the API. Regression tests still
use the old Makefiles.
(thanks to Nicolas Pouillon)

The library directory no longer is "lib-arch-system". The directory now is "lib-linux". Everyone needs to pay attention about SYSTEMCASS environment variable.

Changes:

  • system header includes
  • Add includes to config.h (generated by autoconf/automake)
  • test:
    • linux preprocessor macro instead of _WIN32
    • CONFIG_DEBUG instead of DEBUG

Removes:

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