Main Page   Class Hierarchy   Compound List   File List   Compound Members  

op.h

00001 #ifndef CMA_OP_DEFINED
00002 #define CMA_OP_DEFINED
00003 
00004 #include <stdlib.h>
00005 
00006 namespace CMa
00007 {
00008 
00010 #define CMA_MAX_SP_DELTA 1
00011 
00013 #define CMA_MAX_OP_CODE_ARG_COUNT 1
00014 
00016 #define CMA_MAX_OP_STACK_ARG_COUNT 2
00017 
00018 
00101         class Op
00102         {
00103             public:
00104 
00106                 enum Code
00107                 {
00108                         // Not a code
00109                         WRONG_CODE = -1,
00110             //Aritmetical operations
00111             MINUS,
00112             INC,
00113             DEC,
00114             MUL,
00115             ADD,
00116             SUB,
00117             DIV,
00118             MOD,
00119                         //Logical operations
00120             NOT,
00121             AND,
00122             OR,
00123                         //Comparison operators
00124             EQ,
00125             NEQ,
00126             LE,
00127             LEQ,
00128             GE,
00129             GEQ,
00130                         //Bitwise operators
00131             BIT_NOT,
00132             BIT_AND,
00133             BIT_OR,
00134             BIT_XOR,
00135             BIT_SHL,
00136             BIT_SHR,
00137                         //Various jumps
00138             JUMP,
00139             JUMPZ,
00140             JUMPI,
00141             JUMPZS,
00142             JUMPNZ,
00143                         //Store and load
00144             LOADC,
00145             POP,
00146             LOAD,
00147             LOADA,
00148             STORE,
00149             STOREA,
00150             LOADRC,
00151             LOADR,
00152             STORER,
00153                         //Duplication
00154             DUP,
00155             MOVE,
00156                         //Memory management
00157             NEW,
00158             FREE,
00159                         //Organisatory commands
00160             MARK,
00161             CALL,
00162             ENTER,
00163             ALLOC,
00164             RETURN,
00165             HALT,
00166                         //I/O commands
00167             WRITEI,
00168             READI,
00169             WRITEC,
00170 
00171                         // Not a code
00172                         MAX_CODE
00173                 };
00174                 
00176                 Op()
00177                 {
00178                     //Aritmetical operations
00179                     //describe(code, Arg, sArg, SD, name)
00180                         describe(MINUS,  0,   1,    0,  "MINUS");
00181                         describe(INC,    0,   1,    0,  "INC");
00182                         describe(DEC,    0,   1,    0,  "DEC");
00183                         describe(MUL,    0,   2,   -1,  "MUL");
00184                         describe(ADD,    0,   2,   -1,  "ADD");
00185                         describe(SUB,    0,   2,   -1,  "SUB");
00186                         describe(DIV,    0,   2,   -1,  "DIV");
00187                         describe(MOD,    0,   2,   -1,  "MOD");
00188                         //Logical operations
00189                         describe(NOT,    0,   1,    0,  "NOT");
00190                         describe(AND,    0,   2,   -1,  "AND");
00191                         describe(OR,     0,   2,   -1,  "OR");
00192                         //Comparison operations
00193                         describe(EQ,     0,   2,   -1,  "EQ");
00194                         describe(NEQ,    0,   2,   -1,  "NEQ");
00195                         describe(LE,     0,   2,   -1,  "LE");
00196                         describe(LEQ,    0,   2,   -1,  "LEQ");
00197                         describe(GE,     0,   2,   -1,  "GE");
00198                         describe(GEQ,    0,   2,   -1,  "GEQ");
00199                         //Bit operations
00200                         describe(BIT_NOT,0,   1,    0,  "BIT_NOT");
00201                         describe(BIT_AND,0,   2,   -1,  "BIT_AND");
00202                         describe(BIT_OR, 0,   2,   -1,  "BIT_OR");
00203                         describe(BIT_XOR,0,   2,   -1,  "BIT_XOR");
00204                         describe(BIT_SHL,0,   2,   -1,  "BIT_SHL");
00205                         describe(BIT_SHR,0,   2,   -1,  "BIT_SHR");
00206                         //Jumping
00207                         describe(JUMP,   1,   0,    0,  "JUMP");
00208                         describe(JUMPZ,  1,   1,   -1,  "JUMPZ");
00209                         describe(JUMPI,  1,   1,   -1,  "JUMPI");
00210                         describe(JUMPZS, 1,   1,    0,  "JUMPZS");
00211                         describe(JUMPNZ, 1,   1,    0,  "JUMPNZ");
00212             //Store and Load
00213                         describe(LOADC,  1,   0,    1,  "LOADC");
00214                         describe(POP,    0,   0,   -1,  "POP");
00215                         describe(LOAD,   0,   1,    0,  "LOAD");
00216                         describe(LOADA,  1,   0,    1,  "LOADA");
00217                         describe(STORE,  0,   2,   -1,  "STORE");
00218                         describe(STOREA, 1,   1,    0,  "STOREA");
00219                         describe(LOADRC, 1,   0,    1,  "LOADRC");
00220                         describe(LOADR,  1,   0,    1,  "LOADR");
00221                         describe(STORER, 1,   1,    0,  "STORER");
00222                         describe(DUP,    0,   1,    1,  "DUP");
00223                         describe(MOVE,   1,   1,    0,  "MOVE");
00224                         //(De)Allocation
00225                         describe(NEW,    0,   1,    0,  "NEW");
00226                         describe(FREE,   0,   1,   -1,  "FREE");
00227                         //Organisatory commands
00228                         describe(MARK,   0,   0,    4,  "MARK");
00229                         describe(CALL,   1,   1,   -1,  "CALL");
00230                         describe(ENTER,  1,   0,    0,  "ENTER");
00231                         describe(ALLOC,  1,   0,    0,  "ALLOC");
00232                         describe(RETURN, 0,   1,    0,  "RETURN");
00233                         describe(HALT,   0,   0,    0,  "HALT");
00234                         //I/O calls
00235                         describe(WRITEI, 0,   1,   -1,  "WRITEI");
00236                         describe(READI,  0,   0,    1,  "READI");
00237                         describe(WRITEC, 1,   0,    0,  "WRITEC");
00238                         //Table is unchecked -- simple copy from Vesal's specification.
00239                 }
00240 
00246                 inline bool isValid(Code code)
00247                 {
00248                         if ((code < 0)  || (code >= MAX_CODE)) return false;
00249                         return opDescr[code].isValid;
00250                 }
00251 
00259                 inline bool getDescription(
00260                                                         Code code,
00261                                                         int& codeArgN,
00262                                                         int& stackArgN,
00263                                                         int& SPdelta
00264                                                         )
00265                 {
00266                         if ((code < 0)  || (code >= MAX_CODE)) return false;
00267 
00268                         OpDescr& descr = opDescr[code];
00269                         if (!descr.isValid) return false;
00270 
00271                         codeArgN = descr.codeArgN;
00272                         stackArgN = descr.stackArgN;
00273                         SPdelta = descr.SPdelta;
00274 
00275                         return true;
00276                 }
00283                 inline char* getName(Code code)
00284                 {
00285                         assert(isValid(code));
00286                         return opDescr[code].name;
00287                 }
00288 
00289         private:
00290 
00296                 struct OpDescr
00297                 {
00299                         bool isValid;
00300 
00302                         int codeArgN;
00303 
00305                         int stackArgN;
00306 
00308                         int SPdelta;
00309 
00311                         char* name;
00312 
00313                         OpDescr() : isValid(false), name(NULL)
00314                         {}
00315                 };
00316 
00317                 OpDescr opDescr[ MAX_CODE ];
00318 
00319 
00325                 void describe(
00326                                         Code code,
00327                                         int codeArgN,
00328                                         int stackArgN,
00329                                         int SPdelta,
00330                                         char* name
00331                                         )
00332                 {
00333                         opDescr[code].isValid = true;
00334                         opDescr[code].codeArgN = codeArgN;
00335                         opDescr[code].stackArgN = stackArgN;
00336                         opDescr[code].SPdelta = SPdelta;
00337                         opDescr[code].name = name;
00338                 }
00339 
00345                 void describeFun(
00346                                         Code code,
00347                                         int stackArgN,
00348                                         char* name
00349                                         )
00350                 {
00351                         describe(code, 0, stackArgN, 1 - stackArgN, name);
00352                 }
00353         };
00354 
00355 
00359         static class Op op;
00360 }
00361 
00362 #endif
00363 

Generated on Tue Oct 12 03:30:44 1999 by doxygen1.2.18