21 #define dbgmsg(a) std::cerr << a << " Set breakpoint at " << __FILE__ << ":" << __LINE__ << "\n";
53 sval << dec << bits <<
"'d" <<
value;
65 std::string val = sval;
72 sscanf(val.c_str(),
"%d'%c", &
bits, &radix);
78 for (i = 0; val[
i] !=
'h' && val[
i] !=
'H'; ++
i);
79 for (; i < val.length(); ++
i)
101 dig = val[
i] -
'a' + 10;
109 dig = val[
i] -
'A' + 10;
126 sscanf (val.c_str(),
"%d'%c%d", &
bits, &radix,
reinterpret_cast<int *
>(&
value));
131 for (i = 0; val[
i] !=
'o' && val[
i] !=
'O'; ++
i);
132 for (; i < val.length(); ++
i)
162 for (i = 0; val[
i] !=
'b' && val[
i] !=
'B'; ++
i);
163 for (; i < val.length(); ++
i)
234 mask = (1LL << (
h -
l + 1)) - 1LL;
280 string& Signal::getcatname()
283 catname = lb +
name + rb;
293 #define unop(op,cop) \
294 Signal Signal::op () \
297 t.name = #cop + lb + name + rb; \
299 t.r = mask & (cop getval()); \
303 #define unop(op,cop) \
304 Signal Signal::op () \
308 t.r = mask & (cop getval()); \
327 #define binop(op,cop) \
328 Signal Signal::op (Signal arg) \
331 t.name = lb + name + rb + " " + #cop + " " + arg.lb + arg.name + arg.rb; \
332 printable = arg.printable = 0; \
333 t.r = (getval() cop arg.getval()); \
337 #define binop(op,cop) \
338 Signal Signal::op (Signal arg) \
342 int aln = arg.h - arg.l; \
343 t.init((ln > aln) ? ln : aln, 0, ""); \
344 t.r = t.mask & (getval() cop arg.getval()); \
355 binop (operator<<,<<)
356 binop (operator>>,>>)
358 binop (operator&&,&&)
366 t.name = lb +
name + rb +
" || " + arg.lb + arg.name + arg.rb;
367 t.orname = orname +
" or " + arg.orname;
371 int aln = arg.h - arg.l;
372 t.
init((ln > aln) ? ln : aln, 0,
"");
374 t.
r = t.
mask & (getval() || arg.getval());
375 t.
change = change || arg.change;
383 t.name =
name +
", " + arg.name;
390 t.
init(
h -
l + arg.
h - arg.
l + 1, 0,
"");
399 #define compop(op,cop) \
400 Signal Signal::op (Signal arg) \
403 t.name = lb + name + rb + " " + #cop + " " + arg.lb + arg.name + arg.rb; \
404 printable = arg.printable = 0; \
405 t.r = (getval() cop arg.getval()); \
409 #define compop(op,cop) \
410 Signal Signal::op (Signal arg) \
414 t.r = (getval() cop arg.getval()); \
432 t.name =
"|" + arg.lb + arg.name + arg.rb;
437 tr = (arg.getval()) & arg.mask;
438 t.
r = (tr != 0) ? 1 : 0;
447 t.name =
"&" + arg.lb + arg.name + arg.rb;
453 t.
r = (tr == arg.
mask) ? 1 : 0;
463 t.name =
"^" + arg.lb + arg.name + arg.rb;
470 for (i = 0; i < arg.
h-arg.
l+1; ++
i)
472 t.
r = ((tr & 1) != 0) ? !t.
r : t.
r;
495 dbgmsg(
"Assigning output-reg outside always block.");
497 dbgmsg(
"Assigning non-reg output inside always block.");
502 dbgmsg(
"Assigning inout inside always block.");
506 dbgmsg(
"Assigning to input is not allowed.");
511 dbgmsg(
"Assigning reg outside always block.");
516 dbgmsg(
"Assigning wire inside always block.");
528 glc.setprintassign(0);
538 t.name = lb +
name + rb +
" = " + other.getcatname();
539 if (glc.printassign())
std::cout << glc.getmargin() << t.name <<
";\n" << flush;
541 rval hr, portionr, portionmask, otr;
558 portionr =
rc << shn;
559 portionmask =
mask << shn;
560 host->
set((hr & (~portionmask)) | portionr);
585 glc.setprintassign(1);
598 if (hn.getname().compare(ln.getname()) != 0) bname =
name +
"[" + hn.getname() +
":" + ln.getname() +
"]";
599 else bname =
name +
"[" + hn.getname() +
"]";
601 t.
init(
this, 0, 0, bname.c_str());
612 return (*
this)(
n,
n);
628 if (lb ==
"{") glc.AddIO(lb +
name + rb);
629 else glc.AddIO(
name);
634 dbgmsg(
"Different port length for input argument: declared [" << high <<
":" << low <<
"], passed: [" <<
h <<
":" <<
l <<
"]. ");
653 glc.AddParameter(
name);
654 if (
h ==
l) ln << obname <<
name <<
";\n";
655 else ln << obname <<
"[" << dec <<
h <<
":" <<
l <<
"] " << name <<
";\n";
656 glc.AddDeclarator(ln.str());
680 if (lb ==
"{") glc.AddIO(lb +
name + rb);
681 else glc.AddIO(
name);
686 dbgmsg(
"Different port length for clock argument: declared [" << 0 <<
":" << 0 <<
"], passed: [" <<
h <<
":" <<
l <<
"]. ");
696 glc.AddParameter(
name);
697 if (
h ==
l) ln << obname <<
name <<
";\n";
698 else ln << obname <<
"[" << dec <<
h <<
":" <<
l <<
"] " << name <<
";\n";
699 glc.AddDeclarator(ln.str());
725 if (lb ==
"{") glc.AddIO(lb +
name + rb);
726 else glc.AddIO(
name);
731 dbgmsg(
"Different port length for output argument: declared [" << high <<
":" << low <<
"], passed: [" <<
h <<
":" <<
l <<
"]. ");
735 dbgmsg(
"Using reg as output.");
755 glc.AddParameter(
name);
756 if (
h ==
l) ln << obname <<
name <<
";\n";
757 else ln << obname <<
"[" << dec <<
h <<
":" <<
l <<
"] " << name <<
";\n";
758 glc.AddDeclarator(ln.str());
769 if (
h ==
l) ln <<
"reg " <<
name <<
";\n";
770 else ln <<
"reg [" << dec <<
h <<
":" <<
l <<
"] " << name <<
";\n";
771 glc.AddDeclarator(ln.str());
783 output(0, 0, rname, parent);
791 if (lb ==
"{") glc.AddIO(lb +
name + rb);
792 else glc.AddIO(
name);
797 dbgmsg(
"Different port length for inout argument: declared [" << high <<
":" << low <<
"], passed: [" <<
h <<
":" <<
l <<
"]. ");
817 glc.AddParameter(
name);
818 if (
h ==
l) ln << obname <<
name <<
";\n";
819 else ln << obname <<
"[" << dec <<
h <<
":" <<
l <<
"] " << name <<
";\n";
820 glc.AddDeclarator(ln.str());
832 if (
h ==
l)
cout << glc.getmargin() << obname <<
name <<
";\n" << flush;
833 else std::cout << glc.getmargin() << obname <<
"[" << dec <<
h <<
":" <<
l <<
"] "<<
name <<
";\n" << flush;
856 obname =
"parameter ";
869 cout << glc.getmargin() << obname <<
name << flush;
877 cout <<
" = " << arg.getname() <<
";\n" << flush;
897 if (
h ==
l)
cout << glc.getmargin() << obname <<
name <<
";\n" << flush;
898 else std::cout << glc.getmargin() << obname <<
"[" << dec <<
h <<
":" <<
l <<
"] "<<
name <<
";\n" << flush;
905 ostringstream instnamestream;
906 instnamestream << rname << dec <<
i;
908 wire(high, low, instnamestream.str().c_str());
910 wire(high, low, rname);
917 void memory::reg (
int high,
int low,
int nup,
int ndown,
const char* rname)
933 for (i = 0; i <=
up -
down; ++
i)
941 for (i = 0; i <=
up -
down; ++
i)
948 if (high == low)
std::cout << glc.getmargin() <<
"reg " <<
name <<
" [" << dec <<
up <<
":" <<
down <<
"]" <<
";\n" << flush;
949 else std::cout << glc.getmargin() <<
"reg " <<
"[" << dec << high <<
":" << low <<
"] "<<
name <<
" [" << dec <<
up <<
":" <<
down <<
"]" <<
";\n" << flush;
955 if (
r !=
NULL)
delete []
r;
967 ln =
name +
"[" + i.getname() +
"]";
974 if (ind < down || ind > up)
976 dbgmsg(
"Memory index out of range: index: " << ind <<
", range: [" << up <<
":" << down <<
"]. ");
981 return r[ind - down];
1001 for (
unsigned int i = 0; i <
sizeof(
outreg)/
sizeof(
Signal*); ++
i)
1031 ostringstream instnamestream;
1032 instnamestream << iname << dec <<
index;
1033 instname = instnamestream.str().c_str();
1038 void module::PrintHeader()
1044 newtime = localtime( &aclock );
1045 username = getenv(
"USER");
1046 if (username ==
NULL || strlen(username) < 2) username = getenv(
"USERNAME");
1047 if (username ==
NULL || strlen(username) < 2) username = getenv(
"LOGNAME");
1048 cout <<
"// This Verilog HDL source file was automatically generated" << std::endl;
1049 cout <<
"// by C++ model based on VPP library. Modification of this file" << std::endl;
1050 cout <<
"// is possible, but if you want to keep it in sync with the C++" << std::endl;
1051 cout <<
"// model, please modify the model and re-generate this file." << std::endl;
1052 cout <<
"// VPP library web-page: http://www.phys.ufl.edu/~madorsky/vpp/" << std::endl;
1054 if (username !=
NULL)
1055 cout <<
"// Author : " << username << std::endl;
1056 cout <<
"// File name : " <<
name <<
".v" << std::endl;
1057 cout <<
"// Timestamp : " << asctime(newtime) << std::endl << flush;
1068 cout << glc.getmargin() <<
"(" << glc.PrintIO(
true).c_str() << std::endl << flush;
1069 cout << glc.getmargin() <<
");\n" << flush;
1070 vfile.open (filename.c_str());
1071 outbuf =
std::cout.rdbuf(vfile.rdbuf());
1074 glc.enablemargin(1);
1077 cout << glc.getmargin() <<
"module " <<
name << std::endl << glc.getmargin() <<
"(" << flush;
1088 cout << glc.getmargin() <<
"endmodule\n" << flush;
1102 ln =
"posedge " + arg.getname();
1117 ln =
"negedge " + arg.getname();
1146 ln =
"(" + condition.getname() +
") ? " + iftrue.getname() +
" : " + iffalse.getname();
1150 if (condition.
getbool())
return iftrue;
1151 else return iffalse;
1161 unsigned int lng = hpar - lpar + 1;
1164 mask = (1LL << lng) - 1;
1173 cout <<
"`include " <<
'"' <<
name <<
".v" <<
'"' <<
"\n" << flush;
1192 retname =
name +
"(" + glc.PrintIO(
false) +
")";
1193 vfile.open (filename.c_str());
1194 outbuf =
std::cout.rdbuf(vfile.rdbuf());
1197 glc.enablemargin(1);
1200 cout << glc.getmargin() <<
"function [" << dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n" << flush;
1205 result.setbrackets(
"",
"");
1219 cout << glc.getmargin() <<
"endfunction\n" << flush;
1223 result.setbrackets(
"",
"");
1258 for (i = 0; i < npar; ++
i)
1261 cout << getmargin();
1266 cout << std::endl << getmargin() <<
");\n";
1271 for (i = 0; i < ndecl; ++
i)
1273 cout << glc.getmargin() << decls[
i];
1276 cout <<
"\n" << flush;
1281 string& globcontrol::PrintIO(
bool col)
1289 for (i = 0; i < ndio; ++
i)
1294 outln += getmargin();
1297 if (i < ndio - 1) outln +=
",";
1305 void globcontrol::PrepMargin()
1310 for (i = 0; i < indpos; ++
i)
1317 void globcontrol::AddIO(std::string ln)
1331 sprintf(
constring,
"%d%s", bits, value);
1337 sprintf(
constring,
"%d'd%u", bits, (
unsigned)value);
void init(int, int, const char *)
void reg(int, int, const char *)
void reg(int, int, int, int, const char *)
void makemask(int hpar, int lpar)
void sethlmask(int high, int low, rval imask)
Signal operator()(Signal, Signal)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
void wire(int, int, const char *)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
char constring[RVALS *32+32]
void init(int, int, const char *)
void init(const char *, const char *)
void init(int, int, const char *)
void initreg(int, int, const char *)
Signal ifelse(Signal, Signal, Signal)
void clock(const char *rname)
char * constant(int bits, char *val)
void operator=(Signal arg)
Signal * AddOutReg(Signal arg)
unsigned long long int rval
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Signal & operator[](Signal)
void inout(int, int, const char *)
void output(int, int, const char *)
parameter(const char *rname, Signal arg)
void input(int, int, const char *)