CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/L1Trigger/CSCCommonTrigger/interface/vlib.h

Go to the documentation of this file.
00001 #ifndef RVALS
00002 #define RVALS 2 // max bits in reg/wire divided by 32
00003 #endif
00004 
00009 // Copyright (c) 2002, Alexander Madorsky, University of Florida/Physics. All rights reserved.
00010 
00011 #ifndef _VLIB_H_FILE_
00012 #define _VLIB_H_FILE_
00013 
00014 #include <iostream>
00015 #include <fstream>
00016 #include <sstream>
00017 #include <string>
00018 #include <time.h>
00019 #include <stdio.h>
00020 
00021 #define MAXARG 2000
00022 
00023 typedef unsigned long long int rval;
00024 #define Sizeofrval sizeof(rval)
00025 
00026 class module;
00027 
00028 enum SignalMode 
00029 {
00030         mnone = 0, 
00031         mreg, 
00032         mwire, 
00033         minput, 
00034         moutput, 
00035         minout, 
00036         mnum, 
00037         mtemp
00038 };
00039 
00040 class Signal
00041 {
00042 public:
00043         Signal ();
00044         Signal (rval);
00045         Signal (int);
00046         Signal (unsigned int);
00047         Signal (const char*);
00048         Signal (int bits, rval value);
00049         void create();
00050         void init (int, int, const char*);
00051         void init(const char* rname){init(0, 0, rname);};
00052         void init(Signal* shost, int h, int l, const char* rname);
00053         void makemask();
00054 #ifdef VGEN
00055         std::string& getname(){return name;};
00056         std::string& getorname(){return orname;};
00057         std::string& getcatname();
00058         void setname (std::string& rname){name = rname;};
00059         void setorname (std::string& rname){orname = rname;};
00060         void setbrackets(const char* l, const char* r){lb = l; rb = r;};
00061 #endif
00062         rval getr(){return r;};
00063         int getint(){return (unsigned int)r;};
00064         int getl(){return l;};
00065         int geth(){return h;};
00066         rval getmask(){return mask;};
00067         void setr(rval rv){r = rv & mask;};
00068         void setrc(rval rv){rc = rv & mask;};
00069         void sethlmask(int high, int low, rval imask){h = high; l = low; mask = imask;};
00070 //      bool getbool(){return (r != 0);};
00071         bool getbool(){return (getval() != 0);};
00072         int getposedge(){return pedge;};
00073         int getnegedge(){return nedge;};
00074         int getchange(){return change;};
00075         void setchange(int ch){change = ch;};
00076         void setposedge(int ch){pedge = ch;};
00077         void setnegedge(int ch){nedge = ch;};
00078         void setalwaysn(int n) {alwaysn = (n == -1) ? 0 : n;};
00079         int  getalwaysn(){return alwaysn;};
00080         void setprintable(int p){printable = p;};
00081         rval getval();
00082 
00083         Signal set(Signal);
00084         Signal asgn(Signal);
00085         Signal operator=  (Signal);
00086 
00087         Signal operator+  (Signal);
00088         Signal operator-  (Signal);
00089         Signal operator*  (Signal);
00090         Signal operator/  (Signal);
00091         Signal operator%  (Signal);
00092         Signal operator^  (Signal);
00093         Signal operator>> (Signal);
00094         Signal operator<< (Signal);
00095         Signal operator&  (Signal);
00096         Signal operator&& (Signal);
00097         Signal operator|  (Signal);
00098         Signal operator|| (Signal);
00099 
00100         Signal operator<  (Signal);
00101         Signal operator>  (Signal);
00102         Signal operator<= (Signal);
00103         Signal operator>= (Signal);
00104         Signal operator== (Signal);
00105         Signal operator!= (Signal);
00106 
00107         Signal operator!  ();
00108         Signal operator~  ();
00109         Signal* operator&  ();
00110         Signal operator++  (){return *this = *this + 1;};
00111         Signal operator--  (){return *this = *this - 1;};
00112         Signal operator++  (int){return *this = *this + 1;};            // postfix operators require some work (different names for operations and assignment printing?)
00113         Signal operator--  (int){return *this = *this - 1;};
00114 
00115         friend Signal ror (Signal);
00116         friend Signal rxor (Signal);
00117         friend Signal rand (Signal);
00118 
00119 
00120         Signal operator()(Signal, Signal);
00121         Signal operator()(Signal);
00122 
00123         Signal operator,(Signal);
00124 
00125         friend std::ostream &operator<<(std::ostream &stream, Signal s);
00126 
00127         void input (int, int, const char*);
00128         void input (const char* rname){input(0, 0, rname);};
00129         void clock (const char* rname);
00130 
00131         void output (int, int, const char*);
00132         void output (const char* rname){output(0, 0, rname);};
00133         void output (int high, int low, const char* rname, module* parent);
00134         void output (const char* rname, module* parent);
00135 
00136         void inout (int, int, const char*);
00137         void inout (const char* rname){inout(0, 0, rname);};
00138 
00139         void reg (int, int, const char*);
00140         void initreg (int, int, const char*);
00141         void reg (const char* rname){reg(0, 0, rname);};
00142 
00143         void wire (int, int, const char*);
00144         void wire (int, int, const char*, int);
00145         void wire (const char* rname){wire(0, 0, rname);};
00146 
00147 
00148 protected:
00149         rval r; // value holder
00150         rval rc; // current value holder
00151         int h, l;  // high and low bit numbers
00152         int hostl; // low bit of host
00153         rval mask; // bit mask
00154 #ifdef VGEN
00155         std::string name;
00156         std::string orname;
00157         std::string lb, rb; // to distinguish between expression and variable
00158         std::string obname;
00159         std::string catname;
00160 #endif
00161         Signal* host; // this Signal is a portion of the host
00162         Signal *ca1;
00163         Signal *ca2; // arguments of the comma operator
00164         int pedge, nedge, change;
00165         Signal* source; // pointer to source object
00166         Signal* outhost;
00167         Signal* outreg;
00168         int alwaysn;
00169         int inited;
00170         int printable;
00171         int mode; // none, reg, wire, input, output, inout
00172 };
00173 
00174 
00175 class parameter : public Signal
00176 {
00177 public:
00178         parameter (const char* rname, Signal arg);
00179         operator int(){return (unsigned int)r;};
00180 protected:
00181         void init (int, int, const char*);
00182         void operator= (Signal arg);
00183 };
00184 
00185 
00186 
00187 class memory
00188 {
00189 public: 
00190         memory (){r = NULL;};
00191         ~memory ();
00192         void reg (int, int, int, int, const char*);
00193         void reg (int nup, int ndown, const char* rname) {reg (0, 0, nup, ndown, rname);};
00194 #ifdef VGEN
00195         Signal operator[] (Signal);
00196 #else
00197         Signal& operator[] (Signal);
00198 #endif
00199 
00200 protected:
00201 #ifdef VGEN
00202         std::string name;
00203 #endif
00204         Signal* r;
00205         int up, down;
00206 
00207 };
00208 
00209 class module
00210 {
00211 public:
00212         module ();
00213         virtual ~module ();
00214         void create();
00215         void vendmodule();
00216         void vbeginmodule();
00217 
00218         virtual void operator()(){};
00219         
00220         void init (const char*, const char*);
00221         void init (const char*, const char*, module* fixt);
00222         void init (const char*, const char*, int);
00223         Signal posedge (Signal);
00224         Signal negedge (Signal);
00225         void pushswitch (Signal arg){switcharg[switchn] = arg; switchn++;};
00226         Signal getswitch (){return switcharg[switchn - 1];};
00227         void popswitch () {switchn--;}
00228         Signal* AddOutReg(Signal arg);
00229         Signal ifelse(Signal, Signal, Signal);
00230         void setchange(int c){change = c;}
00231         int getchange(){return change;}
00232 #ifdef VGEN
00233         void PrintHeader();
00234 #endif
00235 protected:
00236 #ifdef VGEN
00237         std::string name;
00238         std::streambuf *outbuf;
00239         std::ofstream vfile;
00240 #endif
00241         std::string instname;
00242         int OuterIndPos;
00243         Signal switcharg[10];
00244         int switchn;
00245         int oldenmarg;
00246         Signal* outreg[1000];
00247         int outregn;
00248         void (*runperiod)();
00249         module* tfixt;
00250         int change;
00251         int itern; // number of iterations, for diagnostics
00252         rval passn; // number of pass
00253 
00254 };
00255 
00256 
00257 class function : public module
00258 {
00259 public:
00260         function(){};
00261         void init (int, int, const char*);
00262         void vendfunction();
00263         void vbeginfunction();
00264         void makemask(int hpar, int lpar);
00265 protected:
00266 #ifdef VGEN
00267         string retname;
00268 #endif
00269         int h, l;
00270         rval mask;
00271         int OldChange;
00272         Signal result;
00273 };
00274   
00275 #define MAXSTIM 10000
00276 
00277 class globcontrol
00278 {
00279 public:
00280         globcontrol();
00281 #ifdef VGEN
00282         void AddParameter(string ln) {pars[npar] = ln; npar++;};
00283         void AddDeclarator(string ln){decls[ndecl] = ln; ndecl++;};
00284         void AddComment(string ln){ln += "\n"; decls[ndecl] = ln; ndecl++;};
00285         void AddIO(string ln);
00286         void Print ();
00287         string& PrintIO(bool col);
00288         void Indent(){indpos++; PrepMargin();};
00289         void Outdent(){indpos--; PrepMargin();};
00290         string& getmargin(){int t = nomargin; nomargin = 0; return (t) ? zeromargin : margin;};
00291         int getpos(){return indpos;};
00292         void setpos(int pos){indpos = pos; PrepMargin();};
00293         void setprintassign(int y){pa = y;};
00294         int  printassign(){return pa;};
00295         void enablemargin (int i){nomargin = !i;};
00296         int  getenablemargin (){return !nomargin;};
00297         void setFileOpen(int fo){VFileOpen = fo;};
00298         int  getFileOpen(){return VFileOpen;};
00299 #endif
00300         void alwaysstart() {alwayscnt = 0; alwaysn++; if (alwaysn == 0 || alwaysn == -1) alwaysn = 1;}; 
00301         void alwayspush() {if (alwayscnt >= 0) alwayscnt++;};
00302         void alwayspop()  {if (alwayscnt >  0) alwayscnt--; if (alwayscnt == 0) alwayscnt = -1;};
00303         int  alwaysget() {return (alwayscnt > 0);};
00304         int  getalwaysn() {return (alwayscnt > 0) ? alwaysn : (-1);};
00305 
00306         void setchange(int i);
00307         int  getchange(){return change;};
00308         void setparent(module *rparent){parent = rparent;};
00309         module* getparent(){return parent;};
00310         void setfunction(int i){functiondecl = i;};
00311         int  getfunction(){int t = functiondecl; functiondecl = 0; return t;};
00312         int getce(){return ce;};
00313         int setce(int c){ce = c; return 1;};
00314         char* constant(int bits, char* val);
00315         char* constant(int bits, int val);
00316         void passn_inc(){passn++;};
00317         rval getpassn(){return passn;}
00318 
00319 protected:
00320 #ifdef VGEN
00321         string pars[MAXARG];
00322         int npar;
00323 
00324         string decls[MAXARG];
00325         int ndecl;
00326 
00327         string dios[MAXARG];
00328         int ndio;
00329 
00330         int indpos;
00331         string margin, zeromargin;
00332         void PrepMargin();
00333         int nomargin;
00334 
00335         int pa;
00336         string outln;
00337 #endif
00338         int functiondecl;
00339 
00340         int alwayscnt;
00341         int alwaysn;
00342 
00343         int change;
00344         module* parent;
00345 
00346         int VFileOpen; // shows if the comments can be written into the file, or they need to be added to declarators
00347         int ce; // clock can be processed
00348         char constring[RVALS*32+32]; // string for text variables
00349         rval passn; // pass number
00350 
00351 };
00352 
00353 #ifdef VGEN
00354         #define beginsystem
00355         #define endsystem  exit(0);
00356 #else
00357         #define beginsystem glc.setce(0); glc.passn_inc(); do { glc.setchange(0);
00358         #define endsystem   } while (glc.getchange() ? 1 : glc.getce() ? 0 : glc.setce(1));
00359 #endif
00360 
00361 
00362 
00363 #endif