CMS 3D CMS Logo

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