abssemantics.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * abssemantics.hpp -- The common abstract semantics for all MoCs *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: The common base for mapping supported MoCs on top of *
7  * the SystemC simulation kernel. *
8  * *
9  * Usage: This file is included automatically *
10  * *
11  * License: BSD3 *
12  *******************************************************************/
13 
14 #ifndef ABSSEMANTICS_HPP
15 #define ABSSEMANTICS_HPP
16 
26 
30 namespace ForSyDe
31 {
32 
33 using namespace sc_core;
34 
35 // Auxilliary Macro definitions
36 #define WRITE_MULTIPORT(PORT,VAL) \
37  for (int WMPi=0;WMPi<PORT.size();WMPi++) PORT[WMPi]->write(VAL);
38 
39 #define WRITE_VEC_MULTIPORT(PORT,VEC) \
40  for (int WMPi=0;WMPi<PORT.size();WMPi++) \
41  for (auto WMPit=VEC.begin();WMPit!=VEC.end();WMPit++) \
42  PORT[WMPi]->write(*WMPit);
43 
45 enum bound_type {PORT, CHANNEL};
46 
49 {
50 public:
52  virtual const char* token_type() const = 0;
53 
54  // TODO: remove if proved not to be needed
55  //~ //! Size of the tokens in the channels
56  //~ virtual unsigned token_size() const = 0;
57 
59  virtual std::string moc() const = 0;
60 
62  sc_object* iport;
63 
65  sc_object* oport;
66 };
67 
69 template <typename T, typename TokenType>
70 class signal: public sc_fifo<TokenType>
71 #ifdef FORSYDE_INTROSPECTION
73 #endif
74 {
75 public:
76  signal() : sc_fifo<TokenType>() {}
77  signal(sc_module_name name, unsigned size) : sc_fifo<TokenType>(name, size) {}
78 #ifdef FORSYDE_INTROSPECTION
79  typedef T type;
80 
81  // TODO: remove if proved not to be needed
82  //~ //! Returns only the size of the token type
83  //~ virtual unsigned token_size() const
84  //~ {
85  //~ return sizeof(T);
86  //~ }
87 
88  // TODO: remove if proved not to be needed
90  virtual const char* token_type() const
91  {
92  return get_type_name<T>();
93  }
94 
95  virtual std::string moc() const = 0;
96 #endif
97 };
98 
100 struct PortInfo
101 {
102  sc_object* port;
103  // TODO: remove if proved not to be needed
104  //~ unsigned toks;
105  std::string portType;
106 };
107 
110 {
111 public:
113  sc_object* bound_port;
114 
116  virtual const char* token_type() const = 0;
117 };
118 
120 template <typename T, typename TokenType, typename ChanType>
121 class in_port: public sc_fifo_in<TokenType>
122 #ifdef FORSYDE_INTROSPECTION
124 #endif
125 {
126 public:
127  in_port() : sc_fifo_in<TokenType>(){}
128  in_port(const char* name) : sc_fifo_in<TokenType>(name){}
129 #ifdef FORSYDE_INTROSPECTION
130  typedef T type;
131 
132  // NOTE: The following member functions could be overriden easier if
133  // bind() was declared virtual in the sc_port base classes.
134  // This will happen in SystemC 2.3, so adapt these accordingly.
136  void operator()(sc_fifo_in_if<TokenType>& i)
137  {
138  sc_fifo_in<TokenType>::operator()(i);
139  static_cast<ChanType&>(i).iport = this;
140  }
141 
143  void operator()(in_port<T,TokenType,ChanType>& p)
144  {
145  sc_fifo_in<TokenType>::operator()(p);
146  p.bound_port = this;
147  }
148 
150  virtual const char* token_type() const
151  {
152  return get_type_name<T>();
153  }
154 #endif
155 };
156 
158 template <typename T, typename TokenType, typename ChanType>
159 class out_port: public sc_fifo_out<TokenType>
160 #ifdef FORSYDE_INTROSPECTION
162 #endif
163 {
164 public:
165  out_port() : sc_fifo_out<TokenType>(){}
166  out_port(const char* name) : sc_fifo_out<TokenType>(name){}
167 #ifdef FORSYDE_INTROSPECTION
168  typedef T type;
169 
170  // NOTE: The following member functions could be overriden easier if
171  // bind() was declared virtual in the sc_port base classes.
172  // This will happen in SystemC 2.3, so adapt these accordingly.
174  void operator()(sc_fifo_out_if<TokenType>& i)
175  {
176  sc_fifo_out<TokenType>::operator()(i);
177  // Register the port-to-port binding
178  static_cast<ChanType&>(i).oport = this;
179  }
180 
182  void operator()(out_port<T,TokenType,ChanType>& p)
183  {
184  sc_fifo_out<TokenType>::operator()(p);
185  // Register the port-to-port binding
186  p.bound_port = this;
187  }
188 
190  virtual const char* token_type() const
191  {
192  return get_type_name<T>();
193  }
194 #endif
195 };
196 
198 
212 class process : public sc_module
213 {
214 private:
216  SC_HAS_PROCESS(process);
217 
219  void worker()
220  {
221  // We run the init stage here and not in the constructor to
222  // force running it after the elaboration phase.
223  init();
224  while (1)
225  {
226  prep(); // The preparaion stage
227  exec(); // The execution stage
228  prod(); // The production stage
229  }
230  }
231 
232 protected:
234 
237  virtual void init() = 0;
238 
240 
243  virtual void prep() = 0;
244 
246 
250  virtual void exec() = 0;
251 
253 
256  virtual void prod() = 0;
257 
259 
262  virtual void clean() = 0;
263 
266  {
267  clean();
268  }
269 
270 #ifdef FORSYDE_INTROSPECTION
271 
273  void end_of_elaboration()
274  {
275  bindInfo();
276  }
277 
279 
283  virtual void bindInfo() = 0;
284 #endif
285 
286 public:
287 
288 #ifdef FORSYDE_INTROSPECTION
289  std::vector<PortInfo> boundInChans;
292  std::vector<PortInfo> boundOutChans;
293 
295  std::vector<std::tuple<std::string,std::string>> arg_vec;
296 #endif
297 
299 
302  process(sc_module_name _name
303  ): sc_module(_name)
304  {
305  SC_THREAD(worker);
306  }
307 
309  virtual std::string forsyde_kind() const = 0;
310 
311 };
312 
313 }
314 
315 #endif
bound_type
Type of the object bound to a port.
Definition: abssemantics.hpp:45
void end_of_simulation()
This hook is used to run the clean stage.
Definition: abssemantics.hpp:265
sc_object * iport
Input port to which a channel is bound.
Definition: abssemantics.hpp:62
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
A helper class used to provide introspective channels.
Definition: abssemantics.hpp:48
CT_in in_port
The CT::in_port is an alias for CT::CT_in.
Definition: ct_process.hpp:61
The in_port port is used for input ports of ForSyDe processes.
Definition: abssemantics.hpp:121
CT2CT signal
The CT::signal is an alias for CT::CT2CT.
Definition: ct_process.hpp:50
The UT_out port is used for output ports of UT processes.
Definition: abssemantics.hpp:159
sc_object * oport
Output port to which a channel is bound.
Definition: abssemantics.hpp:65
sc_object * bound_port
To which port it is bound (used for binding ports of composite processes in the hierarchy) ...
Definition: abssemantics.hpp:113
The process constructor which defines the abstract semantics of execution.
Definition: abssemantics.hpp:212
CT_out out_port
The CT::out_port is an alias for CT::CT_out.
Definition: ct_process.hpp:72
A helper class used to provide introspective ports.
Definition: abssemantics.hpp:109
This type is used in the process base class to store structural information.
Definition: abssemantics.hpp:100
process(sc_module_name _name)
The constructor requires the module name.
Definition: abssemantics.hpp:302
A ForSyDe signal is used to inter-connect processes.
Definition: abssemantics.hpp:70