14 #ifndef SY_WRAPPERS_HPP 15 #define SY_WRAPPERS_HPP 31 #include <sys/types.h> 53 template <
typename T0,
typename T1>
67 const std::string& exec_name
68 ) :
sy_process(_name), iport1(
"iport1"), oport1(
"oport1"),
71 #ifdef FORSYDE_INTROSPECTION 72 arg_vec.push_back(std::make_tuple(
"exec_name",exec_name));
83 std::istringstream oval_str;
84 std::ostringstream ival1_str;
87 std::string exec_name;
91 mi_bkpt *bk_in1, *bk_out;
100 SC_REPORT_ERROR(name(),
"Connection to child GDB instance failed.");
104 if (!d.SelectTargetX11(exec_name.c_str()))
105 SC_REPORT_ERROR(name(),
"Error executing the external model");
108 bk_in1=d.Breakpoint(
"forsyde_read_in1");
109 bk_out=d.Breakpoint(
"forsyde_write_out");
110 if (!bk_in1 || !bk_out)
111 SC_REPORT_ERROR(name(),
"Error Setting the breakpoints");
112 mi_free_bkpt(bk_in1);
113 mi_free_bkpt(bk_out);
116 async_run(d.RunOrContinue());
124 *ival1 = iport1.read();
125 ival1_str<<unsafe_from_abst_ext(*ival1);
126 async_run(d.StepOver());
127 d.ModifyExpression(
"forsyde_in1",const_cast<char*>(ival1_str.str().c_str()));
128 ival1_str.str(std::string());
134 async_run(d.Continue());
139 async_run(d.StepOver());
140 oval_str.str(d.EvalExpression(
"forsyde_out"));
146 async_run(d.Continue());
157 inline void async_run(
int res)
160 SC_REPORT_ERROR(name(),
"Error in GDB command execution!");
163 while (!d.Poll(sr)) wait(SC_ZERO_TIME);
167 SC_REPORT_ERROR(name(),mi_error_from_gdb);
170 #ifdef FORSYDE_INTROSPECTION 173 boundInChans.resize(1);
174 boundInChans[0].port = &iport1;
175 boundOutChans.resize(1);
176 boundOutChans[0].port = &oport1;
187 template <
typename T0,
typename T1>
201 const std::string& pipe_path
202 ) :
sy_process(_name), iport1(
"iport1"), oport1(
"oport1"),
203 offset(offset), pipe_path(pipe_path)
205 #ifdef FORSYDE_INTROSPECTION 206 arg_vec.push_back(std::make_tuple(
"pipe_path",pipe_path));
217 std::istringstream oval_str;
218 std::ostringstream ival_str;
223 std::string pipe_path;
228 int inp_pipe_fd, out_pipe_fd;
238 inp_pipe_fd = out_pipe_fd = 0;
241 ival_str.str(pipe_path +
"/" + basename() +
"_inp");
242 oval_str.str(pipe_path +
"/" + basename() +
"_out");
245 while (inp_pipe_fd<=0 || out_pipe_fd<=0)
249 inp_pipe_fd = open(ival_str.str().c_str(), O_WRONLY|O_NONBLOCK);
251 inp_pipe = fdopen(inp_pipe_fd,
"w");
255 out_pipe_fd = open(oval_str.str().c_str(), O_RDONLY|O_NONBLOCK);
257 out_pipe = fdopen(out_pipe_fd,
"r");
261 ival_str.str(std::string());
262 oval_str.str(std::string());
267 *ival1 = iport1.read();
268 ival_str<<unsafe_from_abst_ext(*ival1);
270 while(fprintf(inp_pipe,
"%s\n",ival_str.str().c_str())==0)
272 if (ferror(inp_pipe) && errno==EAGAIN)
278 SC_REPORT_ERROR(name(),
"Error writing to the input pipe.");
280 ival_str.str(std::string());
289 while(fgets(buf,80,out_pipe)==NULL)
302 else if (ferror(out_pipe) && errno==EAGAIN)
305 SC_REPORT_ERROR(name(),
"Error reading from the output pipe.");
309 oval_str.str(std::string(buf));
323 #ifdef FORSYDE_INTROSPECTION 326 boundInChans.resize(1);
327 boundInChans[0].port = &iport1;
328 boundOutChans.resize(1);
329 boundOutChans[0].port = &oport1;
340 template <
typename T0,
typename T1,
typename T2>
355 const std::string& pipe_path
356 ) :
sy_process(_name), iport1(
"iport1"), iport2(
"iport2"),
357 oport1(
"oport1"), offset(offset), pipe_path(pipe_path)
359 #ifdef FORSYDE_INTROSPECTION 360 arg_vec.push_back(std::make_tuple(
"pipe_path",pipe_path));
372 std::istringstream oval_str;
373 std::ostringstream ival_str;
378 std::string pipe_path;
383 int inp_pipe_fd, out_pipe_fd;
394 inp_pipe_fd = out_pipe_fd = 0;
397 ival_str.str(pipe_path +
"/" + basename() +
"_inp");
398 oval_str.str(pipe_path +
"/" + basename() +
"_out");
401 while (inp_pipe_fd<=0 || out_pipe_fd<=0)
405 inp_pipe_fd = open(ival_str.str().c_str(), O_WRONLY|O_NONBLOCK);
407 inp_pipe = fdopen(inp_pipe_fd,
"w");
411 out_pipe_fd = open(oval_str.str().c_str(), O_RDONLY|O_NONBLOCK);
413 out_pipe = fdopen(out_pipe_fd,
"r");
417 ival_str.str(std::string());
418 oval_str.str(std::string());
425 *ival1 = iport1.read();
426 *ival2 = iport2.read();
427 ival_str<<unsafe_from_abst_ext(*ival1)<<
" "<<unsafe_from_abst_ext(*ival2);
429 while(fprintf(inp_pipe,
"%s\n",ival_str.str().c_str())==0)
431 if (ferror(inp_pipe) && errno==EAGAIN)
437 SC_REPORT_ERROR(name(),
"Error writing to the input pipe.");
440 ival_str.str(std::string());
452 while(fgets(buf,80,out_pipe)==NULL)
465 else if (ferror(out_pipe) && errno==EAGAIN)
468 SC_REPORT_ERROR(name(),
"Error reading from the output pipe.");
472 oval_str.str(std::string(buf));
477 if (offset<0) offset++;
478 else if (offset>0) offset--;
490 #ifdef FORSYDE_INTROSPECTION 493 boundInChans.resize(2);
494 boundInChans[0].port = &iport1;
495 boundInChans[1].port = &iport2;
496 boundOutChans.resize(1);
497 boundOutChans[0].port = &oport1;
510 template <
class T0,
template <
class>
class OIf,
511 class T1,
template <
class>
class I1If>
513 const std::string& exec_name,
533 template <
class T0,
template <
class>
class OIf,
534 class T1,
template <
class>
class I1If>
537 const std::string& path_name,
557 template <
class T0,
template <
class>
class OIf,
558 class T1,
template <
class>
class I1If,
559 class T2,
template <
class>
class I2If>
562 const std::string& path_name,
Process constructor for a pipe wrapper with one input and one output.
Definition: sy_wrappers.hpp:188
SY_in< T1 > iport1
port for the input channel
Definition: sy_wrappers.hpp:191
Process constructor for a GDB wrapper with one input and one output.
Definition: sy_wrappers.hpp:54
pipewrap(const sc_module_name &_name, const int &offset, const std::string &pipe_path)
The constructor requires the module name.
Definition: sy_wrappers.hpp:199
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
std::string forsyde_kind() const
Specifying from which process constructor is the module built.
Definition: sy_wrappers.hpp:211
Implements the Absent-extended values.
SY_in< T2 > iport2
port for the second channel
Definition: sy_wrappers.hpp:345
SY_out< T0 > oport1
port for the output channel
Definition: sy_wrappers.hpp:58
Implements the abstract process in the synchronous Model of Computation.
pipewrap< T0, T1 > * make_pipewrap(const std::string &pName, const int &offset, const std::string &path_name, OIf< T0 > &outS, I1If< T1 > &inp1S)
Helper function to construct a pipewrap process.
Definition: sy_wrappers.hpp:535
SY_out< T0 > oport1
port for the output channel
Definition: sy_wrappers.hpp:346
std::string forsyde_kind() const
Specifying from which process constructor is the module built.
Definition: sy_wrappers.hpp:77
SY_in< T1 > iport1
port for the input channel
Definition: sy_wrappers.hpp:57
SY_in< T1 > iport1
port for the input channel
Definition: sy_wrappers.hpp:344
gdbwrap(const sc_module_name &_name, const std::string &exec_name)
The constructor requires the module name.
Definition: sy_wrappers.hpp:66
The process constructor which defines the abstract semantics of execution.
Definition: abssemantics.hpp:212
Process constructor for a pipe wrapper with one input and one output.
Definition: sy_wrappers.hpp:341
pipewrap2< T0, T1, T2 > * make_pipewrap2(const std::string &pName, const int &offset, const std::string &path_name, OIf< T0 > &outS, I1If< T1 > &inp1S, I2If< T2 > &inp2S)
Helper function to construct a pipewrap process.
Definition: sy_wrappers.hpp:560
SY_out< T0 > oport1
port for the output channel
Definition: sy_wrappers.hpp:192
pipewrap2(const sc_module_name &_name, const int &offset, const std::string &pipe_path)
The constructor requires the module name.
Definition: sy_wrappers.hpp:353
std::string forsyde_kind() const
Specifying from which process constructor is the module built.
Definition: sy_wrappers.hpp:365
gdbwrap< T0, T1 > * make_gdbwrap(const std::string &pName, const std::string &exec_name, OIf< T0 > &outS, I1If< T1 > &inp1S)
Helper function to construct a gdbwrap process.
Definition: sy_wrappers.hpp:512