/src/testdir/build/lua-master/source/lopcodes.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ** $Id: lopcodes.c $ |
3 | | ** Opcodes for Lua virtual machine |
4 | | ** See Copyright Notice in lua.h |
5 | | */ |
6 | | |
7 | | #define lopcodes_c |
8 | | #define LUA_CORE |
9 | | |
10 | | #include "lprefix.h" |
11 | | |
12 | | |
13 | | #include "lopcodes.h" |
14 | | |
15 | | |
16 | | #define opmode(mm,ot,it,t,a,m) \ |
17 | | (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m)) |
18 | | |
19 | | |
20 | | /* ORDER OP */ |
21 | | |
22 | | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { |
23 | | /* MM OT IT T A mode opcode */ |
24 | | opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ |
25 | | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ |
26 | | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ |
27 | | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ |
28 | | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ |
29 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ |
30 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ |
31 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ |
32 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ |
33 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ |
34 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */ |
35 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */ |
36 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */ |
37 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */ |
38 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */ |
39 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */ |
40 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */ |
41 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */ |
42 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */ |
43 | | ,opmode(0, 0, 0, 0, 1, ivABC) /* OP_NEWTABLE */ |
44 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ |
45 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ |
46 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ |
47 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ |
48 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ |
49 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ |
50 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ |
51 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ |
52 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ |
53 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ |
54 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ |
55 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */ |
56 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */ |
57 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */ |
58 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */ |
59 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ |
60 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ |
61 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ |
62 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ |
63 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ |
64 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ |
65 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ |
66 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ |
67 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */ |
68 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */ |
69 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */ |
70 | | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */ |
71 | | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI */ |
72 | | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK */ |
73 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */ |
74 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */ |
75 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */ |
76 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */ |
77 | | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */ |
78 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */ |
79 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */ |
80 | | ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */ |
81 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */ |
82 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */ |
83 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */ |
84 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */ |
85 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */ |
86 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */ |
87 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */ |
88 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */ |
89 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */ |
90 | | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */ |
91 | | ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */ |
92 | | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */ |
93 | | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */ |
94 | | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */ |
95 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */ |
96 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */ |
97 | | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */ |
98 | | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */ |
99 | | ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */ |
100 | | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */ |
101 | | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */ |
102 | | ,opmode(0, 0, 1, 0, 0, ivABC) /* OP_SETLIST */ |
103 | | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */ |
104 | | ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ |
105 | | ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */ |
106 | | ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ |
107 | | }; |
108 | | |
109 | | |
110 | | |
111 | | /* |
112 | | ** Check whether instruction sets top for next instruction, that is, |
113 | | ** it results in multiple values. |
114 | | */ |
115 | 158M | int luaP_isOT (Instruction i) { |
116 | 158M | OpCode op = GET_OPCODE(i); |
117 | 158M | switch (op) { |
118 | 104k | case OP_TAILCALL: return 1; |
119 | 157M | default: |
120 | 157M | return testOTMode(op) && GETARG_C(i) == 0; |
121 | 158M | } |
122 | 158M | } |
123 | | |
124 | | |
125 | | /* |
126 | | ** Check whether instruction uses top from previous instruction, that is, |
127 | | ** it accepts multiple results. |
128 | | */ |
129 | 1.43G | int luaP_isIT (Instruction i) { |
130 | 1.43G | OpCode op = GET_OPCODE(i); |
131 | 1.43G | switch (op) { |
132 | 621k | case OP_SETLIST: |
133 | 1.24M | return testITMode(GET_OPCODE(i)) && GETARG_vB(i) == 0; |
134 | 1.43G | default: |
135 | 1.43G | return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0; |
136 | 1.43G | } |
137 | 1.43G | } |
138 | | |