浏览代码

Opcode names moved to a new header file

The array with the names of the opcodes was moved to a header file
('lopnames.h'), as it is not used by the Lua kernel. Files that need
that array ('luac.c' and 'ltests.c') include the header file to get
a private (static) copy.
Roberto Ierusalimschy 7 年之前
父节点
当前提交
b08c9079c5
共有 4 个文件被更改,包括 100 次插入94 次删除
  1. 1 87
      lopcodes.c
  2. 1 4
      lopcodes.h
  3. 94 0
      lopnames.h
  4. 4 3
      ltests.c

+ 1 - 87
lopcodes.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lopcodes.c,v 1.81 2018/04/04 14:23:41 roberto Exp roberto $
+** $Id: lopcodes.c,v 1.83 2018/06/26 18:00:55 roberto Exp $
 ** Opcodes for Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -17,92 +17,6 @@
 
 /* ORDER OP */
 
-#if defined(LUAI_DEFOPNAMES)
-
-LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
-  "MOVE",
-  "LOADI",
-  "LOADF",
-  "LOADK",
-  "LOADKX",
-  "LOADBOOL",
-  "LOADNIL",
-  "GETUPVAL",
-  "SETUPVAL",
-  "GETTABUP",
-  "GETTABLE",
-  "GETI",
-  "GETFIELD",
-  "SETTABUP",
-  "SETTABLE",
-  "SETI",
-  "SETFIELD",
-  "NEWTABLE",
-  "SELF",
-  "ADDI",
-  "SUBI",
-  "MULI",
-  "MODI",
-  "POWI",
-  "DIVI",
-  "IDIVI",
-  "BANDK",
-  "BORK",
-  "BXORK",
-  "SHRI",
-  "SHLI",
-  "ADD",
-  "SUB",
-  "MUL",
-  "MOD",
-  "POW",
-  "DIV",
-  "IDIV",
-  "BAND",
-  "BOR",
-  "BXOR",
-  "SHL",
-  "SHR",
-  "UNM",
-  "BNOT",
-  "NOT",
-  "LEN",
-  "CONCAT",
-  "CLOSE",
-  "JMP",
-  "EQ",
-  "LT",
-  "LE",
-  "EQK",
-  "EQI",
-  "LTI",
-  "LEI",
-  "GTI",
-  "GEI",
-  "TEST",
-  "TESTSET",
-  "CALL",
-  "TAILCALL",
-  "RETURN",
-  "RETURN0",
-  "RETURN1",
-  "FORLOOP1",
-  "FORPREP1",
-  "FORLOOP",
-  "FORPREP",
-  "TFORCALL",
-  "TFORLOOP",
-  "SETLIST",
-  "CLOSURE",
-  "VARARG",
-  "PREPVARARG",
-  "EXTRAARG",
-  NULL
-};
-
-#endif
-
-
 LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
 /*       OT IT T  A  mode		   opcode  */
   opmode(0, 0, 0, 1, iABC)		/* OP_MOVE */

+ 1 - 4
lopcodes.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lopcodes.h,v 1.192 2018/06/08 19:07:27 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.194 2018/06/26 18:00:55 roberto Exp $
 ** Opcodes for Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -358,9 +358,6 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];)
 #define opmode(ot,it,t,a,m) (((ot)<<6) | ((it)<<5) | ((t)<<4) | ((a)<<3) | (m))
 
 
-LUAI_DDEC(const char *const luaP_opnames[NUM_OPCODES+1];)  /* opcode names */
-
-
 /* number of list items to accumulate before a SETLIST instruction */
 #define LFIELDS_PER_FLUSH	50
 

+ 94 - 0
lopnames.h

@@ -0,0 +1,94 @@
+/*
+** $Id: lopnames.h,v 1.1 2018/06/26 18:00:55 roberto Exp $
+** Opcode names
+** See Copyright Notice in lua.h
+*/
+
+#if !defined(lopnames_h)
+#define lopnames_h
+
+/* ORDER OP */
+
+static const char *const opnames[] = {
+  "MOVE",
+  "LOADI",
+  "LOADF",
+  "LOADK",
+  "LOADKX",
+  "LOADBOOL",
+  "LOADNIL",
+  "GETUPVAL",
+  "SETUPVAL",
+  "GETTABUP",
+  "GETTABLE",
+  "GETI",
+  "GETFIELD",
+  "SETTABUP",
+  "SETTABLE",
+  "SETI",
+  "SETFIELD",
+  "NEWTABLE",
+  "SELF",
+  "ADDI",
+  "SUBI",
+  "MULI",
+  "MODI",
+  "POWI",
+  "DIVI",
+  "IDIVI",
+  "BANDK",
+  "BORK",
+  "BXORK",
+  "SHRI",
+  "SHLI",
+  "ADD",
+  "SUB",
+  "MUL",
+  "MOD",
+  "POW",
+  "DIV",
+  "IDIV",
+  "BAND",
+  "BOR",
+  "BXOR",
+  "SHL",
+  "SHR",
+  "UNM",
+  "BNOT",
+  "NOT",
+  "LEN",
+  "CONCAT",
+  "CLOSE",
+  "JMP",
+  "EQ",
+  "LT",
+  "LE",
+  "EQK",
+  "EQI",
+  "LTI",
+  "LEI",
+  "GTI",
+  "GEI",
+  "TEST",
+  "TESTSET",
+  "CALL",
+  "TAILCALL",
+  "RETURN",
+  "RETURN0",
+  "RETURN1",
+  "FORLOOP1",
+  "FORPREP1",
+  "FORLOOP",
+  "FORPREP",
+  "TFORCALL",
+  "TFORLOOP",
+  "SETLIST",
+  "CLOSURE",
+  "VARARG",
+  "PREPVARARG",
+  "EXTRAARG",
+  NULL
+};
+
+#endif
+

+ 4 - 3
ltests.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltests.c,v 2.244 2018/06/11 14:19:50 roberto Exp roberto $
+** $Id: ltests.c,v 2.246 2018/06/26 18:00:55 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 */
@@ -27,6 +27,7 @@
 #include "lfunc.h"
 #include "lmem.h"
 #include "lopcodes.h"
+#include "lopnames.h"
 #include "lstate.h"
 #include "lstring.h"
 #include "ltable.h"
@@ -523,7 +524,7 @@ int lua_checkmemory (lua_State *L) {
 static char *buildop (Proto *p, int pc, char *buff) {
   Instruction i = p->code[pc];
   OpCode o = GET_OPCODE(i);
-  const char *name = luaP_opnames[o];
+  const char *name = opnames[o];
   int line = luaG_getfuncline(p, pc);
   sprintf(buff, "(%4d) %4d - ", line, pc);
   switch (getOpMode(o)) {
@@ -599,7 +600,7 @@ static int printcode (lua_State *L) {
   printf("numparams: %d\n", p->numparams);
   for (pc=0; pc<p->sizecode; pc++) {
     char buff[100];
-    printf("%d\t%s\n", pc + 1, buildop(p, pc, buff));
+    printf("%s\n", buildop(p, pc, buff));
   }
   return 0;
 }