aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-28 13:53:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-28 13:53:29 -0300
commit722bdbe17d0192baf72978f88069d12a921e9bfb (patch)
tree78da619d4799721e67a760bf4220b568f636cb86 /lopcodes.h
parent1b100335839e13021b4731f0407b87e4f7544dc0 (diff)
downloadlua-722bdbe17d0192baf72978f88069d12a921e9bfb.tar.gz
lua-722bdbe17d0192baf72978f88069d12a921e9bfb.tar.bz2
lua-722bdbe17d0192baf72978f88069d12a921e9bfb.zip
no more 'getBMode'-'getCMode' (imprecise + we will need more space
for op mode) + better control of op modes
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h57
1 files changed, 27 insertions, 30 deletions
diff --git a/lopcodes.h b/lopcodes.h
index d28948d8..6b9c3aeb 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.160 2017/09/19 18:38:14 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.161 2017/09/26 18:14:45 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -89,6 +89,9 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
89#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ 89#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
90 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) 90 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
91 91
92#define checkopm(i,m) (getOpMode(GET_OPCODE(i)) == m)
93
94
92#define getarg(i,pos,size) (cast(int, ((i)>>(pos)) & MASK1(size,0))) 95#define getarg(i,pos,size) (cast(int, ((i)>>(pos)) & MASK1(size,0)))
93#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \ 96#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
94 ((cast(Instruction, v)<<pos)&MASK1(size,pos)))) 97 ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
@@ -96,25 +99,28 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
96#define GETARG_A(i) getarg(i, POS_A, SIZE_A) 99#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
97#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) 100#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
98 101
99#define GETARG_B(i) getarg(i, POS_B, SIZE_B) 102#define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B))
100#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) 103#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
101 104
102#define GETARG_Br(i) getarg(i, POS_B, SIZE_B - 1) 105#define GETARG_Br(i) \
106 check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B - 1))
103#define GETARG_Bk(i) getarg(i, (POS_B + SIZE_B - 1), 1) 107#define GETARG_Bk(i) getarg(i, (POS_B + SIZE_B - 1), 1)
104 108
105#define GETARG_C(i) getarg(i, POS_C, SIZE_C) 109#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))
106#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 110#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
107 111
108#define GETARG_Cr(i) getarg(i, POS_C, SIZE_C - 1) 112#define GETARG_Cr(i) \
113 check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C - 1))
109#define GETARG_Ck(i) getarg(i, (POS_C + SIZE_C - 1), 1) 114#define GETARG_Ck(i) getarg(i, (POS_C + SIZE_C - 1), 1)
110 115
111#define GETARG_Bx(i) getarg(i, POS_Bx, SIZE_Bx) 116#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
112#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) 117#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
113 118
114#define GETARG_Ax(i) getarg(i, POS_Ax, SIZE_Ax) 119#define GETARG_Ax(i) check_exp(checkopm(i, iAx), getarg(i, POS_Ax, SIZE_Ax))
115#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax) 120#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
116 121
117#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) 122#define GETARG_sBx(i) \
123 check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - MAXARG_sBx)
118#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) 124#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
119 125
120 126
@@ -160,8 +166,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
160 166
161/* 167/*
162** R(x) - register 168** R(x) - register
163** Kst(x) - constant (in constant table) 169** K(x) - constant (in constant table)
164** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x) 170** RK(x) == if ISK(x) then K(INDEXK(x)) else R(x)
165*/ 171*/
166 172
167 173
@@ -176,8 +182,8 @@ name args description
176OP_MOVE,/* A B R(A) := R(B) */ 182OP_MOVE,/* A B R(A) := R(B) */
177OP_LOADI,/* A sBx R(A) := sBx */ 183OP_LOADI,/* A sBx R(A) := sBx */
178OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */ 184OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */
179OP_LOADK,/* A Bx R(A) := Kst(Bx) */ 185OP_LOADK,/* A Bx R(A) := K(Bx) */
180OP_LOADKX,/* A R(A) := Kst(extra arg) */ 186OP_LOADKX,/* A R(A) := K(extra arg) */
181OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ 187OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
182OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ 188OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
183OP_GETUPVAL,/* A B R(A) := UpValue[B] */ 189OP_GETUPVAL,/* A B R(A) := UpValue[B] */
@@ -186,7 +192,7 @@ OP_SETUPVAL,/* A B UpValue[B] := R(A) */
186OP_GETTABUP,/* A B C R(A) := UpValue[B][K(C):string] */ 192OP_GETTABUP,/* A B C R(A) := UpValue[B][K(C):string] */
187OP_GETTABLE,/* A B C R(A) := R(B)[R(C)] */ 193OP_GETTABLE,/* A B C R(A) := R(B)[R(C)] */
188OP_GETI,/* A B C R(A) := R(B)[C] */ 194OP_GETI,/* A B C R(A) := R(B)[C] */
189OP_GETFIELD,/* A B C R(A) := R(B)[Kst(C):string] */ 195OP_GETFIELD,/* A B C R(A) := R(B)[K(C):string] */
190 196
191OP_SETTABUP,/* A B C UpValue[A][K(B):string] := RK(C) */ 197OP_SETTABUP,/* A B C UpValue[A][K(B):string] := RK(C) */
192OP_SETTABLE,/* A B C R(A)[R(B)] := RK(C) */ 198OP_SETTABLE,/* A B C R(A)[R(B)] := RK(C) */
@@ -277,27 +283,18 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
277 283
278/* 284/*
279** masks for instruction properties. The format is: 285** masks for instruction properties. The format is:
280** bits 0-1: op mode 286** bits 0-2: op mode
281** bits 2-3: C arg mode 287** bit 3: instruction set register A
282** bits 4-5: B arg mode 288** bit 4: operator is a test (next instruction must be a jump)
283** bit 6: instruction set register A
284** bit 7: operator is a test (next instruction must be a jump)
285*/ 289*/
286 290
287enum OpArgMask {
288 OpArgN, /* argument is not used */
289 OpArgU, /* argument is used */
290 OpArgR, /* argument is a register or a jump offset */
291 OpArgK /* argument is a constant or register/constant */
292};
293
294LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES]; 291LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];
295 292
296#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) 293#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7))
297#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) 294#define testAMode(m) (luaP_opmodes[m] & (1 << 3))
298#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) 295#define testTMode(m) (luaP_opmodes[m] & (1 << 4))
299#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) 296
300#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) 297#define opmode(t,a,m) (((t)<<4) | ((a)<<3) | (m))
301 298
302 299
303LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ 300LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */