dde_helpers.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * dde_helpers.hpp -- Helper primitives in the DDE MoC *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: Providing helper primitives for modeling in the DDE MoC*
7  * *
8  * Usage: This file is included automatically *
9  * *
10  * License: BSD3 *
11  *******************************************************************/
12 
13 #ifndef DDE_HELPERS_HPP
14 #define DDE_HELPERS_HPP
15 
23 #include <functional>
24 #include <tuple>
25 
26 #include "tt_event.hpp"
28 
29 namespace ForSyDe
30 {
31 
32 namespace DDE
33 {
34 
35 using namespace sc_core;
36 
38 
44 template <class T0, template <class> class OIf,
45  class T1, template <class> class I1If>
46 inline comb<T0,T1>* make_comb(std::string pName,
47  typename comb<T0,T1>::functype _func,
48  OIf<T0>& outS,
49  I1If<T1>& inp1S
50  )
51 {
52  auto p = new comb<T0,T1>(pName.c_str(), _func);
53 
54  (*p).iport1(inp1S);
55  (*p).oport1(outS);
56 
57  return p;
58 }
59 
61 
67 template <class T0, template <class> class OIf,
68  class T1, template <class> class I1If,
69  class T2, template <class> class I2If>
70 inline comb2<T0,T1,T2>* make_comb2(std::string pName,
71  typename comb2<T0,T1,T2>::functype _func,
72  OIf<T0>& outS,
73  I1If<T1>& inp1S,
74  I2If<T2>& inp2S
75  )
76 {
77  auto p = new comb2<T0,T1,T2>(pName.c_str(), _func);
78 
79  (*p).iport1(inp1S);
80  (*p).iport2(inp2S);
81  (*p).oport1(outS);
82 
83  return p;
84 }
85 
87 
93 template <typename T, template <class> class IIf,
94  template <class> class OIf>
95 inline delay<T>* make_delay(std::string pName,
96  abst_ext<T> initval,
97  sc_time delay_time,
98  OIf<T>& outS,
99  IIf<T>& inpS
100  )
101 {
102  auto p = new delay<T>(pName.c_str(), initval, delay_time);
103 
104  (*p).iport1(inpS);
105  (*p).oport1(outS);
106 
107  return p;
108 }
109 
116 template <typename IT, typename ST, typename OT,
117  template <class> class IIf,
118  template <class> class OIf>
119 inline mealy<IT,ST,OT>* make_mealy(const std::string& pName,
120  const typename mealy<IT,ST,OT>::ns_functype& _ns_func,
121  const typename mealy<IT,ST,OT>::od_functype& _od_func,
122  const ST& init_st,
123  const sc_time& delay_time,
124  OIf<OT>& outS,
125  IIf<IT>& inpS
126  )
127 {
128  auto p = new mealy<IT,ST,OT>(pName.c_str(), _ns_func, _od_func, init_st, delay_time);
129 
130  (*p).iport1(inpS);
131  (*p).oport1(outS);
132 
133  return p;
134 }
135 
142 template <typename IT1, typename IT2, typename ST, typename OT,
143  template <class> class IIf1, template <class> class IIf2,
144  template <class> class OIf>
145 inline mealy2<IT1,IT2,ST,OT>* make_mealy2(const std::string& pName,
146  const typename mealy2<IT1,IT2,ST,OT>::ns_functype& _ns_func,
147  const typename mealy2<IT1,IT2,ST,OT>::od_functype& _od_func,
148  const ST& init_st,
149  const sc_time& delay_time,
150  OIf<OT>& outS,
151  IIf1<IT1>& inpS1,
152  IIf2<IT2>& inpS2
153  )
154 {
155  auto p = new mealy2<IT1,IT2,ST,OT>(pName.c_str(), _ns_func, _od_func, init_st, delay_time);
156 
157  (*p).iport1(inpS1);
158  (*p).iport2(inpS2);
159  (*p).oport1(outS);
160 
161  return p;
162 }
163 
165 
171 template <class T, template <class> class OIf>
172 inline source<T>* make_source(std::string pName,
173  typename source<T>::functype _func,
174  ttn_event<T> initval,
175  unsigned long long take,
176  OIf<T>& outS
177  )
178 {
179  auto p = new source<T>(pName.c_str(), _func, initval, take);
180 
181  (*p).oport1(outS);
182 
183  return p;
184 }
185 
187 
193 template <class T, template <class> class OIf>
194 inline vsource<T>* make_vsource(std::string pName,
195  const std::vector<T>& values,
196  const std::vector<sc_time>& offsets,
197  OIf<T>& outS
198  )
199 {
200  auto p = new vsource<T>(pName.c_str(), values, offsets);
201 
202  (*p).oport1(outS);
203 
204  return p;
205 }
206 
208 
214 template <class T, template <class> class IIf>
215 inline sink<T>* make_sink(std::string pName,
216  typename sink<T>::functype _func,
217  IIf<T>& inS
218  )
219 {
220  auto p = new sink<T>(pName.c_str(), _func);
221 
222  (*p).iport1(inS);
223 
224  return p;
225 }
226 
228 
234 template <class T1, template <class> class I1If,
235  class T2, template <class> class I2If,
236  template <class> class OIf>
237 inline zip<T1,T2>* make_zip(std::string pName,
238  OIf< std::tuple<abst_ext<T1>,abst_ext<T2>> >& outS,
239  I1If<T1>& inp1S,
240  I2If<T2>& inp2S
241  )
242 {
243  auto p = new zip<T1,T2>(pName.c_str());
244 
245  (*p).iport1(inp1S);
246  (*p).iport2(inp2S);
247  (*p).oport1(outS);
248 
249  return p;
250 }
251 
253 
260 template <class T1, std::size_t N,
261  template <class> class OIf>
262 inline zipX<T1,N>* make_zipX(std::string pName,
263  OIf< std::array<abst_ext<T1>,N> >& outS
264  )
265 {
266  auto p = new zipX<T1,N>(pName.c_str());
267 
268  (*p).oport1(outS);
269 
270  return p;
271 }
272 
274 
280 template <template <class> class IIf,
281  class T1, template <class> class O1If,
282  class T2, template <class> class O2If>
283 inline unzip<T1,T2>* make_unzip(std::string pName,
284  IIf< std::tuple<abst_ext<T1>,abst_ext<T2>> >& inpS,
285  O1If<T1>& out1S,
286  O2If<T2>& out2S
287  )
288 {
289  auto p = new unzip<T1,T2>(pName.c_str());
290 
291  (*p).iport1(inpS);
292  (*p).oport1(out1S);
293  (*p).oport2(out2S);
294 
295  return p;
296 }
297 
299 
306 template <template <class> class IIf,
307  class T1, std::size_t N>
308 inline unzipX<T1,N>* make_unzipX(const std::string& pName,
309  IIf<std::array<abst_ext<T1>,N>>& inpS
310  )
311 {
312  auto p = new unzipX<T1,N>(pName.c_str());
313 
314  (*p).iport1(inpS);
315 
316  return p;
317 }
318 
320 
326 template <typename T, template <class> class IIf,
327  template <class> class OIf>
328 inline fanout<T>* make_fanout(std::string pName,
329  OIf<T>& outS,
330  IIf<T>& inpS
331  )
332 {
333  auto p = new fanout<T>(pName.c_str());
334 
335  (*p).iport1(inpS);
336  (*p).oport1(outS);
337 
338  return p;
339 }
340 
341 
342 }
343 }
344 
345 #endif
std::function< void(ST &, const ST &, const ttn_event< IT > &)> ns_functype
Type of the next-state function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:355
Process constructor for a combinational process with two inputs and one output.
Definition: dde_process_constructors.hpp:135
source< T > * make_source(std::string pName, typename source< T >::functype _func, ttn_event< T > initval, unsigned long long take, OIf< T > &outS)
Helper function to construct a source process.
Definition: dde_helpers.hpp:172
Time-tagged data types.
Definition: tt_event.hpp:32
DDE_in< IT1 > iport1
port for the input channel
Definition: dde_process_constructors.hpp:460
Process constructor for a delay element.
Definition: dde_process_constructors.hpp:264
std::function< void(ttn_event< T > &, const ttn_event< T > &)> functype
Type of the function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:1112
std::function< void(abst_ext< OT > &, const ST &, const ttn_event< IT1 > &, const ttn_event< IT2 > &)> od_functype
Type of the output-decoding function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:468
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
zip< T1, T2 > * make_zip(std::string pName, OIf< std::tuple< abst_ext< T1 >, abst_ext< T2 >> > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S)
Helper function to construct a zip process.
Definition: dde_helpers.hpp:237
DDE_in< std::array< abst_ext< T1 >, N > > iport1
port for the input channel
Definition: dde_process_constructors.hpp:1640
mealy< IT, ST, OT > * make_mealy(const std::string &pName, const typename mealy< IT, ST, OT >::ns_functype &_ns_func, const typename mealy< IT, ST, OT >::od_functype &_od_func, const ST &init_st, const sc_time &delay_time, OIf< OT > &outS, IIf< IT > &inpS)
Definition: dde_helpers.hpp:119
Implements the basic process constructors in the DDE MoC.
The zip process with two inputs and one output.
Definition: dde_process_constructors.hpp:1345
DDE_in< std::tuple< abst_ext< T1 >, abst_ext< T2 > > > iport1
port for the input channel
Definition: dde_process_constructors.hpp:1557
vsource< T > * make_vsource(std::string pName, const std::vector< T > &values, const std::vector< sc_time > &offsets, OIf< T > &outS)
Helper function to construct a vsource process.
Definition: dde_helpers.hpp:194
DDE_in< T > iport1
port for the input channel
Definition: dde_process_constructors.hpp:1279
unzip< T1, T2 > * make_unzip(std::string pName, IIf< std::tuple< abst_ext< T1 >, abst_ext< T2 >> > &inpS, O1If< T1 > &out1S, O2If< T2 > &out2S)
Helper function to construct an unzip process.
Definition: dde_helpers.hpp:283
comb2< T0, T1, T2 > * make_comb2(std::string pName, typename comb2< T0, T1, T2 >::functype _func, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S)
Helper function to construct a comb2 process.
Definition: dde_helpers.hpp:70
std::function< void(abst_ext< T0 > &, const abst_ext< T1 > &, const abst_ext< T2 > &)> functype
Type of the function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:143
The unzipX process with a vector of outputs and one input.
Definition: dde_process_constructors.hpp:1637
The zipX process with a vector of inputs and one output.
Definition: dde_process_constructors.hpp:1460
DDE_out< T > oport1
port for the output channel
Definition: dde_process_constructors.hpp:1204
The unzip process with one input and two outputs.
Definition: dde_process_constructors.hpp:1554
unzipX< T1, N > * make_unzipX(const std::string &pName, IIf< std::array< abst_ext< T1 >, N >> &inpS)
Helper function to construct an unzipX process.
Definition: dde_helpers.hpp:308
std::function< void(const ttn_event< T > &)> functype
Type of the function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:1282
DDE_in< T > iport1
port for the input channel
Definition: dde_process_constructors.hpp:267
std::function< void(ST &, const ST &, const ttn_event< IT1 > &, const ttn_event< IT2 > &)> ns_functype
Type of the next-state function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:465
DDE_in< T1 > iport1
port for the input channel 1
Definition: dde_process_constructors.hpp:1348
DDE_in< T > iport1
port for the input channel
Definition: dde_process_constructors.hpp:1728
Process constructor for a source process.
Definition: dde_process_constructors.hpp:1106
Absent-extended data types.
Definition: abst_ext.hpp:32
Process constructor for a Mealy machine with two inputs.
Definition: dde_process_constructors.hpp:457
Process constructor for a sink process.
Definition: dde_process_constructors.hpp:1276
Process constructor for a source process with vector input.
Definition: dde_process_constructors.hpp:1201
std::function< void(abst_ext< T0 > &, const T1 &)> functype
Type of the function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:56
sink< T > * make_sink(std::string pName, typename sink< T >::functype _func, IIf< T > &inS)
Helper function to construct a sink process.
Definition: dde_helpers.hpp:215
std::function< void(abst_ext< OT > &, const ST &, const ttn_event< IT > &)> od_functype
Type of the output-decoding function to be passed to the process constructor.
Definition: dde_process_constructors.hpp:358
DDE_out< T > oport1
port for the output channel
Definition: dde_process_constructors.hpp:1109
delay< T > * make_delay(std::string pName, abst_ext< T > initval, sc_time delay_time, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a delay process.
Definition: dde_helpers.hpp:95
Process constructor for a fan-out process with one input and one output.
Definition: dde_process_constructors.hpp:1725
comb< T0, T1 > * make_comb(std::string pName, typename comb< T0, T1 >::functype _func, OIf< T0 > &outS, I1If< T1 > &inp1S)
Helper function to construct a comb process.
Definition: dde_helpers.hpp:46
Implements the time-tagged events.
fanout< T > * make_fanout(std::string pName, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a fanout process.
Definition: dde_helpers.hpp:328
Process constructor for a Mealy machine.
Definition: dde_process_constructors.hpp:348
DDE_out< std::array< abst_ext< T1 >, N > > oport1
port for the output channel
Definition: dde_process_constructors.hpp:1464
zipX< T1, N > * make_zipX(std::string pName, OIf< std::array< abst_ext< T1 >, N > > &outS)
Helper function to construct a zipX process.
Definition: dde_helpers.hpp:262
DDE_in< T1 > iport1
port for the input channel 1
Definition: dde_process_constructors.hpp:138
mealy2< IT1, IT2, ST, OT > * make_mealy2(const std::string &pName, const typename mealy2< IT1, IT2, ST, OT >::ns_functype &_ns_func, const typename mealy2< IT1, IT2, ST, OT >::od_functype &_od_func, const ST &init_st, const sc_time &delay_time, OIf< OT > &outS, IIf1< IT1 > &inpS1, IIf2< IT2 > &inpS2)
Definition: dde_helpers.hpp:145
DDE_in< IT > iport1
port for the input channel
Definition: dde_process_constructors.hpp:351
DDE_in< T1 > iport1
port for the input channel
Definition: dde_process_constructors.hpp:52
Process constructor for a combinational process with one input and one output.
Definition: dde_process_constructors.hpp:49