sdf_helpers.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * sdf_helpers.hpp -- Helper primitives in the SDF MoC *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: Providing helper primitives for modeling in the SDF MoC*
7  * *
8  * Usage: This file is included automatically *
9  * *
10  * License: BSD3 *
11  *******************************************************************/
12 
13 #ifndef SDF_HELPERS_HPP
14 #define SDF_HELPERS_HPP
15 
23 #include <functional>
24 #include <tuple>
25 
27 
28 namespace ForSyDe
29 {
30 
31 namespace SDF
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(std::string pName,
46  typename comb<T0,T1>::functype _func,
47  unsigned int o1toks,
48  unsigned int i1toks,
49  OIf<T0>& outS,
50  I1If<T1>& inp1S
51  )
52 {
53  auto p = new comb<T0,T1>(pName.c_str(), _func, o1toks, i1toks);
54 
55  (*p).iport1(inp1S);
56  (*p).oport1(outS);
57 
58  return p;
59 }
60 
62 
68 template <class T0, template <class> class OIf,
69  class T1, template <class> class I1If,
70  class T2, template <class> class I2If>
71 inline comb2<T0,T1,T2>* make_comb2(std::string pName,
72  typename comb2<T0,T1,T2>::functype _func,
73  unsigned int o1toks,
74  unsigned int i1toks,
75  unsigned int i2toks,
76  OIf<T0>& outS,
77  I1If<T1>& inp1S,
78  I2If<T2>& inp2S
79  )
80 {
81  auto p = new comb2<T0,T1,T2>(pName.c_str(), _func, o1toks,
82  i1toks, i2toks);
83 
84  (*p).iport1(inp1S);
85  (*p).iport2(inp2S);
86  (*p).oport1(outS);
87 
88  return p;
89 }
90 
92 
98 template <class T0, template <class> class OIf,
99  class T1, template <class> class I1If,
100  class T2, template <class> class I2If,
101  class T3, template <class> class I3If>
102 inline comb3<T0,T1,T2,T3>* make_comb3(std::string pName,
103  typename comb3<T0,T1,T2,T3>::functype _func,
104  unsigned int o1toks,
105  unsigned int i1toks,
106  unsigned int i2toks,
107  unsigned int i3toks,
108  OIf<T0>& outS,
109  I1If<T1>& inp1S,
110  I2If<T2>& inp2S,
111  I3If<T3>& inp3S
112  )
113 {
114  auto p = new comb3<T0,T1,T2,T3>(pName.c_str(), _func, o1toks,
115  i1toks, i2toks, i3toks);
116 
117  (*p).iport1(inp1S);
118  (*p).iport2(inp2S);
119  (*p).iport3(inp3S);
120  (*p).oport1(outS);
121 
122  return p;
123 }
124 
126 
132 template <class T0, template <class> class OIf,
133  class T1, template <class> class I1If,
134  class T2, template <class> class I2If,
135  class T3, template <class> class I3If,
136  class T4, template <class> class I4If>
137 inline comb4<T0,T1,T2,T3,T4>* make_comb4(std::string pName,
138  typename comb4<T0,T1,T2,T3,T4>::functype _func,
139  unsigned int o1toks,
140  unsigned int i1toks,
141  unsigned int i2toks,
142  unsigned int i3toks,
143  unsigned int i4toks,
144  OIf<T0>& outS,
145  I1If<T1>& inp1S,
146  I2If<T2>& inp2S,
147  I3If<T3>& inp3S,
148  I4If<T4>& inp4S
149  )
150 {
151  auto p = new comb4<T0,T1,T2,T3,T4>(pName.c_str(), _func, o1toks,
152  i1toks, i2toks, i3toks, i4toks);
153 
154  (*p).iport1(inp1S);
155  (*p).iport2(inp2S);
156  (*p).iport3(inp3S);
157  (*p).iport4(inp4S);
158  (*p).oport1(outS);
159 
160  return p;
161 }
162 
164 
170 template <typename T, template <class> class IIf,
171  template <class> class OIf>
172 inline delay<T>* make_delay(std::string pName,
173  T initval,
174  OIf<T>& outS,
175  IIf<T>& inpS
176  )
177 {
178  auto p = new delay<T>(pName.c_str(), initval);
179 
180  (*p).iport1(inpS);
181  (*p).oport1(outS);
182 
183  return p;
184 }
185 
187 
193 template <typename T, template <class> class IIf,
194  template <class> class OIf>
195 inline delayn<T>* make_delayn(std::string pName,
196  T initval,
197  unsigned int n,
198  OIf<T>& outS,
199  IIf<T>& inpS
200  )
201 {
202  auto p = new delayn<T>(pName.c_str(), initval, n);
203 
204  (*p).iport1(inpS);
205  (*p).oport1(outS);
206 
207  return p;
208 }
209 
211 
217 template <class T, template <class> class OIf>
218 inline constant<T>* make_constant(std::string pName,
219  T initval,
220  unsigned long long take,
221  OIf<T>& outS
222  )
223 {
224  auto p = new constant<T>(pName.c_str(), initval, take);
225 
226  (*p).oport1(outS);
227 
228  return p;
229 }
230 
232 
238 template <class T, template <class> class OIf>
239 inline source<T>* make_source(std::string pName,
240  typename source<T>::functype _func,
241  T initval,
242  unsigned long long take,
243  OIf<T>& outS
244  )
245 {
246  auto p = new source<T>(pName.c_str(), _func, initval, take);
247 
248  (*p).oport1(outS);
249 
250  return p;
251 }
252 
254 
260 template <class T, template <class> class OIf>
261 inline file_source<T>* make_file_source(std::string pName,
262  typename file_source<T>::functype _func,
263  std::string file_name,
264  OIf<T>& outS
265  )
266 {
267  auto p = new file_source<T>(pName.c_str(), _func, file_name);
268 
269  (*p).oport1(outS);
270 
271  return p;
272 }
273 
275 
281 template <class T, template <class> class OIf>
282 inline vsource<T>* make_vsource(const std::string& pName,
283  const std::vector<T>& in_vec,
284  OIf<T>& outS
285  )
286 {
287  auto p = new vsource<T>(pName.c_str(), in_vec);
288 
289  (*p).oport1(outS);
290 
291  return p;
292 }
293 
295 
301 template <class T, template <class> class IIf>
302 inline sink<T>* make_sink(std::string pName,
303  typename sink<T>::functype _func,
304  IIf<T>& inS
305  )
306 {
307  auto p = new sink<T>(pName.c_str(), _func);
308 
309  (*p).iport1(inS);
310 
311  return p;
312 }
313 
315 
321 template <class T, template <class> class IIf>
322 inline file_sink<T>* make_file_sink(std::string pName,
323  typename file_sink<T>::functype _func,
324  std::string file_name,
325  IIf<T>& inS
326  )
327 {
328  auto p = new file_sink<T>(pName.c_str(), _func, file_name);
329 
330  (*p).iport1(inS);
331 
332  return p;
333 }
334 
336 
342 template <class T1, template <class> class I1If,
343  class T2, template <class> class I2If,
344  template <class> class OIf>
345 inline zip<T1,T2>* make_zip(std::string pName,
346  unsigned int i1toks,
347  unsigned int i2toks,
348  OIf<std::tuple<std::vector<T1>,std::vector<T2>>>& outS,
349  I1If<T1>& inp1S,
350  I2If<T2>& inp2S
351  )
352 {
353  auto p = new zip<T1,T2>(pName.c_str(), i1toks, i2toks);
354 
355  (*p).iport1(inp1S);
356  (*p).iport2(inp2S);
357  (*p).oport1(outS);
358 
359  return p;
360 }
361 
363 
369 template <template <class> class IIf,
370  class T1, template <class> class O1If,
371  class T2, template <class> class O2If>
372 inline unzip<T1,T2>* make_unzip(std::string pName,
373  IIf<std::tuple<std::vector<T1>,std::vector<T2>>>& inpS,
374  unsigned int o1toks,
375  unsigned int o2toks,
376  O1If<T1>& out1S,
377  O2If<T2>& out2S
378  )
379 {
380  auto p = new unzip<T1,T2>(pName.c_str(), o1toks, o2toks);
381 
382  (*p).iport1(inpS);
383  (*p).oport1(out1S);
384  (*p).oport2(out2S);
385 
386  return p;
387 }
388 
390 
396 //~ template <template <class> class IIf,
397  //~ typename T1, template <typename> typename OIf,
398  //~ typename... Ts>
399 //~ inline unzipN<T...>* make_unzipN(std::string pName,
400  //~ IIf<std::tuple<abst_ext<Ts>...>>& inpS,
401  //~ OIf<T1>& outS,
402  //~ OIfs<Ts>&... outsS
403  //~ )
404 //~ {
405  //~ make_unzipN(pName, inpS, outsS...);
406  //~ std:get???????????(*p).iport1(inpS);
407  //~
408  //~ return p;
409 //~ }
410  //~ auto p = new unzip<T1,T2>(pName.c_str());
411  //~
412  //~ (*p).iport1(inpS);
413  //~ (*p).oport1(out1S);
414  //~ (*p).oport2(out2S);
415  //~
416  //~ return p;
417 //~ }
418 
420 
426 template <typename T, template <class> class IIf,
427  template <class> class OIf>
428 inline fanout<T>* make_fanout(std::string pName,
429  OIf<T>& outS,
430  IIf<T>& inpS
431  )
432 {
433  auto p = new fanout<T>(pName.c_str());
434 
435  (*p).iport1(inpS);
436  (*p).oport1(outS);
437 
438  return p;
439 }
440 
441 
442 }
443 }
444 
445 #endif
Process constructor for a combinational process with two inputs and one output.
Definition: sdf_process_constructors.hpp:329
Process constructor for a combinational process (actor) with one input and one output.
Definition: sdf_process_constructors.hpp:45
unzip< T1, T2 > * make_unzip(std::string pName, IIf< std::tuple< std::vector< T1 >, std::vector< T2 >>> &inpS, unsigned int o1toks, unsigned int o2toks, O1If< T1 > &out1S, O2If< T2 > &out2S)
Helper function to construct an unzip process.
Definition: sdf_helpers.hpp:372
Process constructor for a file_source process.
Definition: sdf_process_constructors.hpp:764
zip< T1, T2 > * make_zip(std::string pName, unsigned int i1toks, 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: sdf_helpers.hpp:345
SDF_in< T > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:453
comb4< T0, T1, T2, T3, T4 > * make_comb4(std::string pName, typename comb4< T0, T1, T2, T3, T4 >::functype _func, unsigned int o1toks, unsigned int i1toks, unsigned int i2toks, unsigned int i3toks, 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: sdf_helpers.hpp:137
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
SDF_out< T > oport1
port for the output channel
Definition: sdf_process_constructors.hpp:607
SDF_in< T1 > iport1
port for the input channel 1
Definition: sdf_process_constructors.hpp:134
SDF_out< T > oport1
port for the output channel
Definition: sdf_process_constructors.hpp:767
Process constructor for a file_sink process.
Definition: sdf_process_constructors.hpp:993
std::function< void(T &, const std::string &)> functype
Type of the function to be passed to the process constructor.
Definition: sdf_process_constructors.hpp:770
SDF_in< std::tuple< std::vector< T1 >, std::vector< T2 > > > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:1329
Process constructor for a source process.
Definition: sdf_process_constructors.hpp:674
Process constructor for a combinational process with two inputs and one output.
Definition: sdf_process_constructors.hpp:131
Process constructor for a source process with vector input.
Definition: sdf_process_constructors.hpp:854
fanout< T > * make_fanout(std::string pName, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct an unzipN process.
Definition: sdf_helpers.hpp:428
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: sdf_process_constructors.hpp:344
Process constructor for a fan-out process with one input and one output.
Definition: sdf_process_constructors.hpp:1531
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: sdf_helpers.hpp:282
delay< T > * make_delay(std::string pName, T initval, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a delay process.
Definition: sdf_helpers.hpp:172
Implements the basic process constructors in the SDF MoC.
Process constructor for a n-delay element.
Definition: sdf_process_constructors.hpp:526
comb2< T0, T1, T2 > * make_comb2(std::string pName, typename comb2< T0, T1, T2 >::functype _func, unsigned int o1toks, unsigned int i1toks, unsigned int i2toks, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S)
Helper function to construct a comb2 process.
Definition: sdf_helpers.hpp:71
SDF_in< T > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:923
SDF_out< T > oport1
port for the output channel
Definition: sdf_process_constructors.hpp:677
std::function< void(T &, const T &)> functype
Type of the function to be passed to the process constructor.
Definition: sdf_process_constructors.hpp:680
SDF_in< T1 > iport1
port for the input channel 1
Definition: sdf_process_constructors.hpp:228
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: sdf_process_constructors.hpp:142
SDF_in< T > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:529
file_source< T > * make_file_source(std::string pName, typename file_source< T >::functype _func, std::string file_name, OIf< T > &outS)
Helper function to construct a file_source process.
Definition: sdf_helpers.hpp:261
SDF_in< T1 > iport1
port for the input channel 1
Definition: sdf_process_constructors.hpp:332
sink< T > * make_sink(std::string pName, typename sink< T >::functype _func, IIf< T > &inS)
Helper function to construct a sink process.
Definition: sdf_helpers.hpp:302
SDF_in< T1 > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:48
std::function< void(std::vector< T0 > &, const std::vector< T1 > &)> functype
Type of the function to be passed to the process constructor.
Definition: sdf_process_constructors.hpp:54
std::function< void(const T &)> functype
Type of the function to be passed to the process constructor.
Definition: sdf_process_constructors.hpp:926
delayn< T > * make_delayn(std::string pName, T initval, unsigned int n, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a delayn process.
Definition: sdf_helpers.hpp:195
constant< T > * make_constant(std::string pName, T initval, unsigned long long take, OIf< T > &outS)
Helper function to construct a constant source process.
Definition: sdf_helpers.hpp:218
SDF_in< T1 > iport1
port for the input channel 1
Definition: sdf_process_constructors.hpp:1129
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: sdf_process_constructors.hpp:238
The zip process with two inputs and one output.
Definition: sdf_process_constructors.hpp:1126
Process constructor for a constant source process.
Definition: sdf_process_constructors.hpp:604
Process constructor for a combinational process with two inputs and one output.
Definition: sdf_process_constructors.hpp:225
Process constructor for a sink process.
Definition: sdf_process_constructors.hpp:920
SDF_out< T > oport1
port for the output channel
Definition: sdf_process_constructors.hpp:857
source< T > * make_source(std::string pName, typename source< T >::functype _func, T initval, unsigned long long take, OIf< T > &outS)
Helper function to construct a source process.
Definition: sdf_helpers.hpp:239
SDF_in< T > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:1534
Process constructor for a delay element.
Definition: sdf_process_constructors.hpp:450
The unzip process with one input and two outputs.
Definition: sdf_process_constructors.hpp:1326
SDF_in< T > iport1
port for the input channel
Definition: sdf_process_constructors.hpp:996
file_sink< T > * make_file_sink(std::string pName, typename file_sink< T >::functype _func, std::string file_name, IIf< T > &inS)
Helper function to construct a file_sink process.
Definition: sdf_helpers.hpp:322
comb< T0, T1 > * make_comb(std::string pName, typename comb< T0, T1 >::functype _func, unsigned int o1toks, unsigned int i1toks, OIf< T0 > &outS, I1If< T1 > &inp1S)
Helper function to construct a comb process.
Definition: sdf_helpers.hpp:45
comb3< T0, T1, T2, T3 > * make_comb3(std::string pName, typename comb3< T0, T1, T2, T3 >::functype _func, unsigned int o1toks, unsigned int i1toks, unsigned int i2toks, unsigned int i3toks, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S, I3If< T3 > &inp3S)
Helper function to construct a comb3 process.
Definition: sdf_helpers.hpp:102
std::function< void(std::string &, const T &)> functype
Type of the function to be passed to the process constructor.
Definition: sdf_process_constructors.hpp:999