ct_helpers.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * ct_helpers.hpp -- Helper primitives in the CT MoC *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: Providing helper primitives for modeling in the CT MoC *
7  * *
8  * Usage: This file is included automatically *
9  * *
10  * License: BSD3 *
11  *******************************************************************/
12 
13 #ifndef CT_HELPERS_HPP
14 #define CT_HELPERS_HPP
15 
23 #include <functional>
24 
25 #include "sub_signal.hpp"
27 
28 namespace ForSyDe
29 {
30 
31 namespace CT
32 {
33 
34 using namespace sc_core;
35 
37 
43 template <class OIf, class I1If>
44 inline comb* make_comb(std::string pName,
45  typename comb::functype _func,
46  OIf& outS,
47  I1If& inp1S
48  )
49 {
50  auto p = new comb(pName.c_str(), _func);
51 
52  (*p).iport1(inp1S);
53  (*p).oport1(outS);
54 
55  return p;
56 }
57 
59 
65 template <class OIf, class I1If, class I2If>
66 inline comb2* make_comb2(std::string pName,
67  typename comb2::functype _func,
68  OIf& outS,
69  I1If& inp1S,
70  I2If& inp2S
71  )
72 {
73  auto p = new comb2(pName.c_str(), _func);
74 
75  (*p).iport1(inp1S);
76  (*p).iport2(inp2S);
77  (*p).oport1(outS);
78 
79  return p;
80 }
81 
83 
89 template <class OIf, class IIf, std::size_t N>
90 inline combX<N>* make_combX(std::string pName,
91  typename combX<N>::functype _func,
92  OIf& outS,
93  std::array<IIf,N>& inpS
94  )
95 {
96  auto p = new combX<N>(pName.c_str(), _func);
97 
98  for (int i=0;i<N;i++)
99  (*p).iport[i](inpS[i]);
100  (*p).oport1(outS);
101 
102  return p;
103 }
104 
106 
112 template <class IIf, class OIf>
113 inline delay* make_delay(std::string pName,
114  sc_time delay_time,
115  OIf& outS,
116  IIf& inpS
117  )
118 {
119  auto p = new delay(pName.c_str(), delay_time);
120 
121  (*p).iport1(inpS);
122  (*p).oport1(outS);
123 
124  return p;
125 }
126 
128 
134 template <class IIf, class OIf>
135 inline shift* make_shift(std::string pName,
136  sc_time delay_time,
137  OIf& outS,
138  IIf& inpS
139  )
140 {
141  auto p = new shift(pName.c_str(), delay_time);
142 
143  (*p).iport1(inpS);
144  (*p).oport1(outS);
145 
146  return p;
147 }
148 
150 
156 template <class OIf>
157 inline constant* make_constant(std::string pName,
158  CTTYPE init_val,
159  sc_time end_time,
160  OIf& outS
161  )
162 {
163  auto p = new constant(pName.c_str(), init_val, end_time);
164 
165  (*p).oport1(outS);
166 
167  return p;
168 }
169 
171 
177 template <class OIf>
178 inline source* make_source(std::string pName,
179  typename source::functype _func,
180  const sc_time& end_time,
181  OIf& outS
182  )
183 {
184  auto p = new source(pName.c_str(), _func, end_time);
185 
186  (*p).oport1(outS);
187 
188  return p;
189 }
190 
192 
198 template <class IIf>
199 inline sink* make_sink(std::string pName,
200  typename sink::functype _func,
201  sc_time sampling_period,
202  IIf& inS
203  )
204 {
205  auto p = new sink(pName.c_str(), _func, sampling_period);
206 
207  (*p).iport1(inS);
208 
209  return p;
210 }
211 
213 
219 template <class IIf>
220 inline traceSig* make_traceSig(std::string pName,
221  sc_time sampling_period,
222  IIf& inpS
223  )
224 {
225  auto p = new traceSig(pName.c_str(), sampling_period);
226 
227  (*p).iport1(inpS);
228 
229  return p;
230 }
231 
233 
239 template <class IIf, class OIf>
240 inline fanout* make_fanout(std::string pName,
241  OIf& outS,
242  IIf& inpS
243  )
244 {
245  auto p = new fanout(pName.c_str());
246 
247  (*p).iport1(inpS);
248  (*p).oport1(outS);
249 
250  return p;
251 }
252 
253 
254 }
255 }
256 
257 #endif
CT_out oport1
port for the output channel
Definition: ct_process_constructors.hpp:513
std::function< void(CTTYPE &, const std::array< CTTYPE, N > &)> functype
Type of the function to be passed to the process constructor.
Definition: ct_process_constructors.hpp:241
std::function< void(CTTYPE &, const sc_time &)> functype
Type of the function to be passed to the process constructor.
Definition: ct_process_constructors.hpp:586
double CTTYPE
Type of the values used in the CT MoC (currently fixed)
Definition: sub_signal.hpp:27
Process constructor for a sink process.
Definition: ct_process_constructors.hpp:657
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
CT_in iport1
port for the input channel
Definition: ct_process_constructors.hpp:48
sink * make_sink(std::string pName, typename sink::functype _func, sc_time sampling_period, IIf &inS)
Helper function to construct a sink process.
Definition: ct_helpers.hpp:199
std::function< void(CTTYPE &, const CTTYPE &)> functype
Type of the function to be passed to the process constructor.
Definition: ct_process_constructors.hpp:52
CT_in iport1
port for the input channel
Definition: ct_process_constructors.hpp:344
Process constructor for a combinational process with one input and one output.
Definition: ct_process_constructors.hpp:45
Process constructor for a delay element.
Definition: ct_process_constructors.hpp:341
CT_in iport1
port for the input channel
Definition: ct_process_constructors.hpp:736
CT_out oport1
port for the output channel
Definition: ct_process_constructors.hpp:583
constant * make_constant(std::string pName, CTTYPE init_val, sc_time end_time, OIf &outS)
Helper function to construct a constant source process.
Definition: ct_helpers.hpp:157
fanout * make_fanout(std::string pName, OIf &outS, IIf &inpS)
Helper function to construct a fanout process.
Definition: ct_helpers.hpp:240
Process constructor for a trace process.
Definition: ct_process_constructors.hpp:733
CT_in iport1
port for the input channel
Definition: ct_process_constructors.hpp:425
std::array< CT_in, N > iport
port for the input channel array
Definition: ct_process_constructors.hpp:237
CT_in iport1
port for the input channel
Definition: ct_process_constructors.hpp:817
Process constructor for a source process.
Definition: ct_process_constructors.hpp:580
CT_in iport1
port for the input channel
Definition: ct_process_constructors.hpp:660
comb * make_comb(std::string pName, typename comb::functype _func, OIf &outS, I1If &inp1S)
Helper function to construct a comb process.
Definition: ct_helpers.hpp:44
Process constructor for a combinational process with an array of inputs and one output.
Definition: ct_process_constructors.hpp:234
Process constructor for a constant source process.
Definition: ct_process_constructors.hpp:510
traceSig * make_traceSig(std::string pName, sc_time sampling_period, IIf &inpS)
Helper function to construct a traceSig process.
Definition: ct_helpers.hpp:220
std::function< void(const CTTYPE &)> functype
Type of the function to be passed to the process constructor.
Definition: ct_process_constructors.hpp:663
combX< N > * make_combX(std::string pName, typename combX< N >::functype _func, OIf &outS, std::array< IIf, N > &inpS)
Helper function to construct a combX process.
Definition: ct_helpers.hpp:90
delay * make_delay(std::string pName, sc_time delay_time, OIf &outS, IIf &inpS)
Helper function to construct a delay process.
Definition: ct_helpers.hpp:113
Process constructor for a shift element.
Definition: ct_process_constructors.hpp:422
Process constructor for a fan-out process with one input and one output.
Definition: ct_process_constructors.hpp:814
shift * make_shift(std::string pName, sc_time delay_time, OIf &outS, IIf &inpS)
Helper function to construct a shift process.
Definition: ct_helpers.hpp:135
Implements the basic process constructors in the CT MoC.
CT_in iport1
port for the input channel 1
Definition: ct_process_constructors.hpp:128
Process constructor for a combinational process with two inputs and one output.
Definition: ct_process_constructors.hpp:125
source * make_source(std::string pName, typename source::functype _func, const sc_time &end_time, OIf &outS)
Helper function to construct a source process.
Definition: ct_helpers.hpp:178
std::function< void(CTTYPE &, const CTTYPE &, const CTTYPE &)> functype
Type of the function to be passed to the process constructor.
Definition: ct_process_constructors.hpp:134
comb2 * make_comb2(std::string pName, typename comb2::functype _func, OIf &outS, I1If &inp1S, I2If &inp2S)
Helper function to construct a comb2 process.
Definition: ct_helpers.hpp:66
Implements the sub-components of a CT signal.