ut_helpers.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * ut_helpers.hpp -- Helper primitives in the UT MoC *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: Providing helper primitives for modeling in the UT MoC *
7  * *
8  * Usage: This file is included automatically *
9  * *
10  * License: BSD3 *
11  *******************************************************************/
12 
13 #ifndef UT_HELPERS_HPP
14 #define UT_HELPERS_HPP
15 
23 #include <functional>
24 #include <tuple>
25 
27 
28 namespace ForSyDe
29 {
30 
31 namespace UT
32 {
33 
34 using namespace sc_core;
35 
37 
43 template <class T0, template <class> class OIf,
44  class T1, template <class> class I1If>
45 inline comb<T0,T1>* make_comb(const std::string& pName,
46  const typename comb<T0,T1>::functype& _func,
47  const unsigned int& i1toks,
48  OIf<T0>& outS,
49  I1If<T1>& inp1S
50  )
51 {
52  auto p = new comb<T0,T1>(pName.c_str(), _func, i1toks);
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(const std::string pName,
71  const typename comb2<T0,T1,T2>::functype& _func,
72  const unsigned int& i1toks,
73  const unsigned int& i2toks,
74  OIf<T0>& outS,
75  I1If<T1>& inp1S,
76  I2If<T2>& inp2S
77  )
78 {
79  auto p = new comb2<T0,T1,T2>(pName.c_str(), _func,
80  i1toks, i2toks);
81 
82  (*p).iport1(inp1S);
83  (*p).iport2(inp2S);
84  (*p).oport1(outS);
85 
86  return p;
87 }
88 
90 
96 template <class T0, template <class> class OIf,
97  class T1, template <class> class I1If,
98  class T2, template <class> class I2If,
99  class T3, template <class> class I3If>
100 inline comb3<T0,T1,T2,T3>* make_comb3(const std::string& pName,
101  const typename comb3<T0,T1,T2,T3>::functype& _func,
102  const unsigned int& i1toks,
103  const unsigned int& i2toks,
104  const unsigned int& i3toks,
105  OIf<T0>& outS,
106  I1If<T1>& inp1S,
107  I2If<T2>& inp2S,
108  I3If<T3>& inp3S
109  )
110 {
111  auto p = new comb3<T0,T1,T2,T3>(pName.c_str(), _func,
112  i1toks, i2toks, i3toks);
113 
114  (*p).iport1(inp1S);
115  (*p).iport2(inp2S);
116  (*p).iport3(inp3S);
117  (*p).oport1(outS);
118 
119  return p;
120 }
121 
123 
129 template <class T0, template <class> class OIf,
130  class T1, template <class> class I1If,
131  class T2, template <class> class I2If,
132  class T3, template <class> class I3If,
133  class T4, template <class> class I4If>
134 inline comb4<T0,T1,T2,T3,T4>* make_comb4(const std::string& pName,
135  const typename comb4<T0,T1,T2,T3,T4>::functype& _func,
136  const unsigned int& i1toks,
137  const unsigned int& i2toks,
138  const unsigned int& i3toks,
139  const unsigned int& i4toks,
140  OIf<T0>& outS,
141  I1If<T1>& inp1S,
142  I2If<T2>& inp2S,
143  I3If<T3>& inp3S,
144  I4If<T4>& inp4S
145  )
146 {
147  auto p = new comb4<T0,T1,T2,T3,T4>(pName.c_str(), _func,
148  i1toks, i2toks, i3toks, i4toks);
149 
150  (*p).iport1(inp1S);
151  (*p).iport2(inp2S);
152  (*p).iport3(inp3S);
153  (*p).iport4(inp4S);
154  (*p).oport1(outS);
155 
156  return p;
157 }
158 
160 
166 template <typename T, template <class> class IIf,
167  template <class> class OIf>
168 inline delay<T>* make_delay(const std::string& pName,
169  const T& initval,
170  OIf<T>& outS,
171  IIf<T>& inpS
172  )
173 {
174  auto p = new delay<T>(pName.c_str(), initval);
175 
176  (*p).iport1(inpS);
177  (*p).oport1(outS);
178 
179  return p;
180 }
181 
183 
189 template <typename T, template <class> class IIf,
190  template <class> class OIf>
191 inline delayn<T>* make_delayn(const std::string& pName,
192  const T& initval,
193  const unsigned int& n,
194  OIf<T>& outS,
195  IIf<T>& inpS
196  )
197 {
198  auto p = new delayn<T>(pName.c_str(), initval, n);
199 
200  (*p).iport1(inpS);
201  (*p).oport1(outS);
202 
203  return p;
204 }
205 
207 
213 template <typename IT, typename ST,
214  template <class> class IIf,
215  template <class> class OIf>
216 inline scan<IT,ST>* make_scan(const std::string& pName,
217  const typename scan<IT,ST>::gamma_functype& _gamma_func,
218  const typename scan<IT,ST>::ns_functype& _ns_func,
219  const ST& init_st,
220  OIf<ST>& outS,
221  IIf<IT>& inpS
222  )
223 {
224  auto p = new scan<IT,ST>(pName.c_str(), _gamma_func, _ns_func, init_st);
225 
226  (*p).iport1(inpS);
227  (*p).oport1(outS);
228 
229  return p;
230 }
231 
233 
239 template <typename IT, typename ST,
240  template <class> class IIf,
241  template <class> class OIf>
242 inline scand<IT,ST>* make_scand(const std::string& pName,
243  const typename scan<IT,ST>::gamma_functype& _gamma_func,
244  const typename scan<IT,ST>::ns_functype& _ns_func,
245  const ST& init_st,
246  OIf<ST>& outS,
247  IIf<IT>& inpS
248  )
249 {
250  auto p = new scand<IT,ST>(pName.c_str(), _gamma_func, _ns_func, init_st);
251 
252  (*p).iport1(inpS);
253  (*p).oport1(outS);
254 
255  return p;
256 }
257 
259 
265 template <typename IT, typename ST, typename OT,
266  template <class> class IIf,
267  template <class> class OIf>
268 inline moore<IT,ST,OT>* make_moore(const std::string& pName,
269  const typename moore<IT,ST,OT>::gamma_functype& _gamma_func,
270  const typename moore<IT,ST,OT>::ns_functype& _ns_func,
271  const typename moore<IT,ST,OT>::od_functype& _od_func,
272  const ST& init_st,
273  OIf<OT>& outS,
274  IIf<IT>& inpS
275  )
276 {
277  auto p = new moore<IT,ST,OT>(pName.c_str(), _gamma_func, _ns_func, _od_func, init_st);
278 
279  (*p).iport1(inpS);
280  (*p).oport1(outS);
281 
282  return p;
283 }
284 
286 
292 template <typename IT, typename ST, typename OT,
293  template <class> class IIf,
294  template <class> class OIf>
295 inline mealy<IT,ST,OT>* make_mealy(const std::string& pName,
296  const typename moore<IT,ST,OT>::gamma_functype& _gamma_func,
297  const typename mealy<IT,ST,OT>::ns_functype& _ns_func,
298  const typename mealy<IT,ST,OT>::od_functype& _od_func,
299  const ST& init_st,
300  OIf<OT>& outS,
301  IIf<IT>& inpS
302  )
303 {
304  auto p = new mealy<IT,ST,OT>(pName.c_str(), _gamma_func, _ns_func, _od_func, init_st);
305 
306  (*p).iport1(inpS);
307  (*p).oport1(outS);
308 
309  return p;
310 }
311 
313 
319 template <class T, template <class> class OIf>
320 inline constant<T>* make_constant(const std::string& pName,
321  const T& initval,
322  const unsigned long long& take,
323  OIf<T>& outS
324  )
325 {
326  auto p = new constant<T>(pName.c_str(), initval, take);
327 
328  (*p).oport1(outS);
329 
330  return p;
331 }
332 
334 
340 template <class T, template <class> class OIf>
341 inline source<T>* make_source(const std::string& pName,
342  const typename source<T>::functype& _func,
343  const T& initval,
344  const unsigned long long& take,
345  OIf<T>& outS
346  )
347 {
348  auto p = new source<T>(pName.c_str(), _func, initval, take);
349 
350  (*p).oport1(outS);
351 
352  return p;
353 }
354 
356 
362 template <class T, template <class> class OIf>
363 inline vsource<T>* make_vsource(const std::string& pName,
364  const std::vector<T>& in_vec,
365  OIf<T>& outS
366  )
367 {
368  auto p = new vsource<T>(pName.c_str(), in_vec);
369 
370  (*p).oport1(outS);
371 
372  return p;
373 }
374 
376 
382 template <class T, template <class> class IIf>
383 inline sink<T>* make_sink(const std::string& pName,
384  const typename sink<T>::functype& _func,
385  IIf<T>& inS
386  )
387 {
388  auto p = new sink<T>(pName.c_str(), _func);
389 
390  (*p).iport1(inS);
391 
392  return p;
393 }
394 
396 
402 template <class T1, template <class> class I1If,
403  class T2, template <class> class I2If,
404  template <class> class OIf>
405 inline zip<T1,T2>* make_zip(const std::string& pName,
406  const unsigned int& i1toks,
407  const unsigned int& i2toks,
408  OIf<std::tuple<std::vector<T1>,std::vector<T2>>>& outS,
409  I1If<T1>& inp1S,
410  I2If<T2>& inp2S
411  )
412 {
413  auto p = new zip<T1,T2>(pName.c_str(), i1toks, i2toks);
414 
415  (*p).iport1(inp1S);
416  (*p).iport2(inp2S);
417  (*p).oport1(outS);
418 
419  return p;
420 }
421 
423 
429 template <template <class> class IIf,
430  class T1, template <class> class O1If,
431  class T2, template <class> class O2If>
432 inline unzip<T1,T2>* make_unzip(const std::string& pName,
433  IIf<std::tuple<std::vector<T1>,std::vector<T2>>>& inpS,
434  O1If<T1>& out1S,
435  O2If<T2>& out2S
436  )
437 {
438  auto p = new unzip<T1,T2>(pName.c_str());
439 
440  (*p).iport1(inpS);
441  (*p).oport1(out1S);
442  (*p).oport2(out2S);
443 
444  return p;
445 }
446 
448 
454 //~ template <template <class> class IIf,
455  //~ typename T1, template <typename> typename OIf,
456  //~ typename... Ts>
457 //~ inline unzipN<T...>* make_unzipN(const std::string& pName,
458  //~ IIf<std::tuple<abst_ext<Ts>...>>& inpS,
459  //~ OIf<T1>& outS,
460  //~ OIfs<Ts>&... outsS
461  //~ )
462 //~ {
463  //~ make_unzipN(pName, inpS, outsS...);
464  //~ std:get???????????(*p).iport1(inpS);
465  //~
466  //~ return p;
467 //~ }
468  //~ auto p = new unzip<T1,T2>(pName.c_str());
469  //~
470  //~ (*p).iport1(inpS);
471  //~ (*p).oport1(out1S);
472  //~ (*p).oport2(out2S);
473  //~
474  //~ return p;
475 //~ }
476 
478 
484 template <typename T, template <class> class IIf,
485  template <class> class OIf>
486 inline fanout<T>* make_fanout(const std::string& pName,
487  OIf<T>& outS,
488  IIf<T>& inpS
489  )
490 {
491  auto p = new fanout<T>(pName.c_str());
492 
493  (*p).iport1(inpS);
494  (*p).oport1(outS);
495 
496  return p;
497 }
498 
499 
500 }
501 }
502 
503 #endif
UT_in< T > iport1
port for the input channel
Definition: ut_process_constructors.hpp:521
UT_in< T1 > iport1
port for the input channel
Definition: ut_process_constructors.hpp:48
UT_in< T1 > iport1
port for the input channel 1
Definition: ut_process_constructors.hpp:1319
scand< IT, ST > * make_scand(const std::string &pName, const typename scan< IT, ST >::gamma_functype &_gamma_func, const typename scan< IT, ST >::ns_functype &_ns_func, const ST &init_st, OIf< ST > &outS, IIf< IT > &inpS)
Helper function to construct a scand-based process.
Definition: ut_helpers.hpp:242
UT_in< IT > iport1
port for the input channel
Definition: ut_process_constructors.hpp:817
UT_in< T > iport1
port for the input channel
Definition: ut_process_constructors.hpp:1694
The zip process with two inputs and one output.
Definition: ut_process_constructors.hpp:1316
comb3< T0, T1, T2, T3 > * make_comb3(const std::string &pName, const typename comb3< T0, T1, T2, T3 >::functype &_func, const unsigned int &i1toks, const unsigned int &i2toks, const unsigned int &i3toks, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S, I3If< T3 > &inp3S)
Helper function to construct a comb3 process.
Definition: ut_helpers.hpp:100
UT_in< IT > iport1
port for the input channel
Definition: ut_process_constructors.hpp:600
std::function< void(std::vector< T0 > &, const std::vector< T1 > &)> functype
Type of the function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:54
UT_in< std::tuple< std::vector< T1 >, std::vector< T2 > > > iport1
port for the input channel
Definition: ut_process_constructors.hpp:1512
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
Process constructor for a Mealy machine.
Definition: ut_process_constructors.hpp:940
moore< IT, ST, OT > * make_moore(const std::string &pName, const typename moore< IT, ST, OT >::gamma_functype &_gamma_func, const typename moore< IT, ST, OT >::ns_functype &_ns_func, const typename moore< IT, ST, OT >::od_functype &_od_func, const ST &init_st, OIf< OT > &outS, IIf< IT > &inpS)
Helper function to construct a moore process.
Definition: ut_helpers.hpp:268
source< T > * make_source(const std::string &pName, const typename source< T >::functype &_func, const T &initval, const unsigned long long &take, OIf< T > &outS)
Helper function to construct a source process.
Definition: ut_helpers.hpp:341
std::function< void(unsigned int &, const ST &)> gamma_functype
Type of the partitioning function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:821
std::function< void(std::vector< T0 > &, const std::vector< T1 > &, const std::vector< T2 > &)> functype
Type of the function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:140
Process constructor for a fan-out process with one input and one output.
Definition: ut_process_constructors.hpp:1691
UT_in< T > iport1
port for the input channel
Definition: ut_process_constructors.hpp:445
std::function< void(std::vector< OT > &, const ST &)> od_functype
Type of the output-decoding function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:827
UT_in< T1 > iport1
port for the input channel 1
Definition: ut_process_constructors.hpp:132
UT_in< IT > iport1
port for the input channel
Definition: ut_process_constructors.hpp:943
Implements the basic process constructors in the UT MoC.
Process constructor for a Moore machine.
Definition: ut_process_constructors.hpp:814
std::function< void(std::vector< T0 > &, const std::vector< T1 > &, const std::vector< T2 > &, const std::vector< T3 > &)> functype
Type of the function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:234
constant< T > * make_constant(const std::string &pName, const T &initval, const unsigned long long &take, OIf< T > &outS)
Helper function to construct a constant source process.
Definition: ut_helpers.hpp:320
The unzip process with one input and two outputs.
Definition: ut_process_constructors.hpp:1509
Process constructor for a combinational process with two inputs and one output.
Definition: ut_process_constructors.hpp:323
UT_in< T1 > iport1
port for the input channel 1
Definition: ut_process_constructors.hpp:224
comb< T0, T1 > * make_comb(const std::string &pName, const typename comb< T0, T1 >::functype &_func, const unsigned int &i1toks, OIf< T0 > &outS, I1If< T1 > &inp1S)
Helper function to construct a comb process.
Definition: ut_helpers.hpp:45
mealy< IT, ST, OT > * make_mealy(const std::string &pName, const typename moore< IT, ST, OT >::gamma_functype &_gamma_func, const typename mealy< IT, ST, OT >::ns_functype &_ns_func, const typename mealy< IT, ST, OT >::od_functype &_od_func, const ST &init_st, OIf< OT > &outS, IIf< IT > &inpS)
Helper function to construct a mealy process.
Definition: ut_helpers.hpp:295
Process constructor for a sink process.
Definition: ut_process_constructors.hpp:1247
std::function< void(const T &)> functype
Type of the function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:1253
fanout< T > * make_fanout(const std::string &pName, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct an unzipN process.
Definition: ut_helpers.hpp:486
UT_in< IT > iport1
port for the input channel
Definition: ut_process_constructors.hpp:701
Process constructor for a combinational process with two inputs and one output.
Definition: ut_process_constructors.hpp:221
std::function< void(std::vector< T0 > &, const std::vector< T1 > &, const std::vector< T2 > &, const std::vector< T3 > &, const std::vector< T4 > &)> functype
Type of the function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:338
zip< T1, T2 > * make_zip(const std::string &pName, const unsigned int &i1toks, const unsigned int &i2toks, OIf< std::tuple< std::vector< T1 >, std::vector< T2 >>> &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S)
Helper function to construct a zip process.
Definition: ut_helpers.hpp:405
std::function< void(std::vector< OT > &, const ST &, const std::vector< IT > &)> od_functype
Type of the output-decoding function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:954
Process constructor for a source process with vector input.
Definition: ut_process_constructors.hpp:1209
delay< T > * make_delay(const std::string &pName, const T &initval, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a delay process.
Definition: ut_helpers.hpp:168
UT_in< T1 > iport1
port for the input channel 1
Definition: ut_process_constructors.hpp:326
Process constructor for a scand process.
Definition: ut_process_constructors.hpp:698
vsource< T > * make_vsource(const std::string &pName, const std::vector< T > &in_vec, OIf< T > &outS)
Helper function to construct a vector source process.
Definition: ut_helpers.hpp:363
Process constructor for a combinational process with two inputs and one output.
Definition: ut_process_constructors.hpp:129
sc_fifo_out< OTYP > oport1
port for the output channel
Definition: ut_process_constructors.hpp:1212
delayn< T > * make_delayn(const std::string &pName, const T &initval, const unsigned int &n, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a delayn process.
Definition: ut_helpers.hpp:191
Process constructor for a constant source process.
Definition: ut_process_constructors.hpp:1051
std::function< void(ST &, const ST &, const std::vector< IT > &)> ns_functype
Type of the next-state function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:607
Process constructor for a n-delay element.
Definition: ut_process_constructors.hpp:518
Process constructor for a delay element.
Definition: ut_process_constructors.hpp:442
comb4< T0, T1, T2, T3, T4 > * make_comb4(const std::string &pName, const typename comb4< T0, T1, T2, T3, T4 >::functype &_func, const unsigned int &i1toks, const unsigned int &i2toks, const unsigned int &i3toks, const unsigned int &i4toks, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S, I3If< T3 > &inp3S, I4If< T4 > &inp4S)
Helper function to construct a comb4 process.
Definition: ut_helpers.hpp:134
Process constructor for a scan process.
Definition: ut_process_constructors.hpp:597
UT_in< T > iport1
port for the input channel
Definition: ut_process_constructors.hpp:1250
std::function< void(T &, const T &)> functype
Type of the function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:1127
Process constructor for a combinational process (actor) with one input and one output.
Definition: ut_process_constructors.hpp:45
std::function< void(unsigned int &, const ST &)> gamma_functype
Type of the partitioning function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:604
sink< T > * make_sink(const std::string &pName, const typename sink< T >::functype &_func, IIf< T > &inS)
Helper function to construct a sink process.
Definition: ut_helpers.hpp:383
UT_out< T > oport1
port for the output channel
Definition: ut_process_constructors.hpp:1124
std::function< void(ST &, const ST &, const std::vector< IT > &)> ns_functype
Type of the next-state function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:950
std::function< void(ST &, const ST &, const std::vector< IT > &)> ns_functype
Type of the next-state function to be passed to the process constructor.
Definition: ut_process_constructors.hpp:824
UT_out< T > oport1
port for the output channel
Definition: ut_process_constructors.hpp:1054
scan< IT, ST > * make_scan(const std::string &pName, const typename scan< IT, ST >::gamma_functype &_gamma_func, const typename scan< IT, ST >::ns_functype &_ns_func, const ST &init_st, OIf< ST > &outS, IIf< IT > &inpS)
Helper function to construct a scan-based process.
Definition: ut_helpers.hpp:216
unzip< T1, T2 > * make_unzip(const std::string &pName, IIf< std::tuple< std::vector< T1 >, std::vector< T2 >>> &inpS, O1If< T1 > &out1S, O2If< T2 > &out2S)
Helper function to construct an unzip process.
Definition: ut_helpers.hpp:432
comb2< T0, T1, T2 > * make_comb2(const std::string pName, const typename comb2< T0, T1, T2 >::functype &_func, const unsigned int &i1toks, const unsigned int &i2toks, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S)
Helper function to construct a comb2 process.
Definition: ut_helpers.hpp:70
Process constructor for a source process.
Definition: ut_process_constructors.hpp:1121