00001
00002
00003
00004
00005
00006
00007 #ifndef lopcodes_h
00008 #define lopcodes_h
00009
00010 #include "llimits.h"
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 enum OpMode {iABC, iABx, iAsBx};
00032
00033
00034
00035
00036
00037 #define SIZE_C 9
00038 #define SIZE_B 9
00039 #define SIZE_Bx (SIZE_C + SIZE_B)
00040 #define SIZE_A 8
00041
00042 #define SIZE_OP 6
00043
00044 #define POS_OP 0
00045 #define POS_A (POS_OP + SIZE_OP)
00046 #define POS_C (POS_A + SIZE_A)
00047 #define POS_B (POS_C + SIZE_C)
00048 #define POS_Bx POS_C
00049
00050
00051
00052
00053
00054
00055
00056 #if SIZE_Bx < LUAI_BITSINT-1
00057 #define MAXARG_Bx ((1<<SIZE_Bx)-1)
00058 #define MAXARG_sBx (MAXARG_Bx>>1)
00059 #else
00060 #define MAXARG_Bx MAX_INT
00061 #define MAXARG_sBx MAX_INT
00062 #endif
00063
00064
00065 #define MAXARG_A ((1<<SIZE_A)-1)
00066 #define MAXARG_B ((1<<SIZE_B)-1)
00067 #define MAXARG_C ((1<<SIZE_C)-1)
00068
00069
00070
00071 #define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p)
00072
00073
00074 #define MASK0(n,p) (~MASK1(n,p))
00075
00076
00077
00078
00079
00080 #define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
00081 #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
00082 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
00083
00084 #define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))
00085 #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
00086 ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
00087
00088 #define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
00089 #define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
00090 ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
00091
00092 #define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
00093 #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
00094 ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
00095
00096 #define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
00097 #define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
00098 ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
00099
00100 #define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx)
00101 #define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
00102
00103
00104 #define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \
00105 | (cast(Instruction, a)<<POS_A) \
00106 | (cast(Instruction, b)<<POS_B) \
00107 | (cast(Instruction, c)<<POS_C))
00108
00109 #define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
00110 | (cast(Instruction, a)<<POS_A) \
00111 | (cast(Instruction, bc)<<POS_Bx))
00112
00113
00114
00115
00116
00117
00118
00119 #define BITRK (1 << (SIZE_B - 1))
00120
00121
00122 #define ISK(x) ((x) & BITRK)
00123
00124
00125 #define INDEXK(r) ((int)(r) & ~BITRK)
00126
00127 #define MAXINDEXRK (BITRK - 1)
00128
00129
00130 #define RKASK(x) ((x) | BITRK)
00131
00132
00133
00134
00135
00136 #define NO_REG MAXARG_A
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 typedef enum {
00151
00152
00153
00154 OP_MOVE,
00155 OP_LOADK,
00156 OP_LOADBOOL,
00157 OP_LOADNIL,
00158 OP_GETUPVAL,
00159
00160 OP_GETGLOBAL,
00161 OP_GETTABLE,
00162
00163 OP_SETGLOBAL,
00164 OP_SETUPVAL,
00165 OP_SETTABLE,
00166
00167 OP_NEWTABLE,
00168
00169 OP_SELF,
00170
00171 OP_ADD,
00172 OP_SUB,
00173 OP_MUL,
00174 OP_DIV,
00175 OP_MOD,
00176 OP_POW,
00177 OP_UNM,
00178 OP_NOT,
00179 OP_LEN,
00180
00181 OP_CONCAT,
00182
00183 OP_JMP,
00184
00185 OP_EQ,
00186 OP_LT,
00187 OP_LE,
00188
00189 OP_TEST,
00190 OP_TESTSET,
00191
00192 OP_CALL,
00193 OP_TAILCALL,
00194 OP_RETURN,
00195
00196 OP_FORLOOP,
00197
00198 OP_FORPREP,
00199
00200 OP_TFORLOOP,
00201
00202 OP_SETLIST,
00203
00204 OP_CLOSE,
00205 OP_CLOSURE,
00206
00207 OP_VARARG
00208 } OpCode;
00209
00210
00211 #define NUM_OPCODES (cast(int, OP_VARARG) + 1)
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 enum OpArgMask {
00246 OpArgN,
00247 OpArgU,
00248 OpArgR,
00249 OpArgK
00250 };
00251
00252 LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];
00253
00254 #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
00255 #define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
00256 #define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
00257 #define testAMode(m) (luaP_opmodes[m] & (1 << 6))
00258 #define testTMode(m) (luaP_opmodes[m] & (1 << 7))
00259
00260
00261 LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1];
00262
00263
00264
00265 #define LFIELDS_PER_FLUSH 50
00266
00267
00268 #endif