dt_helpers.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * dt_helpers.hpp -- Helper primitives in the DT MoC *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: Providing helper primitives for modeling in the DT MoC *
7  * *
8  * Usage: This file is included automatically *
9  * *
10  * License: BSD3 *
11  *******************************************************************/
12 
13 #ifndef DT_HELPERS_HPP
14 #define DT_HELPERS_HPP
15 
23 #include <functional>
24 #include <tuple>
25 
26 #include "abst_ext.hpp"
28 
29 namespace ForSyDe
30 {
31 
32 namespace DT
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 <class T0, template <class> class OIf,
94  class T1, template <class> class I1If,
95  class T2, template <class> class I2If,
96  class T3, template <class> class I3If>
97 inline comb3<T0,T1,T2,T3>* make_comb3(std::string pName,
98  typename comb3<T0,T1,T2,T3>::functype _func,
99  OIf<T0>& outS,
100  I1If<T1>& inp1S,
101  I2If<T2>& inp2S,
102  I3If<T3>& inp3S
103  )
104 {
105  auto p = new comb3<T0,T1,T2,T3>(pName.c_str(), _func);
106 
107  (*p).iport1(inp1S);
108  (*p).iport2(inp2S);
109  (*p).iport3(inp3S);
110  (*p).oport1(outS);
111 
112  return p;
113 }
114 
116 
122 template <class T0, template <class> class OIf,
123  class T1, template <class> class I1If,
124  class T2, template <class> class I2If,
125  class T3, template <class> class I3If,
126  class T4, template <class> class I4If>
127 inline comb4<T0,T1,T2,T3,T4>* make_comb4(std::string pName,
128  typename comb4<T0,T1,T2,T3,T4>::functype _func,
129  OIf<T0>& outS,
130  I1If<T1>& inp1S,
131  I2If<T2>& inp2S,
132  I3If<T3>& inp3S,
133  I4If<T4>& inp4S
134  )
135 {
136  auto p = new comb4<T0,T1,T2,T3,T4>(pName.c_str(), _func);
137 
138  (*p).iport1(inp1S);
139  (*p).iport2(inp2S);
140  (*p).iport3(inp3S);
141  (*p).iport4(inp4S);
142  (*p).oport1(outS);
143 
144  return p;
145 }
146 
148 
154 template <typename T, template <class> class IIf,
155  template <class> class OIf>
156 inline delay<T>* make_delay(std::string pName,
157  abst_ext<T> initval,
158  OIf<T>& outS,
159  IIf<T>& inpS
160  )
161 {
162  auto p = new delay<T>(pName.c_str(), initval);
163 
164  (*p).iport1(inpS);
165  (*p).oport1(outS);
166 
167  return p;
168 }
169 
171 
177 template <typename IT, typename ST, typename OT,
178  template <class> class IIf,
179  template <class> class OIf>
180 inline mealyT<IT,ST,OT>* make_mealyT(std::string pName,
181  typename mealyT<IT,ST,OT>::p_functype gamma,
182  typename mealyT<IT,ST,OT>::ns_functype _ns_func,
183  typename mealyT<IT,ST,OT>::od_functype _od_func,
184  ST init_st,
185  OIf<OT>& outS,
186  IIf<IT>& inpS
187  )
188 {
189  auto p = new mealyT<IT,ST,OT>(pName.c_str(), gamma, _ns_func, _od_func, init_st);
190 
191  (*p).iport1(inpS);
192  (*p).oport1(outS);
193 
194  return p;
195 }
196 
198 
204 template <class T, template <class> class OIf>
205 inline constant<T>* make_constant(std::string pName,
206  abst_ext<T> initval,
207  unsigned long long take,
208  OIf<T>& outS
209  )
210 {
211  auto p = new constant<T>(pName.c_str(), initval, take);
212 
213  (*p).oport1(outS);
214 
215  return p;
216 }
217 
219 
225 template <class T, template <class> class OIf>
226 inline source<T>* make_source(std::string pName,
227  typename source<T>::functype _func,
228  abst_ext<T> initval,
229  unsigned long long take,
230  OIf<T>& outS
231  )
232 {
233  auto p = new source<T>(pName.c_str(), _func, initval, take);
234 
235  (*p).oport1(outS);
236 
237  return p;
238 }
239 
241 
247 template <class T, template <class> class OIf>
248 inline vsource<T>* make_vsource(std::string pName,
249  std::vector<std::tuple<unsigned int,T>> in_vec,
250  OIf<T>& outS
251  )
252 {
253  auto p = new vsource<T>(pName.c_str(), in_vec);
254 
255  (*p).oport1(outS);
256 
257  return p;
258 }
259 
261 
267 template <class T, template <class> class IIf>
268 inline sink<T>* make_sink(std::string pName,
269  typename sink<T>::functype _func,
270  IIf<T>& inS
271  )
272 {
273  auto p = new sink<T>(pName.c_str(), _func);
274 
275  (*p).iport1(inS);
276 
277  return p;
278 }
279 
281 
287 template <class T1, template <class> class I1If,
288  class T2, template <class> class I2If,
289  template <class> class OIf>
290 inline zip<T1,T2>* make_zip(std::string pName,
291  OIf<std::tuple<abst_ext<T1>,abst_ext<T2>>>& outS,
292  I1If<T1>& inp1S,
293  I2If<T2>& inp2S
294  )
295 {
296  auto p = new zip<T1,T2>(pName.c_str());
297 
298  (*p).iport1(inp1S);
299  (*p).iport2(inp2S);
300  (*p).oport1(outS);
301 
302  return p;
303 }
304 
306 
312 template <template <class> class IIf,
313  class T1, template <class> class O1If,
314  class T2, template <class> class O2If>
315 inline unzip<T1,T2>* make_unzip(std::string pName,
316  IIf<std::tuple<abst_ext<T1>,abst_ext<T2>>>& inpS,
317  O1If<T1>& out1S,
318  O2If<T2>& out2S
319  )
320 {
321  auto p = new unzip<T1,T2>(pName.c_str());
322 
323  (*p).iport1(inpS);
324  (*p).oport1(out1S);
325  (*p).oport2(out2S);
326 
327  return p;
328 }
329 
331 
337 //~ template <template <class> class IIf,
338  //~ typename T1, template <typename> typename OIf,
339  //~ typename... Ts>
340 //~ inline unzipN<T...>* make_unzipN(std::string pName,
341  //~ IIf<std::tuple<abst_ext<Ts>...>>& inpS,
342  //~ OIf<T1>& outS,
343  //~ OIfs<Ts>&... outsS
344  //~ )
345 //~ {
346  //~ make_unzipN(pName, inpS, outsS...);
347  //~ std:get???????????(*p).iport1(inpS);
348  //~
349  //~ return p;
350 //~ }
351  //~ auto p = new unzip<T1,T2>(pName.c_str());
352  //~
353  //~ (*p).iport1(inpS);
354  //~ (*p).oport1(out1S);
355  //~ (*p).oport2(out2S);
356  //~
357  //~ return p;
358 //~ }
359 
361 
367 template <typename T, template <class> class IIf,
368  template <class> class OIf>
369 inline fanout<T>* make_fanout(std::string pName,
370  OIf<T>& outS,
371  IIf<T>& inpS
372  )
373 {
374  auto p = new fanout<T>(pName.c_str());
375 
376  (*p).iport1(inpS);
377  (*p).oport1(outS);
378 
379  return p;
380 }
381 
382 
383 }
384 }
385 
386 #endif
DT_in< T1 > iport1
port for the input channel 1
Definition: dt_process_constructors.hpp:144
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: dt_helpers.hpp:315
The zip process with two inputs and one output.
Definition: dt_process_constructors.hpp:1140
std::function< void(T0 &, const T1 &, const T2 &, const T3 &, const T4 &)> functype
Type of the function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:378
DT_in< T1 > iport1
port for the input channel 1
Definition: dt_process_constructors.hpp:1143
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: dt_helpers.hpp:290
std::function< void(T0 &, const T1 &, const T2 &, const T3 &)> functype
Type of the function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:257
std::function< void(const abst_ext< T > &)> functype
Type of the function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:1029
mealyT< IT, ST, OT > * make_mealyT(std::string pName, typename mealyT< IT, ST, OT >::p_functype gamma, typename mealyT< IT, ST, OT >::ns_functype _ns_func, typename mealyT< IT, ST, OT >::od_functype _od_func, ST init_st, OIf< OT > &outS, IIf< IT > &inpS)
Helper function to construct a mealyT process.
Definition: dt_helpers.hpp:180
DT_in< T1 > iport1
port for the input channel 1
Definition: dt_process_constructors.hpp:371
Process constructor for a combinational process with four inputs and one output.
Definition: dt_process_constructors.hpp:368
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
Process constructor for a sink process.
Definition: dt_process_constructors.hpp:1023
Process constructor for a source process.
Definition: dt_process_constructors.hpp:861
DT_out< T > oport1
port for the output channel
Definition: dt_process_constructors.hpp:956
Implements the Absent-extended values.
Process constructor for a combinational process with one input and one output.
Definition: dt_process_constructors.hpp:45
vsource< T > * make_vsource(std::string pName, std::vector< std::tuple< unsigned int, T >> in_vec, OIf< T > &outS)
Helper function to construct a vsource process.
Definition: dt_helpers.hpp:248
DT_in< T1 > iport1
port for the input channel
Definition: dt_process_constructors.hpp:48
std::function< void(T0 &, const T1 &, const T2 &)> functype
Type of the function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:149
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: dt_helpers.hpp:70
Process constructor for a constant source process.
Definition: dt_process_constructors.hpp:788
std::function< void(abst_ext< T > &, const abst_ext< T > &)> functype
Type of the function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:867
Process constructor for a fan-out process with one input and one output.
Definition: dt_process_constructors.hpp:1479
Process constructor for a combinational process with three inputs and one output. ...
Definition: dt_process_constructors.hpp:248
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: dt_helpers.hpp:46
DT_in< std::tuple< abst_ext< T1 >, abst_ext< T2 > > > iport1
port for the input channel
Definition: dt_process_constructors.hpp:1282
Process constructor for a combinational process with two inputs and one output.
Definition: dt_process_constructors.hpp:141
sink< T > * make_sink(std::string pName, typename sink< T >::functype _func, IIf< T > &inS)
Helper function to construct a sink process.
Definition: dt_helpers.hpp:268
std::function< void(std::vector< abst_ext< OT >> &, const ST &, const std::vector< abst_ext< IT >> &)> od_functype
Type of the output-decoding function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:674
DT_in< T > iport1
port for the input channel
Definition: dt_process_constructors.hpp:507
DT_in< T > iport1
port for the input channel
Definition: dt_process_constructors.hpp:1026
Implements the basic process constructors in the DT MoC.
constant< T > * make_constant(std::string pName, abst_ext< T > initval, unsigned long long take, OIf< T > &outS)
Helper function to construct a constant source process.
Definition: dt_helpers.hpp:205
DT_out< T > oport1
port for the output channel
Definition: dt_process_constructors.hpp:864
Process constructor for a source process with vector input.
Definition: dt_process_constructors.hpp:953
std::function< void(unsigned int &, const ST &)> p_functype
Type of the partitioning function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:664
Process constructor for a MealyT machine.
Definition: dt_process_constructors.hpp:657
DT_in< T1 > iport1
port for the input channel 1
Definition: dt_process_constructors.hpp:251
Absent-extended data types.
Definition: abst_ext.hpp:32
Process constructor for a delay element.
Definition: dt_process_constructors.hpp:504
comb4< T0, T1, T2, T3, T4 > * make_comb4(std::string pName, typename comb4< T0, T1, T2, T3, T4 >::functype _func, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S, I3If< T3 > &inp3S, I4If< T4 > &inp4S)
Helper function to construct a comb4 process.
Definition: dt_helpers.hpp:127
DT_in< IT > iport1
port for the input channel
Definition: dt_process_constructors.hpp:660
The unzip process with one input and two outputs.
Definition: dt_process_constructors.hpp:1279
fanout< T > * make_fanout(std::string pName, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct an unzipN process.
Definition: dt_helpers.hpp:369
DT_out< T > oport1
port for the output channel
Definition: dt_process_constructors.hpp:791
source< T > * make_source(std::string pName, typename source< T >::functype _func, abst_ext< T > initval, unsigned long long take, OIf< T > &outS)
Helper function to construct a source process.
Definition: dt_helpers.hpp:226
std::function< void(T0 &, const T1 &)> functype
Type of the function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:52
DT_in< T > iport1
port for the input channel
Definition: dt_process_constructors.hpp:1482
delay< T > * make_delay(std::string pName, abst_ext< T > initval, OIf< T > &outS, IIf< T > &inpS)
Helper function to construct a delay process.
Definition: dt_helpers.hpp:156
comb3< T0, T1, T2, T3 > * make_comb3(std::string pName, typename comb3< T0, T1, T2, T3 >::functype _func, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S, I3If< T3 > &inp3S)
Helper function to construct a comb3 process.
Definition: dt_helpers.hpp:97
std::function< void(ST &, const ST &, const std::vector< abst_ext< IT >> &)> ns_functype
Type of the next-state function to be passed to the process constructor.
Definition: dt_process_constructors.hpp:669