CMS 3D CMS Logo

vlib.h
Go to the documentation of this file.
1 #ifndef RVALS
2 #define RVALS 2 // max bits in reg/wire divided by 32
3 #endif
4 
10 #ifndef _VLIB_H_FILE_
11 #define _VLIB_H_FILE_
12 
13 #include <iostream>
14 #include <fstream>
15 #include <sstream>
16 #include <string>
17 #include <ctime>
18 #include <cstdio>
19 
20 #define MAXARG 2000
21 
22 typedef unsigned long long int rval;
23 #define Sizeofrval sizeof(rval)
24 
25 class module;
26 
28 {
29  mnone = 0,
30  mreg,
35  mnum,
37 };
38 
39 class Signal
40 {
41 public:
42  Signal ();
43  Signal (rval);
44  Signal (int);
45  Signal (unsigned int);
46  Signal (const char*);
47  Signal (int bits, rval value);
48  void create();
49  void init (int, int, const char*);
50  void init(const char* rname){init(0, 0, rname);};
51  void init(Signal* shost, int h, int l, const char* rname);
52  void makemask();
53 #ifdef VGEN
54  std::string& getname(){return name;};
55  std::string& getorname(){return orname;};
56  std::string& getcatname();
57  void setname (std::string& rname){name = rname;};
58  void setorname (std::string& rname){orname = rname;};
59  void setbrackets(const char* l, const char* r){lb = l; rb = r;};
60 #endif
61  rval getr(){return r;};
62  int getint(){return (unsigned int)r;};
63  int getl(){return l;};
64  int geth(){return h;};
65  rval getmask(){return mask;};
66  void setr(rval rv){r = rv & mask;};
67  void setrc(rval rv){rc = rv & mask;};
68  void sethlmask(int high, int low, rval imask){h = high; l = low; mask = imask;};
69 // bool getbool(){return (r != 0);};
70  bool getbool(){return (getval() != 0);};
71  int getposedge(){return pedge;};
72  int getnegedge(){return nedge;};
73  int getchange(){return change;};
74  void setchange(int ch){change = ch;};
75  void setposedge(int ch){pedge = ch;};
76  void setnegedge(int ch){nedge = ch;};
77  void setalwaysn(int n) {alwaysn = (n == -1) ? 0 : n;};
78  int getalwaysn(){return alwaysn;};
79  void setprintable(int p){printable = p;};
80  rval getval();
81 
82  Signal set(Signal);
85 
98 
105 
106  Signal operator! ();
107  Signal operator~ ();
108  Signal* operator& ();
109  Signal operator++ (){return *this = *this + 1;};
110  Signal operator-- (){return *this = *this - 1;};
111  Signal operator++ (int){return *this = *this + 1;}; // postfix operators require some work (different names for operations and assignment printing?)
112  Signal operator-- (int){return *this = *this - 1;};
113 
114  friend Signal ror (Signal);
115  friend Signal rxor (Signal);
116  friend Signal rand (Signal);
117 
118 
121 
123 
124  friend std::ostream &operator<<(std::ostream &stream, Signal s);
125 
126  void input (int, int, const char*);
127  void input (const char* rname){input(0, 0, rname);};
128  void clock (const char* rname);
129 
130  void output (int, int, const char*);
131  void output (const char* rname){output(0, 0, rname);};
132  void output (int high, int low, const char* rname, module* parent);
133  void output (const char* rname, module* parent);
134 
135  void inout (int, int, const char*);
136  void inout (const char* rname){inout(0, 0, rname);};
137 
138  void reg (int, int, const char*);
139  void initreg (int, int, const char*);
140  void reg (const char* rname){reg(0, 0, rname);};
141 
142  void wire (int, int, const char*);
143  void wire (int, int, const char*, int);
144  void wire (const char* rname){wire(0, 0, rname);};
145 
146 
147 protected:
148  rval r; // value holder
149  rval rc; // current value holder
150  int h, l; // high and low bit numbers
151  int hostl; // low bit of host
152  rval mask; // bit mask
153 #ifdef VGEN
155  std::string orname;
156  std::string lb, rb; // to distinguish between expression and variable
157  std::string obname;
158  std::string catname;
159 #endif
160  Signal* host; // this Signal is a portion of the host
162  Signal *ca2; // arguments of the comma operator
164  Signal* source; // pointer to source object
167  int alwaysn;
168  int inited;
170  int mode; // none, reg, wire, input, output, inout
171 };
172 
173 
174 class parameter : public Signal
175 {
176 public:
177  parameter (const char* rname, Signal arg);
178  operator int(){return (unsigned int)r;};
179 protected:
180  void init (int, int, const char*);
181  void operator= (Signal arg);
182 };
183 
184 
185 
186 class memory
187 {
188 public:
189  memory (){r = nullptr;};
190  ~memory ();
191  void reg (int, int, int, int, const char*);
192  void reg (int nup, int ndown, const char* rname) {reg (0, 0, nup, ndown, rname);};
193 #ifdef VGEN
195 #else
197 #endif
198 
199 protected:
200 #ifdef VGEN
202 #endif
204  int up, down;
205 
206 };
207 
208 class module
209 {
210 public:
211  module ();
212  virtual ~module ();
213  void create();
214  void vendmodule();
215  void vbeginmodule();
216 
217  virtual void operator()(){};
218 
219  void init (const char*, const char*);
220  void init (const char*, const char*, module* fixt);
221  void init (const char*, const char*, int);
222  Signal posedge (Signal);
223  Signal negedge (Signal);
224  void pushswitch (Signal arg){switcharg[switchn] = arg; switchn++;};
225  Signal getswitch (){return switcharg[switchn - 1];};
226  void popswitch () {switchn--;}
227  Signal* AddOutReg(Signal arg);
228  Signal ifelse(Signal, Signal, Signal);
229  void setchange(int c){change = c;}
230  int getchange(){return change;}
231 #ifdef VGEN
232  void PrintHeader();
233 #endif
234 protected:
235 #ifdef VGEN
237  std::streambuf *outbuf;
238  std::ofstream vfile;
239 #endif
242  Signal switcharg[10];
243  int switchn;
245  Signal* outreg[1000];
246  int outregn;
247  void (*runperiod)();
249  int change;
250  int itern; // number of iterations, for diagnostics
251  rval passn; // number of pass
252 
253 };
254 
255 
256 class function : public module
257 {
258 public:
259  function(){};
260  void init (int, int, const char*);
261  void vendfunction();
262  void vbeginfunction();
263  void makemask(int hpar, int lpar);
264 protected:
265 #ifdef VGEN
266  string retname;
267 #endif
268  int h, l;
272 };
273 
274 #define MAXSTIM 10000
275 
277 {
278 public:
279  globcontrol();
280 #ifdef VGEN
281  void AddParameter(string ln) {pars[npar] = ln; npar++;};
282  void AddDeclarator(string ln){decls[ndecl] = ln; ndecl++;};
283  void AddComment(string ln){ln += "\n"; decls[ndecl] = ln; ndecl++;};
284  void AddIO(string ln);
285  void Print ();
286  string& PrintIO(bool col);
287  void Indent(){indpos++; PrepMargin();};
288  void Outdent(){indpos--; PrepMargin();};
289  string& getmargin(){int t = nomargin; nomargin = 0; return (t) ? zeromargin : margin;};
290  int getpos(){return indpos;};
291  void setpos(int pos){indpos = pos; PrepMargin();};
292  void setprintassign(int y){pa = y;};
293  int printassign(){return pa;};
294  void enablemargin (int i){nomargin = !i;};
295  int getenablemargin (){return !nomargin;};
296  void setFileOpen(int fo){VFileOpen = fo;};
297  int getFileOpen(){return VFileOpen;};
298 #endif
299  void alwaysstart() {alwayscnt = 0; alwaysn++; if (alwaysn == 0 || alwaysn == -1) alwaysn = 1;};
300  void alwayspush() {if (alwayscnt >= 0) alwayscnt++;};
301  void alwayspop() {if (alwayscnt > 0) alwayscnt--; if (alwayscnt == 0) alwayscnt = -1;};
302  int alwaysget() {return (alwayscnt > 0);};
303  int getalwaysn() {return (alwayscnt > 0) ? alwaysn : (-1);};
304 
305  void setchange(int i);
306  int getchange(){return change;};
307  void setparent(module *rparent){parent = rparent;};
308  module* getparent(){return parent;};
309  void setfunction(int i){functiondecl = i;};
310  int getfunction(){int t = functiondecl; functiondecl = 0; return t;};
311  int getce(){return ce;};
312  int setce(int c){ce = c; return 1;};
313  char* constant(int bits, char* val);
314  char* constant(int bits, int val);
315  void passn_inc(){passn++;};
316  rval getpassn(){return passn;}
317 
318 protected:
319 #ifdef VGEN
320  string pars[MAXARG];
321  int npar;
322 
323  string decls[MAXARG];
324  int ndecl;
325 
326  string dios[MAXARG];
327  int ndio;
328 
329  int indpos;
330  string margin, zeromargin;
331  void PrepMargin();
332  int nomargin;
333 
334  int pa;
335  string outln;
336 #endif
338 
340  int alwaysn;
341 
342  int change;
344 
345  int VFileOpen; // shows if the comments can be written into the file, or they need to be added to declarators
346  int ce; // clock can be processed
347  char constring[RVALS*32+32]; // string for text variables
348  rval passn; // pass number
349 
350 };
351 
352 #ifdef VGEN
353  #define beginsystem
354  #define endsystem exit(0);
355 #else
356  #define beginsystem glc.setce(0); glc.passn_inc(); do { glc.setchange(0);
357  #define endsystem } while (glc.getchange() ? 1 : glc.getce() ? 0 : glc.setce(1));
358 #endif
359 
360 
361 
362 #endif
void inout(const char *rname)
Definition: vlib.h:136
int alwaysget()
Definition: vlib.h:302
void output(const char *rname)
Definition: vlib.h:131
Signal operator>=(Signal)
Definition: vlib.cc:422
rval mask
Definition: vlib.h:152
rval r
Definition: vlib.h:144
void init(int, int, const char *)
Definition: vlib.cc:239
void reg(int, int, const char *)
Definition: vlib.cc:828
Signal * outhost
Definition: vlib.h:165
int l
Definition: vlib.h:268
void setr(rval rv)
Definition: vlib.h:66
int pedge
Definition: vlib.h:163
int ce
Definition: vlib.h:346
Signal operator!=(Signal)
Definition: vlib.cc:424
void sethlmask(int high, int low, rval imask)
Definition: vlib.h:68
void setnegedge(int ch)
Definition: vlib.h:76
Signal operator=(Signal)
Definition: vlib.cc:486
Signal operator==(Signal)
Definition: vlib.cc:423
Definition: vlib.h:186
int change
Definition: vlib.h:342
SignalMode
Definition: vlib.h:27
Definition: vlib.h:34
void alwayspush()
Definition: vlib.h:300
Signal operator|(Signal)
Definition: vlib.cc:359
rval getval()
Definition: vlib.cc:481
Signal operator<(Signal)
Definition: vlib.cc:420
Signal operator()(Signal, Signal)
Definition: vlib.cc:593
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
rval passn
Definition: vlib.h:251
Signal * ca1
Definition: vlib.h:161
void wire(int, int, const char *)
Definition: vlib.cc:885
int getalwaysn()
Definition: vlib.h:303
Signal operator>>(Signal)
Definition: vlib.cc:356
Signal result
Definition: vlib.h:271
Signal operator~()
Definition: vlib.cc:314
int hostl
Definition: vlib.h:151
void makemask()
Definition: vlib.cc:232
susybsm::HSCParticle pa
Definition: classes.h:8
int functiondecl
Definition: vlib.h:337
void wire(const char *rname)
Definition: vlib.h:144
rval getr()
Definition: vlib.h:61
int inited
Definition: vlib.h:168
Signal operator<=(Signal)
Definition: vlib.cc:421
memory()
Definition: vlib.h:189
A arg
Definition: Factorize.h:37
Signal * operator&()
Definition: vlib.cc:316
void setchange(int ch)
Definition: vlib.h:74
void setrc(rval rv)
Definition: vlib.h:67
void passn_inc()
Definition: vlib.h:315
void setposedge(int ch)
Definition: vlib.h:75
Signal operator!()
Definition: vlib.cc:313
Signal operator%(Signal)
Definition: vlib.cc:353
int switchn
Definition: vlib.h:243
rval getpassn()
Definition: vlib.h:316
void init(const char *rname)
Definition: vlib.h:50
void setprintable(int p)
Definition: vlib.h:79
virtual void operator()()
Definition: vlib.h:217
int oldenmarg
Definition: vlib.h:244
rval mask
Definition: vlib.h:269
void setchange(int c)
Definition: vlib.h:229
Definition: vlib.h:35
void reg(const char *rname)
Definition: vlib.h:140
int VFileOpen
Definition: vlib.h:345
Signal operator&&(Signal)
Definition: vlib.cc:358
int OldChange
Definition: vlib.h:270
int up
Definition: vlib.h:204
Definition: vlib.h:36
friend Signal rand(Signal)
Definition: vlib.cc:442
int getposedge()
Definition: vlib.h:71
void reg(int nup, int ndown, const char *rname)
Definition: vlib.h:192
int h
Definition: vlib.h:150
friend Signal ror(Signal)
Definition: vlib.cc:427
int itern
Definition: vlib.h:250
int nedge
Definition: vlib.h:163
int getalwaysn()
Definition: vlib.h:78
Definition: vlib.h:31
def getname(r)
Signal getswitch()
Definition: vlib.h:225
Definition: vlib.h:32
int getchange()
Definition: vlib.h:306
Signal operator<<(Signal)
Definition: vlib.cc:355
void initreg(int, int, const char *)
Definition: vlib.cc:837
void create()
Definition: vlib.cc:25
Double_t margin
Signal asgn(Signal)
Definition: vlib.cc:533
int geth()
Definition: vlib.h:64
T operator[](int i) const
Definition: vlib.h:33
Signal operator||(Signal)
Definition: vlib.cc:362
Definition: value.py:1
int alwaysn
Definition: vlib.h:340
Signal operator>(Signal)
Definition: vlib.cc:419
void alwaysstart()
Definition: vlib.h:299
void setparent(module *rparent)
Definition: vlib.h:307
void clock(const char *rname)
Definition: vlib.cc:677
int getchange()
Definition: vlib.h:230
Signal operator,(Signal)
Definition: vlib.cc:379
int printable
Definition: vlib.h:169
Signal operator/(Signal)
Definition: vlib.cc:352
int l
Definition: vlib.h:150
int getnegedge()
Definition: vlib.h:72
unsigned long long int rval
Definition: vlib.h:22
int OuterIndPos
Definition: vlib.h:241
void setalwaysn(int n)
Definition: vlib.h:77
int alwayscnt
Definition: vlib.h:339
int getchange()
Definition: vlib.h:73
rval passn
Definition: vlib.h:348
void setfunction(int i)
Definition: vlib.h:309
Signal operator+(Signal)
Definition: vlib.cc:349
void pushswitch(Signal arg)
Definition: vlib.h:224
module * tfixt
Definition: vlib.h:248
Signal operator-(Signal)
Definition: vlib.cc:350
Signal * source
Definition: vlib.h:164
Signal * host
Definition: vlib.h:160
void input(const char *rname)
Definition: vlib.h:127
bool getbool()
Definition: vlib.h:70
Signal operator^(Signal)
Definition: vlib.cc:354
Signal operator++()
Definition: vlib.h:109
module * getparent()
Definition: vlib.h:308
int getce()
Definition: vlib.h:311
Definition: vlib.h:29
int change
Definition: vlib.h:249
Signal operator*(Signal)
Definition: vlib.cc:351
int getint()
Definition: vlib.h:62
friend Signal rxor(Signal)
Definition: vlib.cc:457
int getfunction()
Definition: vlib.h:310
int setce(int c)
Definition: vlib.h:312
Definition: vlib.h:30
rval rc
Definition: vlib.h:149
void inout(int, int, const char *)
Definition: vlib.cc:788
std::string instname
Definition: vlib.h:240
Signal()
Definition: vlib.cc:43
col
Definition: cuy.py:1008
module * parent
Definition: vlib.h:343
Signal * r
Definition: vlib.h:203
Signal * outreg
Definition: vlib.h:166
int outregn
Definition: vlib.h:246
void alwayspop()
Definition: vlib.h:301
int alwaysn
Definition: vlib.h:167
int mode
Definition: vlib.h:170
Signal * ca2
Definition: vlib.h:162
int getl()
Definition: vlib.h:63
void output(int, int, const char *)
Definition: vlib.cc:722
void popswitch()
Definition: vlib.h:226
rval getmask()
Definition: vlib.h:65
int change
Definition: vlib.h:163
Signal operator--()
Definition: vlib.h:110
Definition: vlib.h:208
#define MAXARG
Definition: vlib.h:20
void input(int, int, const char *)
Definition: vlib.cc:625
#define RVALS
Definition: vlib.h:2
Definition: vlib.h:39