diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-09-06 14:14:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-09-06 14:14:11 -0300 |
commit | 4518e5df24600cacdb3bab75d640348d28e8b769 (patch) | |
tree | c9e8c678e718b5ccec7e7ca120bd68c5634bdfda | |
parent | 72a094bda7d71050a91a88474d67d39aa2bc1c46 (diff) | |
download | lua-4518e5df24600cacdb3bab75d640348d28e8b769.tar.gz lua-4518e5df24600cacdb3bab75d640348d28e8b769.tar.bz2 lua-4518e5df24600cacdb3bab75d640348d28e8b769.zip |
Added macro 'testMMMode'
Macro 'testMMMode' checks whether opcode is an MM opcode.
-rw-r--r-- | ldebug.c | 8 | ||||
-rw-r--r-- | lopcodes.c | 176 | ||||
-rw-r--r-- | lopcodes.h | 5 |
3 files changed, 95 insertions, 94 deletions
@@ -465,16 +465,14 @@ static int filterpc (int pc, int jmptarget) { | |||
465 | 465 | ||
466 | 466 | ||
467 | /* | 467 | /* |
468 | ** try to find last instruction before 'lastpc' that modified register 'reg' | 468 | ** Try to find last instruction before 'lastpc' that modified register 'reg'. |
469 | */ | 469 | */ |
470 | static int findsetreg (const Proto *p, int lastpc, int reg) { | 470 | static int findsetreg (const Proto *p, int lastpc, int reg) { |
471 | int pc; | 471 | int pc; |
472 | int setreg = -1; /* keep last instruction that changed 'reg' */ | 472 | int setreg = -1; /* keep last instruction that changed 'reg' */ |
473 | int jmptarget = 0; /* any code before this address is conditional */ | 473 | int jmptarget = 0; /* any code before this address is conditional */ |
474 | if (GET_OPCODE(p->code[lastpc]) == OP_MMBIN || | 474 | if (testMMMode(GET_OPCODE(p->code[lastpc]))) |
475 | GET_OPCODE(p->code[lastpc]) == OP_MMBINI || | 475 | lastpc--; /* previous instruction was not actually executed */ |
476 | GET_OPCODE(p->code[lastpc]) == OP_MMBINK) | ||
477 | lastpc--; | ||
478 | for (pc = 0; pc < lastpc; pc++) { | 476 | for (pc = 0; pc < lastpc; pc++) { |
479 | Instruction i = p->code[pc]; | 477 | Instruction i = p->code[pc]; |
480 | OpCode op = GET_OPCODE(i); | 478 | OpCode op = GET_OPCODE(i); |
@@ -18,93 +18,93 @@ | |||
18 | /* ORDER OP */ | 18 | /* ORDER OP */ |
19 | 19 | ||
20 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | 20 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { |
21 | /* OT IT T A mode opcode */ | 21 | /* MM OT IT T A mode opcode */ |
22 | opmode(0, 0, 0, 1, iABC) /* OP_MOVE */ | 22 | opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ |
23 | ,opmode(0, 0, 0, 1, iAsBx) /* OP_LOADI */ | 23 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ |
24 | ,opmode(0, 0, 0, 1, iAsBx) /* OP_LOADF */ | 24 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ |
25 | ,opmode(0, 0, 0, 1, iABx) /* OP_LOADK */ | 25 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ |
26 | ,opmode(0, 0, 0, 1, iABx) /* OP_LOADKX */ | 26 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ |
27 | ,opmode(0, 0, 0, 1, iABC) /* OP_LOADBOOL */ | 27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADBOOL */ |
28 | ,opmode(0, 0, 0, 1, iABC) /* OP_LOADNIL */ | 28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ |
29 | ,opmode(0, 0, 0, 1, iABC) /* OP_GETUPVAL */ | 29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ |
30 | ,opmode(0, 0, 0, 0, iABC) /* OP_SETUPVAL */ | 30 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */ |
31 | ,opmode(0, 0, 0, 1, iABC) /* OP_GETTABUP */ | 31 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */ |
32 | ,opmode(0, 0, 0, 1, iABC) /* OP_GETTABLE */ | 32 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */ |
33 | ,opmode(0, 0, 0, 1, iABC) /* OP_GETI */ | 33 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */ |
34 | ,opmode(0, 0, 0, 1, iABC) /* OP_GETFIELD */ | 34 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */ |
35 | ,opmode(0, 0, 0, 0, iABC) /* OP_SETTABUP */ | 35 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */ |
36 | ,opmode(0, 0, 0, 0, iABC) /* OP_SETTABLE */ | 36 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */ |
37 | ,opmode(0, 0, 0, 0, iABC) /* OP_SETI */ | 37 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */ |
38 | ,opmode(0, 0, 0, 0, iABC) /* OP_SETFIELD */ | 38 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */ |
39 | ,opmode(0, 0, 0, 1, iABC) /* OP_NEWTABLE */ | 39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */ |
40 | ,opmode(0, 0, 0, 1, iABC) /* OP_SELF */ | 40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ |
41 | ,opmode(0, 0, 0, 1, iABC) /* OP_ADDI */ | 41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ |
42 | ,opmode(0, 0, 0, 1, iABC) /* OP_SUBI */ | 42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBI */ |
43 | ,opmode(0, 0, 0, 1, iABC) /* OP_MULI */ | 43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULI */ |
44 | ,opmode(0, 0, 0, 1, iABC) /* OP_MODI */ | 44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODI */ |
45 | ,opmode(0, 0, 0, 1, iABC) /* OP_POWI */ | 45 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWI */ |
46 | ,opmode(0, 0, 0, 1, iABC) /* OP_DIVI */ | 46 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVI */ |
47 | ,opmode(0, 0, 0, 1, iABC) /* OP_IDIVI */ | 47 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVI */ |
48 | ,opmode(0, 0, 0, 1, iABC) /* OP_ADDK */ | 48 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ |
49 | ,opmode(0, 0, 0, 1, iABC) /* OP_SUBK */ | 49 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ |
50 | ,opmode(0, 0, 0, 1, iABC) /* OP_MULK */ | 50 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ |
51 | ,opmode(0, 0, 0, 1, iABC) /* OP_MODK */ | 51 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ |
52 | ,opmode(0, 0, 0, 1, iABC) /* OP_POWK */ | 52 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ |
53 | ,opmode(0, 0, 0, 1, iABC) /* OP_DIVK */ | 53 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ |
54 | ,opmode(0, 0, 0, 1, iABC) /* OP_IDIVK */ | 54 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ |
55 | ,opmode(0, 0, 0, 1, iABC) /* OP_BANDK */ | 55 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ |
56 | ,opmode(0, 0, 0, 1, iABC) /* OP_BORK */ | 56 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ |
57 | ,opmode(0, 0, 0, 1, iABC) /* OP_BXORK */ | 57 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */ |
58 | ,opmode(0, 0, 0, 1, iABC) /* OP_SHRI */ | 58 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */ |
59 | ,opmode(0, 0, 0, 1, iABC) /* OP_SHLI */ | 59 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */ |
60 | ,opmode(0, 0, 0, 1, iABC) /* OP_ADD */ | 60 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */ |
61 | ,opmode(0, 0, 0, 1, iABC) /* OP_SUB */ | 61 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ |
62 | ,opmode(0, 0, 0, 1, iABC) /* OP_MUL */ | 62 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ |
63 | ,opmode(0, 0, 0, 1, iABC) /* OP_MOD */ | 63 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ |
64 | ,opmode(0, 0, 0, 1, iABC) /* OP_POW */ | 64 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ |
65 | ,opmode(0, 0, 0, 1, iABC) /* OP_DIV */ | 65 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ |
66 | ,opmode(0, 0, 0, 1, iABC) /* OP_IDIV */ | 66 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ |
67 | ,opmode(0, 0, 0, 1, iABC) /* OP_BAND */ | 67 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ |
68 | ,opmode(0, 0, 0, 1, iABC) /* OP_BOR */ | 68 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ |
69 | ,opmode(0, 0, 0, 1, iABC) /* OP_BXOR */ | 69 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */ |
70 | ,opmode(0, 0, 0, 1, iABC) /* OP_SHL */ | 70 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */ |
71 | ,opmode(0, 0, 0, 1, iABC) /* OP_SHR */ | 71 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */ |
72 | ,opmode(0, 0, 0, 0, iABC) /* OP_MMBIN */ | 72 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */ |
73 | ,opmode(0, 0, 0, 0, iABC) /* OP_MMBINI*/ | 73 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI*/ |
74 | ,opmode(0, 0, 0, 0, iABC) /* OP_MMBINK*/ | 74 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK*/ |
75 | ,opmode(0, 0, 0, 1, iABC) /* OP_UNM */ | 75 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */ |
76 | ,opmode(0, 0, 0, 1, iABC) /* OP_BNOT */ | 76 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */ |
77 | ,opmode(0, 0, 0, 1, iABC) /* OP_NOT */ | 77 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */ |
78 | ,opmode(0, 0, 0, 1, iABC) /* OP_LEN */ | 78 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */ |
79 | ,opmode(0, 0, 0, 1, iABC) /* OP_CONCAT */ | 79 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */ |
80 | ,opmode(0, 0, 0, 0, iABC) /* OP_CLOSE */ | 80 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */ |
81 | ,opmode(0, 0, 0, 0, iABC) /* OP_TBC */ | 81 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */ |
82 | ,opmode(0, 0, 0, 0, isJ) /* OP_JMP */ | 82 | ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */ |
83 | ,opmode(0, 0, 1, 0, iABC) /* OP_EQ */ | 83 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */ |
84 | ,opmode(0, 0, 1, 0, iABC) /* OP_LT */ | 84 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */ |
85 | ,opmode(0, 0, 1, 0, iABC) /* OP_LE */ | 85 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */ |
86 | ,opmode(0, 0, 1, 0, iABC) /* OP_EQK */ | 86 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */ |
87 | ,opmode(0, 0, 1, 0, iABC) /* OP_EQI */ | 87 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */ |
88 | ,opmode(0, 0, 1, 0, iABC) /* OP_LTI */ | 88 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */ |
89 | ,opmode(0, 0, 1, 0, iABC) /* OP_LEI */ | 89 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */ |
90 | ,opmode(0, 0, 1, 0, iABC) /* OP_GTI */ | 90 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */ |
91 | ,opmode(0, 0, 1, 0, iABC) /* OP_GEI */ | 91 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */ |
92 | ,opmode(0, 0, 1, 0, iABC) /* OP_TEST */ | 92 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */ |
93 | ,opmode(0, 0, 1, 1, iABC) /* OP_TESTSET */ | 93 | ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */ |
94 | ,opmode(1, 1, 0, 1, iABC) /* OP_CALL */ | 94 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */ |
95 | ,opmode(1, 1, 0, 1, iABC) /* OP_TAILCALL */ | 95 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */ |
96 | ,opmode(0, 1, 0, 0, iABC) /* OP_RETURN */ | 96 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */ |
97 | ,opmode(0, 0, 0, 0, iABC) /* OP_RETURN0 */ | 97 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */ |
98 | ,opmode(0, 0, 0, 0, iABC) /* OP_RETURN1 */ | 98 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */ |
99 | ,opmode(0, 0, 0, 1, iABx) /* OP_FORLOOP */ | 99 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */ |
100 | ,opmode(0, 0, 0, 1, iABx) /* OP_FORPREP */ | 100 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */ |
101 | ,opmode(0, 0, 0, 0, iABx) /* OP_TFORPREP */ | 101 | ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */ |
102 | ,opmode(0, 0, 0, 0, iABC) /* OP_TFORCALL */ | 102 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */ |
103 | ,opmode(0, 0, 0, 1, iABx) /* OP_TFORLOOP */ | 103 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */ |
104 | ,opmode(0, 1, 0, 0, iABC) /* OP_SETLIST */ | 104 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_SETLIST */ |
105 | ,opmode(0, 0, 0, 1, iABx) /* OP_CLOSURE */ | 105 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */ |
106 | ,opmode(1, 0, 0, 1, iABC) /* OP_VARARG */ | 106 | ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ |
107 | ,opmode(0, 1, 0, 1, iABC) /* OP_VARARGPREP */ | 107 | ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */ |
108 | ,opmode(0, 0, 0, 0, iAx) /* OP_EXTRAARG */ | 108 | ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ |
109 | }; | 109 | }; |
110 | 110 | ||
@@ -359,6 +359,7 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
359 | ** bit 4: operator is a test (next instruction must be a jump) | 359 | ** bit 4: operator is a test (next instruction must be a jump) |
360 | ** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0) | 360 | ** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0) |
361 | ** bit 6: instruction sets 'L->top' for next instruction (when C == 0) | 361 | ** bit 6: instruction sets 'L->top' for next instruction (when C == 0) |
362 | ** bit 7: instruction is an MM instruction (call a metamethod) | ||
362 | */ | 363 | */ |
363 | 364 | ||
364 | LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) | 365 | LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) |
@@ -368,6 +369,7 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) | |||
368 | #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) | 369 | #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) |
369 | #define testITMode(m) (luaP_opmodes[m] & (1 << 5)) | 370 | #define testITMode(m) (luaP_opmodes[m] & (1 << 5)) |
370 | #define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) | 371 | #define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) |
372 | #define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) | ||
371 | 373 | ||
372 | /* "out top" (set top for next instruction) */ | 374 | /* "out top" (set top for next instruction) */ |
373 | #define isOT(i) \ | 375 | #define isOT(i) \ |
@@ -377,7 +379,8 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) | |||
377 | /* "in top" (uses top from previous instruction) */ | 379 | /* "in top" (uses top from previous instruction) */ |
378 | #define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0) | 380 | #define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0) |
379 | 381 | ||
380 | #define opmode(ot,it,t,a,m) (((ot)<<6) | ((it)<<5) | ((t)<<4) | ((a)<<3) | (m)) | 382 | #define opmode(mm,ot,it,t,a,m) \ |
383 | (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m)) | ||
381 | 384 | ||
382 | 385 | ||
383 | /* number of list items to accumulate before a SETLIST instruction */ | 386 | /* number of list items to accumulate before a SETLIST instruction */ |