source: sources/src/sc_port_ext.h @ 60

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