Browse Source

new module lopcodes.c for tables describing opcodes

Roberto Ierusalimschy 24 years ago
parent
commit
2a4afb97c8
5 changed files with 35 additions and 117 deletions
  1. 1 50
      ldebug.c
  2. 1 20
      ldebug.h
  3. 28 1
      lopcodes.h
  4. 2 45
      ltests.c
  5. 3 1
      ltests.h

+ 1 - 50
ldebug.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldebug.c,v 1.84 2001/06/26 13:20:45 roberto Exp roberto $
+** $Id: ldebug.c,v 1.85 2001/06/28 14:57:17 roberto Exp roberto $
 ** Debug Interface
 ** Debug Interface
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -563,52 +563,3 @@ void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
     luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2);
     luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2);
 }
 }
 
 
-
-
-#define opmode(t,a,b,c,sa,k,m) (((t)<<OpModeT) | \
-   ((b)<<OpModeBreg) | ((c)<<OpModeCreg) | \
-   ((sa)<<OpModesetA) | ((k)<<OpModeK) | (m))
-
-
-const lu_byte luaG_opmodes[] = {
-/*       T J B C sA K mode		   opcode    */
-  opmode(0,0,1,0, 1,0,iABC),		/* OP_MOVE */
-  opmode(0,0,0,0, 1,1,iABc),		/* OP_LOADK */
-  opmode(0,0,0,0, 1,0,iAsBc),		/* OP_LOADINT */
-  opmode(0,0,1,0, 1,0,iABC),		/* OP_LOADNIL */
-  opmode(0,0,0,0, 1,0,iABc),		/* OP_LOADUPVAL */
-  opmode(0,0,0,0, 1,1,iABc),		/* OP_GETGLOBAL */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_GETTABLE */
-  opmode(0,0,0,0, 0,1,iABc),		/* OP_SETGLOBAL */
-  opmode(0,0,1,1, 0,0,iABC),		/* OP_SETTABLE */
-  opmode(0,0,0,0, 1,0,iABc),		/* OP_NEWTABLE */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_SELF */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_ADD */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_SUB */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_MUL */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_DIV */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_POW */
-  opmode(0,0,1,0, 1,0,iABC),		/* OP_UNM */
-  opmode(0,0,1,0, 1,0,iABC),		/* OP_NOT */
-  opmode(0,0,1,1, 1,0,iABC),		/* OP_CONCAT */
-  opmode(0,1,0,0, 0,0,iAsBc),		/* OP_JMP */
-  opmode(0,1,0,0, 0,0,iAsBc),		/* OP_CJMP */
-  opmode(1,0,0,1, 0,0,iABC),		/* OP_TESTEQ */
-  opmode(1,0,0,1, 0,0,iABC),		/* OP_TESTNE */
-  opmode(1,0,0,1, 0,0,iABC),		/* OP_TESTLT */
-  opmode(1,0,0,1, 0,0,iABC),		/* OP_TESTLE */
-  opmode(1,0,0,1, 0,0,iABC),		/* OP_TESTGT */
-  opmode(1,0,0,1, 0,0,iABC),		/* OP_TESTGE */
-  opmode(1,0,1,0, 1,0,iABC),		/* OP_TESTT */
-  opmode(1,0,1,0, 1,0,iABC),		/* OP_TESTF */
-  opmode(0,0,0,0, 1,0,iAsBc),		/* OP_NILJMP */
-  opmode(0,0,0,0, 0,0,iABC),		/* OP_CALL */
-  opmode(0,0,0,0, 0,0,iABC),		/* OP_RETURN */
-  opmode(0,0,0,0, 0,0,iAsBc),		/* OP_FORPREP */
-  opmode(0,0,0,0, 0,0,iAsBc),		/* OP_FORLOOP */
-  opmode(0,1,0,0, 0,0,iAsBc),		/* OP_TFORPREP */
-  opmode(0,1,0,0, 0,0,iAsBc),		/* OP_TFORLOOP */
-  opmode(0,0,0,0, 0,0,iABc),		/* OP_SETLIST */
-  opmode(0,0,0,0, 0,0,iABc),		/* OP_SETLIST0 */
-  opmode(0,0,0,0, 0,0,iABc)		/* OP_CLOSURE */
-};

+ 1 - 20
ldebug.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldebug.h,v 1.13 2001/06/06 17:50:36 roberto Exp roberto $
+** $Id: ldebug.h,v 1.14 2001/06/11 14:56:42 roberto Exp roberto $
 ** Auxiliary functions from Debug Interface module
 ** Auxiliary functions from Debug Interface module
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -12,25 +12,6 @@
 #include "luadebug.h"
 #include "luadebug.h"
 
 
 
 
-enum OpMode {iABC, iABc, iAsBc};  /* basic instruction format */
-
-/*
-** masks for instruction properties
-*/
-enum OpModeMask {
-  OpModeBreg = 2,	/* B is a register */
-  OpModeCreg,		/* C is a register/constant */
-  OpModesetA,		/* instruction set register A */
-  OpModeK,		/* Bc is a constant */
-  OpModeT		/* operator is a test */
-};
-
-extern const lu_byte luaG_opmodes[];
-
-#define getOpMode(m)		((enum OpMode)(luaG_opmodes[m] & 3))
-#define testOpMode(m, b)	(luaG_opmodes[m] & (1 << (b)))
-
-
 void luaG_typeerror (lua_State *L, StkId o, const l_char *op);
 void luaG_typeerror (lua_State *L, StkId o, const l_char *op);
 void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
 void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
 void luaG_aritherror (lua_State *L, StkId p1, TObject *p2);
 void luaG_aritherror (lua_State *L, StkId p1, TObject *p2);

+ 28 - 1
lopcodes.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lopcodes.h,v 1.74 2001/06/08 19:00:57 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.75 2001/06/11 14:56:42 roberto Exp roberto $
 ** Opcodes for Lua virtual machine
 ** Opcodes for Lua virtual machine
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -28,6 +28,9 @@
 ===========================================================================*/
 ===========================================================================*/
 
 
 
 
+enum OpMode {iABC, iABc, iAsBc};  /* basic instruction format */
+
+
 /*
 /*
 ** size and position of opcode arguments.
 ** size and position of opcode arguments.
 */
 */
@@ -198,4 +201,28 @@ OP_CLOSURE /*	A Bc	R(A) := closure(KPROTO[Bc], R(A), ... ,R(A+n))	*/
 ===========================================================================*/
 ===========================================================================*/
 
 
 
 
+
+/*
+** masks for instruction properties
+*/  
+enum OpModeMask {
+  OpModeBreg = 2,       /* B is a register */
+  OpModeCreg,           /* C is a register/constant */
+  OpModesetA,           /* instruction set register A */
+  OpModeK,              /* Bc is a constant */
+  OpModeT               /* operator is a test */
+};
+
+extern const lu_byte luaP_opmodes[];
+
+#define getOpMode(m)            ((enum OpMode)(luaP_opmodes[m] & 3))
+#define testOpMode(m, b)        (luaP_opmodes[m] & (1 << (b)))
+
+
+/*
+** opcode names (only included when compiled with LUA_OPNAMES)
+*/
+extern const l_char *const luaP_opnames[];
+
+
 #endif
 #endif

+ 2 - 45
ltests.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltests.c,v 1.84 2001/06/26 13:20:45 roberto Exp roberto $
+** $Id: ltests.c,v 1.85 2001/06/28 15:06:20 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -139,53 +139,10 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
 */
 */
 
 
 
 
-static const l_char *const instrname[NUM_OPCODES] = {
-  l_s("OP_MOVE"),
-  l_s("OP_LOADK"),
-  l_s("OP_LOADINT"),
-  l_s("OP_LOADNIL"),
-  l_s("OP_LOADUPVAL"),
-  l_s("OP_GETGLOBAL"),
-  l_s("OP_GETTABLE"),
-  l_s("OP_SETGLOBAL"),
-  l_s("OP_SETTABLE"),
-  l_s("OP_NEWTABLE"),
-  l_s("OP_SELF"),
-  l_s("OP_ADD"),
-  l_s("OP_SUB"),
-  l_s("OP_MUL"),
-  l_s("OP_DIV"),
-  l_s("OP_POW"),
-  l_s("OP_UNM"),
-  l_s("OP_NOT"),
-  l_s("OP_CONCAT"),
-  l_s("OP_JMP"),
-  l_s("OP_CJMP"),
-  l_s("OP_TESTEQ"),
-  l_s("OP_TESTNE"),
-  l_s("OP_TESTLT"),
-  l_s("OP_TESTLE"),
-  l_s("OP_TESTGT"),
-  l_s("OP_TESTGE"),
-  l_s("OP_TESTT"),
-  l_s("OP_TESTF"),
-  l_s("OP_NILJMP"),
-  l_s("OP_CALL"),
-  l_s("OP_RETURN"),
-  l_s("OP_FORPREP"),
-  l_s("OP_FORLOOP"),
-  l_s("OP_LFORPREP"),
-  l_s("OP_LFORLOOP"),
-  l_s("OP_SETLIST"),
-  l_s("OP_SETLIST0"),
-  l_s("OP_CLOSURE")
-};
-
-
 static l_char *buildop (Proto *p, int pc, l_char *buff) {
 static l_char *buildop (Proto *p, int pc, l_char *buff) {
   Instruction i = p->code[pc];
   Instruction i = p->code[pc];
   OpCode o = GET_OPCODE(i);
   OpCode o = GET_OPCODE(i);
-  const l_char *name = instrname[o];
+  const l_char *name = luaP_opnames[o];
   sprintf(buff, l_s("%4d - "), pc);
   sprintf(buff, l_s("%4d - "), pc);
   switch (getOpMode(o)) {  
   switch (getOpMode(o)) {  
     case iABC:
     case iABC:

+ 3 - 1
ltests.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltests.h,v 1.5 2001/02/12 15:42:44 roberto Exp roberto $
+** $Id: ltests.h,v 1.6 2001/03/02 17:27:50 roberto Exp roberto $
 ** Internal Header for Debugging of the Lua Implementation
 ** Internal Header for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -13,6 +13,8 @@
 
 
 #define LUA_DEBUG
 #define LUA_DEBUG
 
 
+#define LUA_OPNAMES
+
 #undef NDEBUG
 #undef NDEBUG
 #include <assert.h>
 #include <assert.h>
 #define lua_assert(c)           assert(c)
 #define lua_assert(c)           assert(c)