source: sources/src/sc_port_ext.h

Last change on this file was 62, checked in by meunier, 7 years ago
  • Functional (or supposedly functional) OpenMP support configure must be run with --enable-use-omp and the topcell must define the USE_OPENMP flag before including the .h files of systemcass (if openmp enabled).
File size: 11.0 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
14#ifndef __SC_PORT_EXT_H__
15#define __SC_PORT_EXT_H__
16
17// Define registers writing method
18#include <iostream>
19#include <cstdlib>
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"
28#include "sc_fwd.h"
29#include "sc_interface.h"
30#include "sc_nbdefs.h"
31#include "sc_object.h"
32
33
34//__GNUC__
35//__GNUC_MINOR__
36//__GNUC_PATCHLEVEL__
37//
38#if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4))
39    #define INLINE __attribute__((always_inline))
40#else
41    /* gcc3.4 doesn't support */ 
42    #define INLINE
43#endif
44
45#include <list>
46
47
48namespace sc_core {
49
50using namespace sc_dt;
51
52const char * get_name(const tab_t * pointer);
53
54#define READ_SIGNAL(value_type_,pointer_) \
55  ((value_type_&) (*((value_type_*) (pointer_))))
56
57
58///////////////////// DEPRECATED
59// C ANSI-only since it is needed to link with extern "C"
60
61
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
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
72extern "C" void update(void);
73
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;
100};
101
102
103template < typename T > class sc_port_b : public sc_port_base
104{
105};
106
107
108// ----------------------------------------------------------------------------
109//  CLASS : sc_in< T >
110//
111// ----------------------------------------------------------------------------
112
113template < typename T >
114class sc_in : public sc_port_base {
115
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;
121
122
123    ///////////
124    // Internal
125    void init();
126    ///////////
127
128    public:
129    // constructors
130    sc_in() : base_type() { init(); }
131
132    explicit sc_in(const char * name_) : base_type(name_) { init(); }
133
134    explicit sc_in(const base_type & parent_) : base_type( parent_ ) { init(); }
135
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"; };
142
143    sc_event neg() const { return sc_event(*this, sc_event::NEG); };
144    sc_event pos() const { return sc_event(*this, sc_event::POS); };
145
146    // read the current value
147    inline const T & read() const INLINE; 
148    inline operator const T & () const INLINE;
149
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
169};
170
171
172template < typename T >
173void sc_in< T >::init() { 
174    set_kind(sc_in_string);
175    sc_interface::init(sizeof(data_type)); 
176}
177
178
179// read
180template < typename T > inline 
181const T & sc_in< T >::read() const { 
182#ifdef DUMP_READ
183    std::cerr << "read " << READ_SIGNAL(const T &, get_pointer())
184     << " on signal " << name() << "\n";
185#endif
186    return READ_SIGNAL(const T, get_pointer());
187}
188 
189
190template < typename T > inline 
191sc_in< T >::operator const T & () const {
192    return sc_in< T >::read();
193}
194
195
196template < typename T > inline 
197bool sc_in< T >::operator == (const T & v) {
198    return sc_in< T >::read() == v;
199}
200
201
202
203// ----------------------------------------------------------------------------
204//  CLASS : sc_inout< T >
205//
206// ----------------------------------------------------------------------------
207
208template < typename  T >
209class sc_inout : public sc_port_base {
210
211  ///////////
212  // Internal
213    protected:
214    void init();
215    T val;
216
217    private:
218    typedef T data_type;
219
220    typedef sc_inout<data_type> this_type;
221    typedef sc_signal<data_type> signal_type;
222
223   
224    public:
225    // contructeurs
226    sc_inout() : base_type() { init (); };
227
228    explicit sc_inout(const char * name_) : base_type(name_) { init(); };
229
230    /*
231    // LRM error !
232    //static const char *const kind_string; this is a template !
233    */
234
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    }
242
243    inline operator const T & () const INLINE;
244
245    inline sc_inout< T > & operator = (const T & a) INLINE;
246    inline sc_inout< T > & operator = (const sc_signal< T > & a) INLINE;
247
248    // operateur ==
249    inline bool operator == (const bool & v) INLINE;
250
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() {};
262};
263
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);
272    /* Fix :
273     * FSM checker generates an error at runtime
274     */
275
276}
277
278
279// read
280template < typename T >
281inline const T & sc_inout< T >::read() const {
282#ifdef DUMP_READ
283    std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) // val
284        << " on signal " << name () << "\n";
285#endif
286    //  return val;
287    return READ_SIGNAL(const T, get_pointer());
288}
289
290
291// write the new value
292template < typename T >
293inline void sc_inout< T >::write(const T & value_) {
294#ifdef DUMP_WRITE
295    std::cerr << "write " << value_ << " on in/out port (writing into a signal) '" << name() << "'\n";
296#endif
297    T * p = (T *) get_pointer();
298    if (*p != value_) {
299        *p = value_;
300#ifndef USE_PORT_DEPENDENCY
301        if (unstable == 0) {
302            unstable = 1;
303        }
304#endif
305    }
306}
307
308
309template < typename T >
310inline sc_inout< T >::operator const T & () const {
311    return sc_inout< T >::read();
312}
313
314
315template < typename T >
316inline sc_inout< T > & sc_inout< T >::operator = (const T & a) {
317    sc_inout< T >::write(a);
318    return *this;
319}
320
321
322template < typename T >
323inline sc_inout< T > & sc_inout< T >::operator = (const sc_signal< T > & a) {
324    sc_inout< T >::write(a.read());
325    return *this;
326}
327
328
329/*
330   template <typename T>
331   inline
332   sc_inout<T>& sc_inout<T>::operator = ( const sc_port_base& a )
333   { write( a.read() ); return *this; }
334   */
335
336
337template < typename T > inline 
338bool sc_inout< T >::operator == (const bool & v) {
339    return sc_inout< T >::read() == v;
340}
341
342
343// ----------------------------------------------------------------------------
344//  CLASS : sc_out<T>
345//
346// ----------------------------------------------------------------------------
347// Official SystemC implementation notes :
348// "sc_out can also read from its port, hence no difference with sc_inout.
349// For debugging reasons, a class is provided instead of a define."
350
351template < typename T >
352class sc_out : public sc_inout< T > {
353
354    ///////////
355    // Internal
356    void init();
357    ///////////
358 
359    public:
360    typedef T data_type;
361    typedef sc_inout< T > base_type;
362    typedef sc_out<data_type> this_type;
363    typedef sc_signal<data_type> signal_type;
364
365
366    // constructors & destructor
367    sc_out() : base_type() {
368        init();
369    }
370
371    explicit sc_out(const char * name_) : base_type(name_) {
372        init();
373    }
374
375    sc_out(this_type & parent_);
376    sc_out(const char * name_, this_type & parent_);
377
378    /*
379    // LRM error !
380    //static const char *const kind_string; this is a template !
381    */
382    //virtual const char *kind () const
383    //{ return "sc_out"; };
384
385
386    inline this_type & operator = (const data_type & a) INLINE;
387    inline bool operator == (const bool & v) INLINE;
388
389    // bind to in interface
390    void operator () (sc_signal<data_type> & s) {
391        bind(*this, s);
392    }
393
394    void operator () (this_type & parent_) {
395        bind(*this, parent_);
396    }
397
398    //////////////////////
399    // Systemcass specific
400    void operator () (sc_port_base & o) {
401        set_port_dependency(&o, (sc_port_base &) (*this));
402    }
403    //////////////////////
404
405
406    /*virtual */~sc_out() {};
407
408    private:
409    // disabled
410    sc_out(const this_type &);
411
412};
413
414
415
416template< typename T >
417void sc_out< T >::init() {
418    sc_inout< T >::init();
419    //  tab_t *t = &(sc_inout<T>::val);
420    //  sc_interface::set_pointer (t);
421    sc_object::set_kind(sc_out_string);
422    //  sc_interface::init (sizeof (data_type));
423    //  /*ref*/ sc_inout<T>::val = 0;
424    //sc_inout<T>::write (0);
425    /* Fix :
426     * FSM checker generates an error at runtime
427     */
428}
429
430
431template< typename T >
432inline sc_out< T > & sc_out< T >::operator = (const data_type & a) {
433    sc_out< T >::write(a);
434    return *this;
435}
436
437
438template< typename T >
439inline bool sc_out< T >::operator == (const bool & v) {
440    return sc_out< T >::read() == v;
441}
442
443
444// Dumps
445template< typename T >
446inline std::ostream & operator << ( std::ostream & os, const sc_in< T > & r) {
447    return os << r.read();
448}
449
450
451// Add '&'
452template< class T >
453inline std::ostream & operator << ( std::ostream & os, const sc_inout< T > & r) {
454    return os << r.read();
455}
456
457
458template< class T >
459inline std::ostream & operator << ( std::ostream & os, const sc_signal< T > & r) {
460    return os << r.read();
461}
462
463
464// Declarations
465typedef sc_in<bool> sc_in_clk;
466
467#undef INLINE
468
469#undef READ_SIGNAL
470
471} // end of sc_core namespace
472
473using sc_core::sc_in_clk;
474
475#endif /* __SC_PORT_EXT_H__ */
476
477/*
478# Local Variables:
479# tab-width: 4;
480# c-basic-offset: 4;
481# c-file-offsets:((innamespace . 0)(inline-open . 0));
482# indent-tabs-mode: nil;
483# End:
484#
485# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
486*/
487
Note: See TracBrowser for help on using the repository browser.