7 char const*
obnames[] = {
"none ",
"reg ",
"wire ",
"input ",
"output ",
"inout ",
"num ",
"temp "};
9 #define dbgmsg(a) std::cerr << a << " Set breakpoint at " << __FILE__ << ":" << __LINE__ << "\n";
53 sscanf(
val.c_str(),
"%d'%c", &
bits, &radix);
58 for (
i = 0;
val[
i] !=
'h' &&
val[
i] !=
'H'; ++
i)
60 for (;
i <
val.length(); ++
i) {
80 dig =
val[
i] -
'a' + 10;
88 dig =
val[
i] -
'A' + 10;
103 sscanf(
val.c_str(),
"%d'%c%d", &
bits, &radix, reinterpret_cast<int*>(&
value));
108 for (
i = 0;
val[
i] !=
'o' &&
val[
i] !=
'O'; ++
i)
110 for (;
i <
val.length(); ++
i) {
137 for (
i = 0;
val[
i] !=
'b' &&
val[
i] !=
'B'; ++
i)
139 for (;
i <
val.length(); ++
i) {
244 string& Signal::getcatname() {
246 catname = lb +
name + rb;
256 #define unop(op, cop) \
257 Signal Signal::op() { \
259 t.name = #cop + lb + name + rb; \
261 t.r = mask & (cop getval()); \
265 #define unop(op, cop) \
266 Signal Signal::op() { \
269 t.r = mask & (cop getval()); \
285 #define binop(op, cop) \
286 Signal Signal::op(Signal arg) { \
288 t.name = lb + name + rb + " " + #cop + " " + arg.lb + arg.name + arg.rb; \
289 printable = arg.printable = 0; \
290 t.r = (getval() cop arg.getval()); \
294 #define binop(op, cop) \
295 Signal Signal::op(Signal arg) { \
298 int aln = arg.h - arg.l; \
299 t.init((ln > aln) ? ln : aln, 0, ""); \
300 t.r = t.mask & (getval() cop arg.getval()); \
312 t.orname = orname +
" or " +
arg.orname;
313 printable =
arg.printable = 0;
317 t.init((ln > aln) ? ln : aln, 0,
"");
319 t.r =
t.mask & (getval() ||
arg.getval());
320 t.change = change ||
arg.change;
334 t.init(
h -
l +
arg.h -
arg.l + 1, 0,
"");
343 #define compop(op, cop) \
344 Signal Signal::op(Signal arg) { \
346 t.name = lb + name + rb + " " + #cop + " " + arg.lb + arg.name + arg.rb; \
347 printable = arg.printable = 0; \
348 t.r = (getval() cop arg.getval()); \
352 #define compop(op, cop) \
353 Signal Signal::op(Signal arg) { \
356 t.r = (getval() cop arg.getval()); \
374 tr = (
arg.getval()) &
arg.mask;
375 t.r = (tr != 0) ? 1 : 0;
388 tr = (
arg.getval()) &
arg.mask;
389 t.r = (tr ==
arg.mask) ? 1 : 0;
403 tr = (
arg.getval()) &
arg.mask;
406 t.r = ((tr & 1) != 0) ? !
t.r :
t.r;
423 dbgmsg(
"Assigning output-reg outside always block.");
425 dbgmsg(
"Assigning non-reg output inside always block.");
430 dbgmsg(
"Assigning inout inside always block.");
434 dbgmsg(
"Assigning to input is not allowed.");
439 dbgmsg(
"Assigning reg outside always block.");
444 dbgmsg(
"Assigning wire inside always block.");
454 glc.setprintassign(0);
463 t.name = lb +
name + rb +
" = " +
other.getcatname();
464 if (
glc.printassign())
467 rval hr, portionr, portionmask, otr;
485 portionr =
rc << shn;
486 portionmask =
mask << shn;
487 host->
set((hr & (~portionmask)) | portionr);
490 if (
ca1 !=
nullptr &&
ca2 !=
nullptr)
510 glc.setprintassign(1);
521 if (hn.getname().compare(ln.getname()) != 0)
522 bname =
name +
"[" + hn.getname() +
":" + ln.getname() +
"]";
524 bname =
name +
"[" + hn.getname() +
"]";
526 t.init(
this, 0, 0, bname.c_str());
528 t.init(
this, (
unsigned)hn.
getval(), (unsigned)ln.
getval(),
"");
556 dbgmsg(
"Different port length for input argument: declared [" <<
high <<
":" <<
low <<
"], passed: [" <<
h <<
":"
575 ln << obname <<
name <<
";\n";
577 ln << obname <<
"[" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n";
578 glc.AddDeclarator(ln.str());
614 dbgmsg(
"Different port length for clock argument: declared [" << 0 <<
":" << 0 <<
"], passed: [" <<
h <<
":" <<
l
627 ln << obname <<
name <<
";\n";
629 ln << obname <<
"[" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n";
630 glc.AddDeclarator(ln.str());
637 if (
rc == 1 &&
r == 0)
641 if (
rc == 0 &&
r == 1)
664 dbgmsg(
"Different port length for output argument: declared [" <<
high <<
":" <<
low <<
"], passed: [" <<
h <<
":"
668 dbgmsg(
"Using reg as output.");
687 ln << obname <<
name <<
";\n";
689 ln << obname <<
"[" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n";
690 glc.AddDeclarator(ln.str());
700 ln <<
"reg " <<
name <<
";\n";
702 ln <<
"reg [" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n";
703 glc.AddDeclarator(ln.str());
726 dbgmsg(
"Different port length for inout argument: declared [" <<
high <<
":" <<
low <<
"], passed: [" <<
h <<
":"
746 ln << obname <<
name <<
";\n";
748 ln << obname <<
"[" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n";
749 glc.AddDeclarator(ln.str());
760 cout <<
glc.getmargin() << obname <<
name <<
";\n" << flush;
762 std::cout <<
glc.getmargin() << obname <<
"[" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n" << flush;
784 obname =
"parameter ";
795 cout <<
glc.getmargin() << obname <<
name << flush;
802 cout <<
" = " <<
arg.getname() <<
";\n" << flush;
821 cout <<
glc.getmargin() << obname <<
name <<
";\n" << flush;
823 std::cout <<
glc.getmargin() << obname <<
"[" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n" << flush;
829 ostringstream instnamestream;
888 ln =
name +
"[" +
i.getname() +
"]";
893 rval ind =
i.getval();
895 if (ind < down || ind >
up) {
896 dbgmsg(
"Memory index out of range: index: " << ind <<
", range: [" <<
up <<
":" <<
down <<
"]. ");
900 return r[ind -
down];
940 ostringstream instnamestream;
941 instnamestream << iname <<
dec <<
index;
942 instname = instnamestream.str().c_str();
947 void module::PrintHeader() {
952 newtime = localtime(&aclock);
958 cout <<
"// This Verilog HDL source file was automatically generated" << std::endl;
959 cout <<
"// by C++ model based on VPP library. Modification of this file" << std::endl;
960 cout <<
"// is possible, but if you want to keep it in sync with the C++" << std::endl;
961 cout <<
"// model, please modify the model and re-generate this file." << std::endl;
962 cout <<
"// VPP library web-page: http://www.phys.ufl.edu/~madorsky/vpp/" << std::endl;
966 cout <<
"// File name : " <<
name <<
".v" << std::endl;
967 cout <<
"// Timestamp : " << asctime(newtime) << std::endl << flush;
976 cout <<
glc.getmargin() <<
"(" <<
glc.PrintIO(
true).c_str() << std::endl << flush;
977 cout <<
glc.getmargin() <<
");\n" << flush;
985 cout <<
glc.getmargin() <<
"module " <<
name << std::endl <<
glc.getmargin() <<
"(" << flush;
995 cout <<
glc.getmargin() <<
"endmodule\n" << flush;
1008 ln =
"posedge " +
arg.getname();
1009 t.init(
NULL, 0, 0, ln.c_str());
1011 t.init(
nullptr, 0, 0,
"");
1013 if (
arg.getposedge())
1015 t.setchange(
arg.getposedge());
1023 ln =
"negedge " +
arg.getname();
1024 t.init(
NULL, 0, 0, ln.c_str());
1026 t.init(
nullptr, 0, 0,
"");
1028 if (
arg.getnegedge())
1030 t.setchange(
arg.getnegedge());
1048 ln =
"(" +
condition.getname() +
") ? " + iftrue.getname() +
" : " + iffalse.getname();
1063 unsigned int lng = hpar - lpar + 1;
1074 cout <<
"`include " <<
'"' <<
name <<
".v" <<
'"' <<
"\n" << flush;
1089 retname =
name +
"(" +
glc.PrintIO(
false) +
")";
1091 outbuf =
std::cout.rdbuf(vfile.rdbuf());
1094 glc.enablemargin(1);
1097 cout <<
glc.getmargin() <<
"function [" <<
dec <<
h <<
":" <<
l <<
"] " <<
name <<
";\n" << flush;
1102 result.setbrackets(
"",
"");
1114 cout <<
glc.getmargin() <<
"endfunction\n" << flush;
1118 result.setbrackets(
"",
"");
1144 void globcontrol::Print() {
1149 for (
i = 0;
i < npar; ++
i) {
1151 cout << getmargin();
1157 cout << std::endl << getmargin() <<
");\n";
1162 for (
i = 0;
i < ndecl; ++
i) {
1163 cout <<
glc.getmargin() << decls[
i];
1166 cout <<
"\n" << flush;
1169 string& globcontrol::PrintIO(
bool col) {
1176 for (
i = 0;
i < ndio; ++
i) {
1179 outln += getmargin();
1192 void globcontrol::PrepMargin() {
1195 for (
i = 0;
i < indpos; ++
i) {