xref: /freebsd/contrib/lua/src/lopcodes.c (revision 8e3e3a7ae841ccf6f6ac30a2eeab85df5d7f04bc)
1*8e3e3a7aSWarner Losh /*
2*8e3e3a7aSWarner Losh ** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $
3*8e3e3a7aSWarner Losh ** Opcodes for Lua virtual machine
4*8e3e3a7aSWarner Losh ** See Copyright Notice in lua.h
5*8e3e3a7aSWarner Losh */
6*8e3e3a7aSWarner Losh 
7*8e3e3a7aSWarner Losh #define lopcodes_c
8*8e3e3a7aSWarner Losh #define LUA_CORE
9*8e3e3a7aSWarner Losh 
10*8e3e3a7aSWarner Losh #include "lprefix.h"
11*8e3e3a7aSWarner Losh 
12*8e3e3a7aSWarner Losh 
13*8e3e3a7aSWarner Losh #include <stddef.h>
14*8e3e3a7aSWarner Losh 
15*8e3e3a7aSWarner Losh #include "lopcodes.h"
16*8e3e3a7aSWarner Losh 
17*8e3e3a7aSWarner Losh 
18*8e3e3a7aSWarner Losh /* ORDER OP */
19*8e3e3a7aSWarner Losh 
20*8e3e3a7aSWarner Losh LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
21*8e3e3a7aSWarner Losh   "MOVE",
22*8e3e3a7aSWarner Losh   "LOADK",
23*8e3e3a7aSWarner Losh   "LOADKX",
24*8e3e3a7aSWarner Losh   "LOADBOOL",
25*8e3e3a7aSWarner Losh   "LOADNIL",
26*8e3e3a7aSWarner Losh   "GETUPVAL",
27*8e3e3a7aSWarner Losh   "GETTABUP",
28*8e3e3a7aSWarner Losh   "GETTABLE",
29*8e3e3a7aSWarner Losh   "SETTABUP",
30*8e3e3a7aSWarner Losh   "SETUPVAL",
31*8e3e3a7aSWarner Losh   "SETTABLE",
32*8e3e3a7aSWarner Losh   "NEWTABLE",
33*8e3e3a7aSWarner Losh   "SELF",
34*8e3e3a7aSWarner Losh   "ADD",
35*8e3e3a7aSWarner Losh   "SUB",
36*8e3e3a7aSWarner Losh   "MUL",
37*8e3e3a7aSWarner Losh   "MOD",
38*8e3e3a7aSWarner Losh   "POW",
39*8e3e3a7aSWarner Losh   "DIV",
40*8e3e3a7aSWarner Losh   "IDIV",
41*8e3e3a7aSWarner Losh   "BAND",
42*8e3e3a7aSWarner Losh   "BOR",
43*8e3e3a7aSWarner Losh   "BXOR",
44*8e3e3a7aSWarner Losh   "SHL",
45*8e3e3a7aSWarner Losh   "SHR",
46*8e3e3a7aSWarner Losh   "UNM",
47*8e3e3a7aSWarner Losh   "BNOT",
48*8e3e3a7aSWarner Losh   "NOT",
49*8e3e3a7aSWarner Losh   "LEN",
50*8e3e3a7aSWarner Losh   "CONCAT",
51*8e3e3a7aSWarner Losh   "JMP",
52*8e3e3a7aSWarner Losh   "EQ",
53*8e3e3a7aSWarner Losh   "LT",
54*8e3e3a7aSWarner Losh   "LE",
55*8e3e3a7aSWarner Losh   "TEST",
56*8e3e3a7aSWarner Losh   "TESTSET",
57*8e3e3a7aSWarner Losh   "CALL",
58*8e3e3a7aSWarner Losh   "TAILCALL",
59*8e3e3a7aSWarner Losh   "RETURN",
60*8e3e3a7aSWarner Losh   "FORLOOP",
61*8e3e3a7aSWarner Losh   "FORPREP",
62*8e3e3a7aSWarner Losh   "TFORCALL",
63*8e3e3a7aSWarner Losh   "TFORLOOP",
64*8e3e3a7aSWarner Losh   "SETLIST",
65*8e3e3a7aSWarner Losh   "CLOSURE",
66*8e3e3a7aSWarner Losh   "VARARG",
67*8e3e3a7aSWarner Losh   "EXTRAARG",
68*8e3e3a7aSWarner Losh   NULL
69*8e3e3a7aSWarner Losh };
70*8e3e3a7aSWarner Losh 
71*8e3e3a7aSWarner Losh 
72*8e3e3a7aSWarner Losh #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
73*8e3e3a7aSWarner Losh 
74*8e3e3a7aSWarner Losh LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
75*8e3e3a7aSWarner Losh /*       T  A    B       C     mode		   opcode	*/
76*8e3e3a7aSWarner Losh   opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_MOVE */
77*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgN, iABx)		/* OP_LOADK */
78*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgN, OpArgN, iABx)		/* OP_LOADKX */
79*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_LOADBOOL */
80*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_LOADNIL */
81*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_GETUPVAL */
82*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgK, iABC)		/* OP_GETTABUP */
83*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgK, iABC)		/* OP_GETTABLE */
84*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgK, OpArgK, iABC)		/* OP_SETTABUP */
85*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgU, OpArgN, iABC)		/* OP_SETUPVAL */
86*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgK, OpArgK, iABC)		/* OP_SETTABLE */
87*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_NEWTABLE */
88*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgK, iABC)		/* OP_SELF */
89*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_ADD */
90*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_SUB */
91*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_MUL */
92*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_MOD */
93*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_POW */
94*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_DIV */
95*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_IDIV */
96*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_BAND */
97*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_BOR */
98*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_BXOR */
99*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_SHL */
100*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_SHR */
101*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_UNM */
102*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_BNOT */
103*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_NOT */
104*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_LEN */
105*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgR, iABC)		/* OP_CONCAT */
106*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgR, OpArgN, iAsBx)		/* OP_JMP */
107*8e3e3a7aSWarner Losh  ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_EQ */
108*8e3e3a7aSWarner Losh  ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_LT */
109*8e3e3a7aSWarner Losh  ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_LE */
110*8e3e3a7aSWarner Losh  ,opmode(1, 0, OpArgN, OpArgU, iABC)		/* OP_TEST */
111*8e3e3a7aSWarner Losh  ,opmode(1, 1, OpArgR, OpArgU, iABC)		/* OP_TESTSET */
112*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_CALL */
113*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_TAILCALL */
114*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgU, OpArgN, iABC)		/* OP_RETURN */
115*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_FORLOOP */
116*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_FORPREP */
117*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgN, OpArgU, iABC)		/* OP_TFORCALL */
118*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_TFORLOOP */
119*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgU, OpArgU, iABC)		/* OP_SETLIST */
120*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgN, iABx)		/* OP_CLOSURE */
121*8e3e3a7aSWarner Losh  ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_VARARG */
122*8e3e3a7aSWarner Losh  ,opmode(0, 0, OpArgU, OpArgU, iAx)		/* OP_EXTRAARG */
123*8e3e3a7aSWarner Losh };
124*8e3e3a7aSWarner Losh 
125