SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_signal_rv.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_signal_rv.h -- The resolved vector signal class.
23
24 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
25
26 CHANGE LOG IS AT THE END OF THE FILE
27 *****************************************************************************/
28
29#ifndef SC_SIGNAL_RV_H
30#define SC_SIGNAL_RV_H
31
34
35namespace sc_core {
36
37class sc_process_b;
38
39// ----------------------------------------------------------------------------
40// CLASS sc_lv_resolve<W>
41//
42// Resolution function for sc_dt::sc_lv<W>.
43// ----------------------------------------------------------------------------
44
46
47
48template <int W>
50{
51public:
52
53 // resolves sc_dt::sc_lv<W> values and returns the resolved value
54 static void resolve(sc_dt::sc_lv<W>&, const std::vector<sc_dt::sc_lv<W>*>&);
55};
56
57
58// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
59
60// resolves sc_dt::sc_lv<W> values and returns the resolved value
61
62template <int W>
63inline
64void
66 const std::vector<sc_dt::sc_lv<W>*>& values_ )
67{
68 int sz = values_.size();
69
70 sc_assert( sz != 0 );
71
72 if( sz == 1 ) {
73 result_ = *values_[0];
74 return;
75 }
76
77 for( int j = result_.length() - 1; j >= 0; -- j ) {
78 sc_dt::sc_logic_value_t res = (*values_[0])[j].value();
79 for( int i = sz - 1; i > 0 && res != 3; -- i ) {
80 res = sc_logic_resolution_tbl[res][(*values_[i])[j].value()];
81 }
82 result_[j] = res;
83 }
84}
85
86
87// ----------------------------------------------------------------------------
88// CLASS : sc_signal_rv<W>
89//
90// The resolved vector signal class.
91// ----------------------------------------------------------------------------
92
93template <int W>
95: public sc_signal<sc_dt::sc_lv<W>, SC_MANY_WRITERS>
96{
97public:
98
99 // typedefs
100
104
105public:
106
107 // constructors
108
110 : base_type( sc_gen_unique_name( "signal_rv" ) )
111 {}
112
113 explicit sc_signal_rv( const char* name_ )
114 : base_type( name_, value_type() )
115 {}
116
117 sc_signal_rv( const char* name_, const value_type& initial_value_ )
118 : base_type( name_, initial_value_ )
119 {}
120
121
122 // destructor
123 virtual ~sc_signal_rv();
124
125
126 // interface methods
127
128 virtual void register_port( sc_port_base&, const char* )
129 {}
130
131
132 // write the new value
133 virtual void write( const value_type& );
134
135
136 // other methods
137 virtual const char* kind() const
138 { return "sc_signal_rv"; }
139
140
141 // assignment
142 using base_type::operator=;
144 { base_type::operator=(a); return *this; }
145
146protected:
147
148 virtual void update();
149
150protected:
151
152 std::vector<sc_process_b*> m_proc_vec; // processes writing this signal
153 std::vector<value_type*> m_val_vec; // new values written this signal
154
155private:
156
157 // disabled
158 sc_signal_rv( const this_type& );
159};
160
161
162// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
163
164
165// destructor
166
167template <int W>
168inline
170{
171 for( int i = m_val_vec.size() - 1; i >= 0; -- i ) {
172 delete m_val_vec[i];
173 }
174}
175
176
177// write the new value
178
179template <int W>
180inline
181void
183{
185
186 bool value_changed = false;
187 bool found = false;
188
189 for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) {
190 if( cur_proc == m_proc_vec[i] ) {
191 if( value_ != *m_val_vec[i] ) {
192 *m_val_vec[i] = value_;
193 value_changed = true;
194 }
195 found = true;
196 break;
197 }
198 }
199
200 if( ! found ) {
201 m_proc_vec.push_back( cur_proc );
202 m_val_vec.push_back( new value_type( value_ ) );
203 value_changed = true;
204 }
205
206 if( value_changed ) {
207 this->request_update();
208 }
209}
210
211
212template <int W>
213inline
214void
216{
217 sc_lv_resolve<W>::resolve( this->m_new_val, m_val_vec );
218 base_type::update();
219}
220
221} // namespace sc_core
222
223//$Log: sc_signal_rv.h,v $
224//Revision 1.4 2011/08/26 20:45:44 acg
225// Andy Goodrich: moved the modification log to the end of the file to
226// eliminate source line number skew when check-ins are done.
227//
228//Revision 1.3 2011/04/19 02:36:26 acg
229// Philipp A. Hartmann: new aysnc_update and mutex support.
230//
231//Revision 1.2 2011/02/18 20:23:45 acg
232// Andy Goodrich: Copyright update.
233//
234//Revision 1.1.1.1 2006/12/15 20:20:04 acg
235//SystemC 2.3
236//
237//Revision 1.3 2006/03/21 00:00:27 acg
238// Andy Goodrich: changed name of sc_get_current_process_base() to be
239// sc_get_current_process_b() since its returning an sc_process_b instance.
240//
241//Revision 1.2 2006/01/03 23:18:26 acg
242//Changed copyright to include 2006.
243//
244//Revision 1.1.1.1 2005/12/19 23:16:43 acg
245//First check in of SystemC 2.1 into its own archive.
246//
247//Revision 1.10 2005/09/15 23:01:52 acg
248//Added std:: prefix to appropriate methods and types to get around
249//issues with the Edison Front End.
250//
251//Revision 1.9 2005/06/10 22:43:55 acg
252//Added CVS change log annotation.
253//
254
255#endif
256
257// Taf!
#define SC_API
Definition: sc_cmnhdr.h:148
#define sc_assert(expr)
Definition: sc_report.h:248
SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
SC_API const sc_dt::sc_logic_value_t sc_logic_resolution_tbl[4][4]
Definition: sc_signal_rv.h:45
sc_process_b * sc_get_current_process_b()
@ SC_MANY_WRITERS
allow multiple writers (with different ports)
sc_logic_value_t
Definition: sc_logic.h:87
sc_core::sc_signal_in_if< T > & value(const T &val)
Definition: sc_stub.h:217
static void resolve(sc_dt::sc_lv< W > &, const std::vector< sc_dt::sc_lv< W > * > &)
Definition: sc_signal_rv.h:65
std::vector< sc_process_b * > m_proc_vec
Definition: sc_signal_rv.h:152
sc_signal_rv(const char *name_, const value_type &initial_value_)
Definition: sc_signal_rv.h:117
sc_signal_rv< W > this_type
Definition: sc_signal_rv.h:101
virtual void register_port(sc_port_base &, const char *)
Definition: sc_signal_rv.h:128
sc_signal_rv(const char *name_)
Definition: sc_signal_rv.h:113
this_type & operator=(const this_type &a)
Definition: sc_signal_rv.h:143
sc_signal< sc_dt::sc_lv< W >, SC_MANY_WRITERS > base_type
Definition: sc_signal_rv.h:102
std::vector< value_type * > m_val_vec
Definition: sc_signal_rv.h:153
sc_dt::sc_lv< W > value_type
Definition: sc_signal_rv.h:103
virtual const char * kind() const
Definition: sc_signal_rv.h:137
virtual void write(const value_type &)
Definition: sc_signal_rv.h:182
virtual void update()
Definition: sc_signal_rv.h:215
int length() const
Definition: sc_lv_base.h:203