CMS 3D CMS Logo

vlib.cc
Go to the documentation of this file.
1 // Alexander Madorsky, University of Florida/Physics.
2 
4 
6 
7 char const* obnames[] = {"none ", "reg ", "wire ", "input ", "output ", "inout ", "num ", "temp "};
8 
9 #define dbgmsg(a) std::cerr << a << " Set breakpoint at " << __FILE__ << ":" << __LINE__ << "\n";
10 
11 // Signal class --------------------------------------------------------------------------
12 
14 #ifdef VGEN
15  name = "";
16  orname = "";
17  obname = "";
18  lb = "(";
19  rb = ")";
20 #endif
21 
22  outhost = host = outreg = ca1 = ca2 = nullptr;
23  inited = printable = r = rc = l = pedge = nedge = change = alwaysn = mode = 0;
24  h = 8 * Sizeofrval - 1;
25  mask = (rval)(-1);
26  hostl = -1;
27 }
28 
30 
32  create();
33 #ifdef VGEN
34  ostringstream sval;
35  sval << dec << bits << "'d" << value;
36  Signal::init(bits - 1, 0, sval.str().c_str());
37 #else
38  Signal::init(bits - 1, 0, "");
39 #endif
40  r = rc = value & mask;
41 }
42 
43 Signal::Signal(const char* sval) {
44  create();
45  mode = mnum;
46  std::string val = sval;
47  int bits;
48  unsigned int i;
49  char radix;
50  rval value = 0;
51  int dig;
52 
53  sscanf(val.c_str(), "%d'%c", &bits, &radix);
54  switch (radix) {
55  case 'h':
56  case 'H':
57  // sscanf (val.c_str(), "%d'%c%x", &bits, &radix, &value);
58  for (i = 0; val[i] != 'h' && val[i] != 'H'; ++i)
59  ;
60  for (; i < val.length(); ++i) {
61  switch (val[i]) {
62  case '0':
63  case '1':
64  case '2':
65  case '3':
66  case '4':
67  case '5':
68  case '6':
69  case '7':
70  case '8':
71  case '9':
72  dig = val[i] - '0';
73  break;
74  case 'a':
75  case 'b':
76  case 'c':
77  case 'd':
78  case 'e':
79  case 'f':
80  dig = val[i] - 'a' + 10;
81  break;
82  case 'A':
83  case 'B':
84  case 'C':
85  case 'D':
86  case 'E':
87  case 'F':
88  dig = val[i] - 'A' + 10;
89  break;
90  default:
91  dig = -1;
92  break;
93  }
94  if (dig >= 0) {
95  value = value << 4;
96  value = value | dig;
97  }
98  }
99 
100  break;
101  case 'd':
102  case 'D':
103  sscanf(val.c_str(), "%d'%c%d", &bits, &radix, reinterpret_cast<int*>(&value));
104  break;
105  case 'o':
106  case 'O':
107  // sscanf (val.c_str(), "%d'%c%o", &bits, &radix, &value);
108  for (i = 0; val[i] != 'o' && val[i] != 'O'; ++i)
109  ;
110  for (; i < val.length(); ++i) {
111  switch (val[i]) {
112  case '0':
113  case '1':
114  case '2':
115  case '3':
116  case '4':
117  case '5':
118  case '6':
119  case '7':
120  dig = val[i] - '0';
121  break;
122  default:
123  dig = -1;
124  break;
125  }
126  if (dig >= 0) {
127  value = value << 3;
128  value = value | dig;
129  }
130  }
131 
132  break;
133 
134  case 'b':
135  case 'B':
136 
137  for (i = 0; val[i] != 'b' && val[i] != 'B'; ++i)
138  ;
139  for (; i < val.length(); ++i) {
140  switch (val[i]) {
141  case '0':
142  value = value << 1;
143  break;
144  case '1':
145  value = value << 1;
146  value = value | 1;
147  break;
148  }
149  }
150  break;
151  }
152  Signal::init(bits - 1, 0, val.c_str());
153  rc = value & mask;
154  r = rc;
155 }
156 
158  create();
159  mode = mnum;
160 #ifdef VGEN
161  ostringstream ln;
162  ln << dec << n;
163  init(8 * Sizeofrval - 1, 0, ln.str().c_str());
164 #else
165  init(8 * Sizeofrval - 1, 0, "");
166 #endif
167  inited = 0;
168  rc = n;
169  r = n;
170 }
171 
173  create();
174  mode = mnum;
175 #ifdef VGEN
176  ostringstream ln;
177  ln << dec << n;
178  init(Sizeofrval * 8 - 1, 0, ln.str().c_str());
179 #else
180  init(Sizeofrval * 8 - 1, 0, "");
181 #endif
182  inited = 0;
183  r = (rval)n;
184  rc = r;
185 }
186 
187 Signal::Signal(unsigned int n) {
188  create();
189  mode = mnum;
190 #ifdef VGEN
191  ostringstream ln;
192  ln << dec << n;
193  init(Sizeofrval * 8 - 1, 0, ln.str().c_str());
194 #else
195  init(Sizeofrval * 8 - 1, 0, "");
196 #endif
197  inited = 0;
198  r = (rval)n;
199  rc = r;
200 }
201 
203  mask = (1LL << (h - l + 1)) - 1LL;
204  if (mask == 0LL)
205  mask = ~mask;
206 }
207 
208 void Signal::init(int high, int low, const char* rname) {
209 #ifdef VGEN
210  name = rname;
211  orname = rname;
212  lb = "";
213  rb = "";
214 #endif
215  if (!inited) {
216  h = high;
217  l = low;
218  makemask();
219  inited = 1;
220  }
221  source = this;
222 }
223 
224 void Signal::init(Signal* shost, int high, int low, const char* rname) {
225  host = shost;
226 #ifdef VGEN
227  name = rname;
228  orname = rname;
229  lb = "";
230  rb = "";
231 #endif
232  h = high;
233  l = low;
234  makemask();
235  source = this;
236  if (host) {
237  rc = (host->getr() >> (l - host->getl())) & mask;
238  r = rc;
239  }
240  change = pedge = nedge = 0;
241 }
242 
243 #ifdef VGEN
244 string& Signal::getcatname() {
245  if (lb[0] == '{')
246  catname = lb + name + rb;
247  else
248  catname = name;
249  return catname;
250 }
251 #endif
252 
253 // unary operators -------------------------------------
254 
255 #ifdef VGEN
256 #define unop(op, cop) \
257  Signal Signal::op() { \
258  Signal t; \
259  t.name = #cop + lb + name + rb; \
260  printable = 0; \
261  t.r = mask & (cop getval()); \
262  return t; \
263  }
264 #else
265 #define unop(op, cop) \
266  Signal Signal::op() { \
267  Signal t; \
268  t.init(h, l, ""); \
269  t.r = mask & (cop getval()); \
270  return t; \
271  }
272 #endif
273 
274 unop(operator!, !) unop(operator~, ~)
275 
277 #ifdef VGEN
278  printable = 0;
279 #endif
280  return this;
281 }
282 
283 // binary operators ------------------------------------
284 #ifdef VGEN
285 #define binop(op, cop) \
286  Signal Signal::op(Signal arg) { \
287  Signal t; \
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()); \
291  return t; \
292  }
293 #else
294 #define binop(op, cop) \
295  Signal Signal::op(Signal arg) { \
296  Signal t; \
297  int ln = h - l; \
298  int aln = arg.h - arg.l; \
299  t.init((ln > aln) ? ln : aln, 0, ""); \
300  t.r = t.mask & (getval() cop arg.getval()); \
301  return t; \
302  }
303 #endif
304 
305 binop(operator+, +) binop(operator-, -) binop(operator*, *) binop(operator/, /) binop(operator%, %) binop(operator^, ^)
307 
309  Signal t;
310 #ifdef VGEN
311  t.name = lb + name + rb + " || " + arg.lb + arg.name + arg.rb;
312  t.orname = orname + " or " + arg.orname;
313  printable = arg.printable = 0;
314 #else
315  int ln = h - l;
316  int aln = arg.h - arg.l;
317  t.init((ln > aln) ? ln : aln, 0, "");
318 #endif
319  t.r = t.mask & (getval() || arg.getval());
320  t.change = change || arg.change;
321  return t;
322 }
323 
325  Signal t;
326 #ifdef VGEN
327  t.name = name + ", " + arg.name;
328  t.lb = "{";
329  t.rb = "}";
330  printable = arg.printable = 0;
331 #else
332  t.ca1 = this;
333  t.ca2 = arg.source;
334  t.init(h - l + arg.h - arg.l + 1, 0, "");
335 #endif
336  t.r = (((getval() << (arg.h - arg.l + 1)) & (~(arg.mask))) | arg.getval()) & t.mask;
337  return t;
338 }
339 
340 // comparison operators ---------------------------------------------------
341 
342 #ifdef VGEN
343 #define compop(op, cop) \
344  Signal Signal::op(Signal arg) { \
345  Signal t; \
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()); \
349  return t; \
350  }
351 #else
352 #define compop(op, cop) \
353  Signal Signal::op(Signal arg) { \
354  Signal t; \
355  t.init(""); \
356  t.r = (getval() cop arg.getval()); \
357  return t; \
358  }
359 #endif
360 
361 compop(operator>, >) compop(operator<, <) compop(operator<=, <=) compop(operator>=, >=) compop(operator==, ==)
363 
364  // reduction operators --------------------------------------------------------------
366  Signal t;
367  rval tr;
368 #ifdef VGEN
369  t.name = "|" + arg.lb + arg.name + arg.rb;
370  arg.printable = 0;
371 #else
372  t.init("");
373 #endif
374  tr = (arg.getval()) & arg.mask;
375  t.r = (tr != 0) ? 1 : 0;
376  return t;
377 }
378 
380  Signal t;
381  rval tr;
382 #ifdef VGEN
383  t.name = "&" + arg.lb + arg.name + arg.rb;
384  arg.printable = 0;
385 #else
386  t.init("");
387 #endif
388  tr = (arg.getval()) & arg.mask;
389  t.r = (tr == arg.mask) ? 1 : 0;
390  return t;
391 }
392 
394  Signal t;
395  rval tr;
396  int i;
397 #ifdef VGEN
398  t.name = "^" + arg.lb + arg.name + arg.rb;
399  arg.printable = 0;
400 #else
401  t.init("");
402 #endif
403  tr = (arg.getval()) & arg.mask;
404  t.r = 0;
405  for (i = 0; i < arg.h - arg.l + 1; ++i) {
406  t.r = ((tr & 1) != 0) ? !t.r : t.r;
407  tr = tr >> 1;
408  }
409  t.r = t.r & 1;
410  return t;
411 }
412 
413 // blocking assignment operator -----------------------------------------------------
414 
415 rval Signal::getval() { return (getalwaysn() == glc.getalwaysn()) ? rc : r; }
416 
418 #ifndef VGEN
419 #ifdef _VDEBUG
420  switch (mode) {
421  case moutput:
422  if (glc.getalwaysn() == -1 && outreg != NULL)
423  dbgmsg("Assigning output-reg outside always block.");
424  if (glc.getalwaysn() != -1 && outreg == NULL)
425  dbgmsg("Assigning non-reg output inside always block.");
426  break;
427 
428  case minout:
429  if (glc.getalwaysn() != -1)
430  dbgmsg("Assigning inout inside always block.");
431  break;
432 
433  case minput:
434  dbgmsg("Assigning to input is not allowed.");
435  return other;
436 
437  case mreg:
438  if (glc.getalwaysn() == -1)
439  dbgmsg("Assigning reg outside always block.");
440  break;
441 
442  case mwire:
443  if (glc.getalwaysn() != -1)
444  dbgmsg("Assigning wire inside always block.");
445  break;
446  }
447 #endif
448 #endif
449  return asgn(other);
450 }
451 
453 #ifdef VGEN
454  glc.setprintassign(0);
455 #endif
456  return asgn(other);
457 }
458 
460  Signal t;
461 
462 #ifdef VGEN
463  t.name = lb + name + rb + " = " + other.getcatname();
464  if (glc.printassign())
465  std::cout << glc.getmargin() << t.name << ";\n" << flush;
466 #endif
467  rval hr, portionr, portionmask, otr;
468  int shn;
469 
470  otr = other.getval() & mask;
471 
472  if (otr != r) {
474  glc.setchange(1);
475  }
476 
477  rc = otr;
478  if (host) // is this a portion of the other register?
479  {
480  hr = host->rc;
481  if (hostl > 0)
482  shn = (hostl - host->getl());
483  else
484  shn = (l - host->getl());
485  portionr = rc << shn;
486  portionmask = mask << shn;
487  host->set((hr & (~portionmask)) | portionr);
488  }
489 
490  if (ca1 != nullptr && ca2 != nullptr) // is this a concatenation of the two registers?
491  {
492  ca2->set(other);
493  ca1->set(other >> (ca2->h - ca2->l + 1));
494  }
495  if (outhost != nullptr && outhost != this && (mode == moutput || mode == minout)) {
496  outhost->set(other);
497  }
498  if (outreg) {
499  outreg->set(other);
500  }
501 
502  t.h = h;
503  t.l = l;
504  t.mask = mask;
505  t.pedge = pedge;
506  t.nedge = nedge;
507  t.change = change;
508  t.r = rc;
509 #ifdef VGEN
510  glc.setprintassign(1);
511 #endif
512  return t;
513 }
514 
515 // bit selection operator -----------------------------------------------
516 
518  Signal t;
519 #ifdef VGEN
520  string bname;
521  if (hn.getname().compare(ln.getname()) != 0)
522  bname = name + "[" + hn.getname() + ":" + ln.getname() + "]";
523  else
524  bname = name + "[" + hn.getname() + "]";
525  hn.printable = ln.printable = 0;
526  t.init(this, 0, 0, bname.c_str());
527 #else
528  t.init(this, (unsigned)hn.getval(), (unsigned)ln.getval(), "");
529 #endif
530  t.rc = (getval() >> (t.l - l)) & t.mask;
531  t.r = t.rc;
532  return t;
533 }
534 
535 Signal Signal::operator()(Signal n) { return (*this)(n, n); }
536 
537 // insertion operator ---------------------------------------------------
538 std::ostream& operator<<(std::ostream& stream, Signal s) {
539  stream << s.getr();
540  s.setprintable(0);
541  return stream;
542 }
543 
544 // input -----------------------------------------------------------------------------
545 void Signal::input(int high, int low, const char* rname) {
546 #ifdef VGEN
547  if (lb == "{")
548  glc.AddIO(lb + name + rb);
549  else
550  glc.AddIO(name);
551 #else
552 #ifdef _VDEBUG
553  if (h - l != high - low &&
554  inited) // inited is analysed in case the passed parameter is a temp var. Actually, every operator should return temp with the proper mask,h,l inherited from operands
555  {
556  dbgmsg("Different port length for input argument: declared [" << high << ":" << low << "], passed: [" << h << ":"
557  << l << "]. ");
558  }
559 #endif
560 #endif
562  if (high >= low) {
563  h = high;
564  l = low;
565  } else {
566  h = low;
567  l = high;
568  }
569  mode = minput;
570 #ifdef VGEN
571  obname = obnames[mode];
572  ostringstream ln;
573  glc.AddParameter(name);
574  if (h == l)
575  ln << obname << name << ";\n";
576  else
577  ln << obname << "[" << dec << h << ":" << l << "] " << name << ";\n";
578  glc.AddDeclarator(ln.str());
579  printable = 0;
580 #else
581  outreg = glc.getparent()->AddOutReg((Signal)(*this));
582  r = r & outreg->getmask();
583  if (outreg->getr() != r) {
584  change = 1;
585  glc.getparent()->setchange(1);
586  if (r == 1 && outreg->getr() == 0)
587  pedge = 1;
588  else
589  pedge = 0;
590  if (r == 0 && outreg->getr() == 1)
591  nedge = 1;
592  else
593  nedge = 0;
594  } else
595  change = pedge = nedge = 0;
596  outreg->setr(r);
597  outreg->setrc(r);
598  outhost = host = nullptr;
599 #endif
600 }
601 
602 // clock input --------------------------------------------------------------
603 void Signal::clock(const char* rname) {
604 #ifdef VGEN
605  if (lb == "{")
606  glc.AddIO(lb + name + rb);
607  else
608  glc.AddIO(name);
609 #else
610 #ifdef _VDEBUG
611  if (h - l != 0 &&
612  inited) // inited is analysed in case the passed parameter is a temp var. Actually, every operator should return temp with the proper mask,h,l inherited from operands
613  {
614  dbgmsg("Different port length for clock argument: declared [" << 0 << ":" << 0 << "], passed: [" << h << ":" << l
615  << "]. ");
616  }
617 #endif
618 #endif
619  Signal::init(0, 0, rname);
620  h = l = 0;
621  mode = minput;
622 #ifdef VGEN
623  obname = obnames[mode];
624  ostringstream ln;
625  glc.AddParameter(name);
626  if (h == l)
627  ln << obname << name << ";\n";
628  else
629  ln << obname << "[" << dec << h << ":" << l << "] " << name << ";\n";
630  glc.AddDeclarator(ln.str());
631  printable = 0;
632 #else
633  outreg = glc.getparent()->AddOutReg((Signal)(*this));
634  if (rc != r) {
635  change = 1;
636  glc.getparent()->setchange(1);
637  if (rc == 1 && r == 0)
638  pedge = 1;
639  else
640  pedge = 0;
641  if (rc == 0 && r == 1)
642  nedge = 1;
643  else
644  nedge = 0;
645  } else
646  change = pedge = nedge = 0;
647  outreg->setr(r);
648  outreg->setrc(r);
649  outhost = host = nullptr;
650 #endif
651 }
652 
653 // output -----------------------------------------------------------------------------
654 
655 void Signal::output(int high, int low, const char* rname) {
656 #ifdef VGEN
657  if (lb == "{")
658  glc.AddIO(lb + name + rb);
659  else
660  glc.AddIO(name);
661 #else
662 #ifdef _VDEBUG
663  if (h - l != high - low) {
664  dbgmsg("Different port length for output argument: declared [" << high << ":" << low << "], passed: [" << h << ":"
665  << l << "]. ");
666  }
667  if (mode == mreg) {
668  dbgmsg("Using reg as output.");
669  }
670 #endif
671 #endif
672  hostl = l;
674  if (high >= low) {
675  h = high;
676  l = low;
677  } else {
678  h = low;
679  l = high;
680  }
681  mode = moutput;
682 #ifdef VGEN
683  obname = obnames[mode];
684  ostringstream ln;
685  glc.AddParameter(name);
686  if (h == l)
687  ln << obname << name << ";\n";
688  else
689  ln << obname << "[" << dec << h << ":" << l << "] " << name << ";\n";
690  glc.AddDeclarator(ln.str());
691  printable = 0;
692 #endif
693 }
694 
695 void Signal::output(int high, int low, const char* rname, module* parent) {
696  output(high, low, rname);
697 #ifdef VGEN
698  ostringstream ln;
699  if (h == l)
700  ln << "reg " << name << ";\n";
701  else
702  ln << "reg [" << dec << h << ":" << l << "] " << name << ";\n";
703  glc.AddDeclarator(ln.str());
704 #else
705  outreg = parent->AddOutReg((Signal)(*this));
706  setr(outreg->getr());
710 #endif
711 }
712 
713 void Signal::output(const char* rname, module* parent) { output(0, 0, rname, parent); }
714 
715 // inout -----------------------------------------------------------------------------
716 
717 void Signal::inout(int high, int low, const char* rname) {
718 #ifdef VGEN
719  if (lb == "{")
720  glc.AddIO(lb + name + rb);
721  else
722  glc.AddIO(name);
723 #else
724 #ifdef _VDEBUG
725  if (h - l != high - low) {
726  dbgmsg("Different port length for inout argument: declared [" << high << ":" << low << "], passed: [" << h << ":"
727  << l << "]. ");
728  }
729 #endif
730 #endif
731  hostl = l;
733  if (high >= low) {
734  h = high;
735  l = low;
736  } else {
737  h = low;
738  l = high;
739  }
740  mode = minout;
741 #ifdef VGEN
742  obname = obnames[mode];
743  ostringstream ln;
744  glc.AddParameter(name);
745  if (h == l)
746  ln << obname << name << ";\n";
747  else
748  ln << obname << "[" << dec << h << ":" << l << "] " << name << ";\n";
749  glc.AddDeclarator(ln.str());
750  printable = 0;
751 #endif
752 }
753 
754 // reg -------------------------------------------------------------------------------
755 
756 void Signal::reg(int high, int low, const char* rname) {
757  initreg(high, low, rname);
758 #ifdef VGEN
759  if (h == l)
760  cout << glc.getmargin() << obname << name << ";\n" << flush;
761  else
762  std::cout << glc.getmargin() << obname << "[" << dec << h << ":" << l << "] " << name << ";\n" << flush;
763 #endif
764 }
765 
766 void Signal::initreg(int high, int low, const char* rname) {
768  mode = mreg;
769 #ifdef VGEN
770  obname = obnames[mode];
771 #endif
772  change = (r != rc);
773  if (change)
774  glc.getparent()->setchange(1);
775  pedge = (rc == 1 && r == 0);
776  nedge = (rc == 0 && r == 1);
777  r = rc;
778 }
779 
780 // parameter class -------------------------------------------------------------------------------
781 
783 #ifdef VGEN
784  obname = "parameter ";
785 #endif
786  init(Sizeofrval * 8 - 1, 0, rname);
787  operator=(arg);
788 }
789 
790 void parameter::init(int h, int l, const char* rname) {
791  Signal::init(h, l, rname);
792  change = pedge = nedge = 0;
793 
794 #ifdef VGEN
795  cout << glc.getmargin() << obname << name << flush;
796 #endif
797 }
798 
800  r = arg.getr();
801 #ifdef VGEN
802  cout << " = " << arg.getname() << ";\n" << flush;
803 #endif
804 }
805 
806 // wire -------------------------------------------------------------------------------
807 
808 void Signal::wire(int high, int low, const char* rname) {
810  mode = mwire;
811  outhost = this;
812  change = (r != rc);
813  if (change && glc.getparent())
814  glc.getparent()->setchange(1);
815  pedge = (rc == 1 && r == 0);
816  nedge = (rc == 0 && r == 1);
817  r = rc;
818 #ifdef VGEN
819  obname = obnames[mode];
820  if (h == l)
821  cout << glc.getmargin() << obname << name << ";\n" << flush;
822  else
823  std::cout << glc.getmargin() << obname << "[" << dec << h << ":" << l << "] " << name << ";\n" << flush;
824 #endif
825 }
826 
827 void Signal::wire(int high, int low, const char* rname, int i) {
828 #ifdef VGEN
829  ostringstream instnamestream;
830  instnamestream << rname << dec << i;
831  // init(high, low, instnamestream.str().c_str());
832  wire(high, low, instnamestream.str().c_str());
833 #else
834  wire(high, low, rname);
835 #endif
836 }
837 
838 // memory class -----------------------------------------------------------------------------
839 
840 void memory::reg(int high, int low, int nup, int ndown, const char* rname) {
841  int i;
842  if (nup > ndown) {
843  up = nup;
844  down = ndown;
845  } else {
846  up = ndown;
847  down = nup;
848  }
849  if (r == nullptr) {
850  r = new Signal[up - down + 1];
851  for (i = 0; i <= up - down; ++i) {
852  r[i].initreg(high, low, "");
853  r[i].setr(0);
854  }
855  } else {
856  for (i = 0; i <= up - down; ++i) {
857  r[i].initreg(high, low, "");
858  }
859  }
860 #ifdef VGEN
861  name = rname;
862  if (high == low)
863  std::cout << glc.getmargin() << "reg " << name << " [" << dec << up << ":" << down << "]"
864  << ";\n"
865  << flush;
866  else
867  std::cout << glc.getmargin() << "reg "
868  << "[" << dec << high << ":" << low << "] " << name << " [" << dec << up << ":" << down << "]"
869  << ";\n"
870  << flush;
871 #endif
872 }
873 
875  if (r != nullptr)
876  delete[] r;
877  r = nullptr;
878 }
879 
880 #ifdef VGEN
882 #else
884 #endif
885 {
886 #ifdef VGEN
887  string ln;
888  ln = name + "[" + i.getname() + "]";
889  r[0].setname(ln);
890  r[0].setorname(ln);
891  return r[0];
892 #else
893  rval ind = i.getval();
894 #ifdef _VDEBUG
895  if (ind < down || ind > up) {
896  dbgmsg("Memory index out of range: index: " << ind << ", range: [" << up << ":" << down << "]. ");
897  return r[down];
898  } else
899 #endif
900  return r[ind - down];
901 #endif
902 }
903 
904 // module class -------------------------------------------------------------------------
905 
907  for (unsigned int i = 0; i < sizeof(outreg) / sizeof(Signal*); ++i)
908  outreg[i] = nullptr;
909  outregn = 0;
910  runperiod = nullptr;
911 }
912 
914 
916  for (unsigned int i = 0; i < sizeof(outreg) / sizeof(Signal*); ++i) {
917  if (outreg[i] != nullptr)
918  delete outreg[i];
919  }
920 }
921 
922 void module::init(const char* mname, const char* iname) {
923 #ifdef VGEN
924  name = mname;
925  instname = iname;
926 #endif
927 }
928 
929 void module::init(const char* mname, const char* iname, module* fixt) {
930 #ifdef VGEN
931  name = mname;
932  instname = iname;
933 #endif
934  tfixt = fixt;
935 }
936 
937 void module::init(const char* mname, const char* iname, int index) {
938 #ifdef VGEN
939  name = mname;
940  ostringstream instnamestream;
941  instnamestream << iname << dec << index;
942  instname = instnamestream.str().c_str();
943 #endif
944 }
945 
946 #ifdef VGEN
947 void module::PrintHeader() {
948  char* username = NULL;
949  struct tm* newtime;
950  time_t aclock;
951  time(&aclock);
952  newtime = localtime(&aclock);
953  username = std::getenv("USER");
954  if (username == NULL || strlen(username) < 2)
955  username = std::getenv("USERNAME");
956  if (username == NULL || strlen(username) < 2)
957  username = std::getenv("LOGNAME");
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;
963  cout << std::endl;
964  if (username != NULL)
965  cout << "// Author : " << username << std::endl;
966  cout << "// File name : " << name << ".v" << std::endl;
967  cout << "// Timestamp : " << asctime(newtime) << std::endl << flush;
968 }
969 #endif
970 
972  switchn = 0;
973 #ifdef VGEN
974  string filename = name + ".v";
975  cout << glc.getmargin() << name << " " << instname << std::endl << flush;
976  cout << glc.getmargin() << "(" << glc.PrintIO(true).c_str() << std::endl << flush;
977  cout << glc.getmargin() << ");\n" << flush;
978  vfile.open(filename.c_str());
979  outbuf = std::cout.rdbuf(vfile.rdbuf());
980  OuterIndPos = glc.getpos();
981  oldenmarg = glc.getenablemargin();
982  glc.enablemargin(1);
983  glc.setpos(0);
984  PrintHeader();
985  cout << glc.getmargin() << "module " << name << std::endl << glc.getmargin() << "(" << flush;
986  glc.setfunction(0);
987  glc.Print();
988  glc.setFileOpen(1);
989 #endif
990 }
991 
993 #ifdef VGEN
994  glc.Outdent();
995  cout << glc.getmargin() << "endmodule\n" << flush;
996  glc.setpos(OuterIndPos);
997  cout.rdbuf(outbuf);
998  vfile.close();
999  glc.enablemargin(oldenmarg);
1000 #endif
1001  outregn = 0;
1002 }
1003 
1005  Signal t;
1006 #ifdef VGEN
1007  string ln = "";
1008  ln = "posedge " + arg.getname();
1009  t.init(NULL, 0, 0, ln.c_str());
1010 #else
1011  t.init(nullptr, 0, 0, "");
1012 #endif
1013  if (arg.getposedge())
1014  glc.setce(0);
1015  t.setchange(arg.getposedge());
1016  return t;
1017 }
1018 
1020  Signal t;
1021 #ifdef VGEN
1022  string ln = "";
1023  ln = "negedge " + arg.getname();
1024  t.init(NULL, 0, 0, ln.c_str());
1025 #else
1026  t.init(nullptr, 0, 0, "");
1027 #endif
1028  if (arg.getnegedge())
1029  glc.setce(0);
1030  t.setchange(arg.getnegedge());
1031  return t;
1032 }
1033 
1035  if (outreg[outregn] == nullptr) {
1036  outreg[outregn] = new Signal;
1037  outreg[outregn]->setr(0);
1038  }
1039  outreg[outregn]->reg(arg.geth(), arg.getl(), "");
1040  outregn++;
1041  return outreg[outregn - 1];
1042 }
1043 
1045 #ifdef VGEN
1046  Signal t;
1047  string ln;
1048  ln = "(" + condition.getname() + ") ? " + iftrue.getname() + " : " + iffalse.getname();
1049  t.setname(ln);
1050  return t;
1051 #else
1052  if (condition.getbool())
1053  return iftrue;
1054  else
1055  return iffalse;
1056 #endif
1057 }
1058 
1059 // function class -------------------------------------------------------------
1060 
1061 void function::makemask(int hpar, int lpar) {
1062  //int i;
1063  unsigned int lng = hpar - lpar + 1;
1064 
1065  if (lng < Sizeofrval * 8)
1066  mask = (1LL << lng) - 1;
1067  else
1068  mask = (rval)(-1);
1069 }
1070 
1071 void function::init(int high, int low, const char* rname) {
1072 #ifdef VGEN
1073  name = rname;
1074  cout << "`include " << '"' << name << ".v" << '"' << "\n" << flush;
1075 #endif
1076  if (high >= low) {
1077  h = high;
1078  l = low;
1079  } else {
1080  h = low;
1081  l = high;
1082  }
1083  makemask(h, l);
1084 }
1085 
1087 #ifdef VGEN
1088  string filename = name + ".v";
1089  retname = name + "(" + glc.PrintIO(false) + ")";
1090  vfile.open(filename.c_str());
1091  outbuf = std::cout.rdbuf(vfile.rdbuf());
1092  OuterIndPos = glc.getpos();
1093  oldenmarg = glc.getenablemargin();
1094  glc.enablemargin(1);
1095  glc.setpos(0);
1096  PrintHeader();
1097  cout << glc.getmargin() << "function [" << dec << h << ":" << l << "] " << name << ";\n" << flush;
1098  glc.setfunction(1);
1099  glc.Print();
1100  glc.setFileOpen(1);
1101  result.setname(name);
1102  result.setbrackets("", "");
1103 #endif
1104  switchn = 0;
1105  OldChange = glc.getchange();
1106 }
1107 
1109  result.sethlmask(h, l, mask);
1110  result.setr(result.getr() & mask);
1112 #ifdef VGEN
1113  glc.Outdent();
1114  cout << glc.getmargin() << "endfunction\n" << flush;
1115  glc.setpos(OuterIndPos);
1116  cout.rdbuf(outbuf);
1117  result.setname(retname);
1118  result.setbrackets("", "");
1119  vfile.close();
1120  glc.enablemargin(oldenmarg);
1121 #endif
1122  outregn = 0;
1123 }
1124 
1125 // globcontrol class --------------------------------------------------------------------
1126 
1128 #ifdef VGEN
1129  nomargin = 0;
1130  ndio = 0;
1131  npar = 0;
1132  ndecl = 0;
1133  indpos = 0;
1134  pa = 1;
1135  zeromargin = "";
1136  VFileOpen = 0;
1137 #endif
1138  alwayscnt = -1;
1139  alwaysn = 1;
1140  change = 0;
1141 }
1142 
1143 #ifdef VGEN
1144 void globcontrol::Print() {
1145  int i;
1146 
1147  if (functiondecl == 0) {
1148  Indent();
1149  for (i = 0; i < npar; ++i) {
1150  cout << std::endl;
1151  cout << getmargin();
1152  cout << pars[i];
1153  if (i != npar - 1)
1154  std::cout << ",";
1155  }
1156  Outdent();
1157  cout << std::endl << getmargin() << ");\n";
1158  }
1159  Indent();
1160  cout << "\n";
1161 
1162  for (i = 0; i < ndecl; ++i) {
1163  cout << glc.getmargin() << decls[i];
1164  }
1165  npar = ndecl = 0;
1166  cout << "\n" << flush;
1167 }
1168 
1169 string& globcontrol::PrintIO(bool col) {
1170  int i;
1171 
1172  if (col)
1173  Indent();
1174  outln = "";
1175  if (ndio > 0) {
1176  for (i = 0; i < ndio; ++i) {
1177  if (col) {
1178  outln += "\n";
1179  outln += getmargin();
1180  }
1181  outln += dios[i];
1182  if (i < ndio - 1)
1183  outln += ",";
1184  }
1185  }
1186  ndio = 0;
1187  if (col)
1188  Outdent();
1189  return outln;
1190 }
1191 
1192 void globcontrol::PrepMargin() {
1193  int i;
1194  margin = "";
1195  for (i = 0; i < indpos; ++i) {
1196  margin += " ";
1197  }
1198 }
1199 
1200 void globcontrol::AddIO(std::string ln) {
1201  dios[ndio] = ln;
1202  ndio++;
1203 }
1204 #endif
1205 
1207 
1208 char* globcontrol::constant(int bits, char* value) {
1209  sprintf(constring, "%d%s", bits, value);
1210  return constring;
1211 }
1212 
1214  sprintf(constring, "%d'd%u", bits, (unsigned)value);
1215  return constring;
1216 }
Signal::operator()
Signal operator()(Signal, Signal)
Definition: vlib.cc:517
module::init
void init(const char *, const char *)
Definition: vlib.cc:922
vlib.h
ror
Signal ror(Signal arg)
Definition: vlib.cc:365
Signal::pedge
int pedge
Definition: vlib.h:158
Signal::host
Signal * host
Definition: vlib.h:155
mps_fire.i
i
Definition: mps_fire.py:355
Signal::asgn
Signal asgn(Signal)
Definition: vlib.cc:459
muonRPCDigis_cfi.Signal
Signal
Definition: muonRPCDigis_cfi.py:29
Signal::setr
void setr(rval rv)
Definition: vlib.h:57
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
Signal::printable
int printable
Definition: vlib.h:164
Signal::inout
void inout(int, int, const char *)
Definition: vlib.cc:717
globcontrol::getalwaysn
int getalwaysn()
Definition: vlib.h:328
Signal::setalwaysn
void setalwaysn(int n)
Definition: vlib.h:72
Signal::outhost
Signal * outhost
Definition: vlib.h:160
memory::down
int down
Definition: vlib.h:195
operator<<
std::ostream & operator<<(std::ostream &stream, Signal s)
Definition: vlib.cc:538
Signal::input
void input(int, int, const char *)
Definition: vlib.cc:545
globcontrol::change
int change
Definition: vlib.h:374
Signal::change
int change
Definition: vlib.h:158
parameter::operator=
void operator=(Signal arg)
Definition: vlib.cc:799
module::module
module()
Definition: vlib.cc:913
Signal::create
void create()
Definition: vlib.cc:13
function::result
Signal result
Definition: vlib.h:261
function::OldChange
int OldChange
Definition: vlib.h:260
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
function::vbeginfunction
void vbeginfunction()
Definition: vlib.cc:1086
cuy.col
col
Definition: cuy.py:1010
gather_cfg.cout
cout
Definition: gather_cfg.py:144
Signal::inited
int inited
Definition: vlib.h:163
memory::reg
void reg(int, int, int, int, const char *)
Definition: vlib.cc:840
Signal::getalwaysn
int getalwaysn()
Definition: vlib.h:73
mwire
Definition: vlib.h:26
globcontrol::globcontrol
globcontrol()
Definition: vlib.cc:1127
Signal::sethlmask
void sethlmask(int high, int low, rval imask)
Definition: vlib.h:59
function::init
void init(int, int, const char *)
Definition: vlib.cc:1071
Signal::alwaysn
int alwaysn
Definition: vlib.h:162
Signal::source
Signal * source
Definition: vlib.h:159
Signal::getnegedge
int getnegedge()
Definition: vlib.h:67
mnum
Definition: vlib.h:26
memory::up
int up
Definition: vlib.h:195
Signal
Definition: vlib.h:28
unop
#define unop(op, cop)
Definition: vlib.cc:265
globcontrol::VFileOpen
int VFileOpen
Definition: vlib.h:377
Signal::getposedge
int getposedge()
Definition: vlib.h:66
binop
#define binop(op, cop)
Definition: vlib.cc:294
Signal::nedge
int nedge
Definition: vlib.h:158
Utilities.operator
operator
Definition: Utilities.py:24
module::outreg
Signal * outreg[1000]
Definition: vlib.h:237
Signal::reg
void reg(int, int, const char *)
Definition: vlib.cc:756
globcontrol::functiondecl
int functiondecl
Definition: vlib.h:369
Signal::wire
void wire(int, int, const char *)
Definition: vlib.cc:808
Signal::set
Signal set(Signal)
Definition: vlib.cc:452
alignCSCRings.s
s
Definition: alignCSCRings.py:92
globcontrol
Definition: vlib.h:266
down
Definition: BitonicSort.h:7
module::outregn
int outregn
Definition: vlib.h:238
rval
unsigned long long int rval
Definition: vlib.h:21
Signal::Signal
Signal()
Definition: vlib.cc:29
module::vbeginmodule
void vbeginmodule()
Definition: vlib.cc:971
module::setchange
void setchange(int c)
Definition: vlib.h:221
Signal::getl
int getl()
Definition: vlib.h:54
function::mask
rval mask
Definition: vlib.h:259
globcontrol::getchange
int getchange()
Definition: vlib.h:331
Signal::setposedge
void setposedge(int ch)
Definition: vlib.h:70
function::l
int l
Definition: vlib.h:258
Signal::l
int l
Definition: vlib.h:145
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
Signal::output
void output(int, int, const char *)
Definition: vlib.cc:655
trackingPlots.other
other
Definition: trackingPlots.py:1465
h
OrderedSet.t
t
Definition: OrderedSet.py:90
globcontrol::setfunction
void setfunction(int i)
Definition: vlib.h:334
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
mreg
Definition: vlib.h:26
rxor
Signal rxor(Signal arg)
Definition: vlib.cc:393
memory::operator[]
Signal & operator[](Signal)
Definition: vlib.cc:883
globcontrol::setchange
void setchange(int i)
Definition: vlib.cc:1206
module::AddOutReg
Signal * AddOutReg(Signal arg)
Definition: vlib.cc:1034
globcontrol::constring
char constring[2 *32+32]
Definition: vlib.h:379
obnames
char const * obnames[]
Definition: vlib.cc:7
module::tfixt
module * tfixt
Definition: vlib.h:240
memory::~memory
~memory()
Definition: vlib.cc:874
Signal::getchange
int getchange()
Definition: vlib.h:68
Signal::operator=
Signal operator=(Signal)
Definition: vlib.cc:417
module::posedge
Signal posedge(Signal)
Definition: vlib.cc:1004
Signal::ca2
Signal * ca2
Definition: vlib.h:157
module::negedge
Signal negedge(Signal)
Definition: vlib.cc:1019
rname
const G4String rname[NREG]
Definition: ParametrisedEMPhysics.cc:46
glc
globcontrol glc
Definition: vlib.cc:5
globcontrol::getparent
module * getparent()
Definition: vlib.h:333
globcontrol::alwayscnt
int alwayscnt
Definition: vlib.h:371
module::OuterIndPos
int OuterIndPos
Definition: vlib.h:233
value
Definition: value.py:1
parameter::parameter
parameter(const char *rname, Signal arg)
Definition: vlib.cc:782
Signal::initreg
void initreg(int, int, const char *)
Definition: vlib.cc:766
globcontrol::constant
char * constant(int bits, char *val)
Definition: vlib.cc:1208
memory::r
Signal * r
Definition: vlib.h:194
rand
Signal rand(Signal arg)
Definition: vlib.cc:379
Signal::r
rval r
Definition: vlib.h:140
Signal::operator,
Signal operator,(Signal)
Definition: vlib.cc:324
Signal::makemask
void makemask()
Definition: vlib.cc:202
compop
#define compop(op, cop)
Definition: vlib.cc:352
module
Definition: vlib.h:198
Signal::hostl
int hostl
Definition: vlib.h:146
cms::cuda::for
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
Definition: HistoContainer.h:27
Signal::ca1
Signal * ca1
Definition: vlib.h:156
goodZToMuMu_cfi.condition
condition
Definition: goodZToMuMu_cfi.py:37
Signal::outreg
Signal * outreg
Definition: vlib.h:161
NULL
#define NULL
Definition: scimark2.h:8
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
globcontrol::alwaysn
int alwaysn
Definition: vlib.h:372
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Signal::getr
rval getr()
Definition: vlib.h:52
Signal::getval
rval getval()
Definition: vlib.cc:415
module::runperiod
void(* runperiod)()
Definition: vlib.h:239
minput
Definition: vlib.h:26
module::ifelse
Signal ifelse(Signal, Signal, Signal)
Definition: vlib.cc:1044
L1DTConfigBti_cff.LL
LL
Definition: L1DTConfigBti_cff.py:25
function::makemask
void makemask(int hpar, int lpar)
Definition: vlib.cc:1061
bits
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
Definition: EventSelector-behavior.doc:35
Signal::clock
void clock(const char *rname)
Definition: vlib.cc:603
Sizeofrval
#define Sizeofrval
Definition: vlib.h:22
LaserClient_cfi.high
high
Definition: LaserClient_cfi.py:50
heppy_batch.val
val
Definition: heppy_batch.py:351
Signal::mask
rval mask
Definition: vlib.h:147
Signal::setnegedge
void setnegedge(int ch)
Definition: vlib.h:71
Signal::setchange
void setchange(int ch)
Definition: vlib.h:69
Signal::mode
int mode
Definition: vlib.h:165
moutput
Definition: vlib.h:26
relativeConstraints.value
value
Definition: relativeConstraints.py:53
personalPlayback.username
username
Definition: personalPlayback.py:449
Signal::getmask
rval getmask()
Definition: vlib.h:56
Signal::h
int h
Definition: vlib.h:145
module::vendmodule
void vendmodule()
Definition: vlib.cc:992
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
parameter::init
void init(int, int, const char *)
Definition: vlib.cc:790
Signal::init
void init(int, int, const char *)
Definition: vlib.cc:208
Signal::rc
rval rc
Definition: vlib.h:144
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
funct::arg
A arg
Definition: Factorize.h:36
module::create
void create()
Definition: vlib.cc:906
module::instname
std::string instname
Definition: vlib.h:232
minout
Definition: vlib.h:26
ntuplemaker.time
time
Definition: ntuplemaker.py:310
globcontrol::setce
int setce(int c)
Definition: vlib.h:341
dbgmsg
#define dbgmsg(a)
Definition: vlib.cc:9
Signal::setrc
void setrc(rval rv)
Definition: vlib.h:58
module::~module
virtual ~module()
Definition: vlib.cc:915
class-composition.parent
parent
Definition: class-composition.py:88
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
module::switchn
int switchn
Definition: vlib.h:235
up
Definition: BitonicSort.h:7
function::vendfunction
void vendfunction()
Definition: vlib.cc:1108
module::oldenmarg
int oldenmarg
Definition: vlib.h:236
margin
Double_t margin
Definition: trackSplitPlot.h:45