src/Opcodes.tbl
changeset 195 c1ba166f3fc4
parent 194 b029d63565a2
child 208 7c5be05296e3
     1.1 --- a/src/Opcodes.tbl	Mon Sep 17 00:10:01 2012 -0700
     1.2 +++ b/src/Opcodes.tbl	Sat Nov 17 18:41:01 2012 -0800
     1.3 @@ -17,7 +17,7 @@
     1.4   * JITCraft. If not, see http://www.gnu.org/licenses/.
     1.5   */
     1.6  // Opcode macros:
     1.7 -//  NAME            NUMBER      TEXT                LENGTH  USES  DEFS   
     1.8 +//  NAME                TEXT            LENGTH  USES  DEFS   
     1.9  //
    1.10  // Type suffixes:
    1.11  //  I = 32-bit integer
    1.12 @@ -25,83 +25,62 @@
    1.13  //  O = object reference
    1.14  
    1.15  // No operation.
    1.16 -OPDEF(OP_NOP,           0,          "nop",          1,      0,  0)
    1.17 +OPDEF(OP_NOP,           "nop",          1,      0,  0)
    1.18  
    1.19  // Pushes a signed integer immediate onto the stack.
    1.20 -OPDEF(OP_INT,           1,          "int",          5,      0,  1)    
    1.21 +OPDEF(OP_INT,           "int",          5,      0,  1)    
    1.22  
    1.23  // Returns from the current routine, propagating the value at the top of the
    1.24  // stack to the caller.
    1.25 -OPDEF(OP_RETURN,        2,          "return",       1,      1,  0)
    1.26 -
    1.27 -// Stack transitions for these comparison ops:
    1.28 -// rhs = pop()
    1.29 -// lhs = pop()
    1.30 -// if (lhs COMPARE rhs)
    1.31 -//    goto target (immediate, relative to the beginning of the jump instruction)
    1.32 -OPDEF(OP_JL,            3,          "jl",           5,      2,  0)
    1.33 -OPDEF(OP_JLE,           4,          "jle",          5,      2,  0)
    1.34 -OPDEF(OP_JG,            5,          "jg",           5,      2,  0)
    1.35 -OPDEF(OP_JGE,           6,          "jge",          5,      2,  0)
    1.36 -OPDEF(OP_JEQ,           7,          "jeq",          5,      2,  0)
    1.37 -OPDEF(OP_JNE,           8,          "jne",          5,      2,  0)
    1.38 +OPDEF(OP_RETURN,        "return",       1,      1,  0)
    1.39  
    1.40  // value = pop()
    1.41  // if (value == [true, false])
    1.42  //    goto target
    1.43 -OPDEF(OP_JT,            9,          "jt",           5,      1,  0)
    1.44 -OPDEF(OP_JF,            10,         "jf",           5,      1,  0)
    1.45 -
    1.46 -OPDEF(OP_JL_F,          11,         "jl.f",         5,      2,  0)
    1.47 -OPDEF(OP_JLE_F,         12,         "jle.f",        5,      2,  0)
    1.48 -OPDEF(OP_JG_F,          13,         "jg.f",         5,      2,  0)
    1.49 -OPDEF(OP_JGE_F,         14,         "jge.f",        5,      2,  0)
    1.50 -OPDEF(OP_JEQ_F,         15,         "jeq.f",        5,      2,  0)
    1.51 -OPDEF(OP_JNE_F,         16,         "jne.f",        5,      2,  0)
    1.52 -OPDEF(OP_JT_F,          17,         "jt.f",         5,      1,  0)
    1.53 -OPDEF(OP_JF_F,          18,         "jf.f",         5,      1,  0)
    1.54 +OPDEF(OP_JT,            "jt",           5,      1,  0)
    1.55 +OPDEF(OP_JF,            "jf",           5,      1,  0)
    1.56  
    1.57  // Unconditional jump.
    1.58 -OPDEF(OP_JUMP,          19,         "jump",         5,      0,  0)
    1.59 +OPDEF(OP_JUMP,          "jump",         5,      0,  0)
    1.60  
    1.61  // Gets or sets the value of a local variable onto the stack. The local
    1.62  // variable is given by an immediate index.
    1.63 -OPDEF(OP_GETLOCAL,      20,         "getlocal",     5,      0,  1)
    1.64 -OPDEF(OP_SETLOCAL,      21,         "setlocal",     5,      1,  1)
    1.65 +OPDEF(OP_GETLOCAL,      "getlocal",     5,      0,  1)
    1.66 +OPDEF(OP_SETLOCAL,      "setlocal",     5,      1,  1)
    1.67  
    1.68  // Stack transitions for these binary operators:
    1.69  // rhs = pop()
    1.70  // lhs = pop()
    1.71  // push(lhs OP rhs)
    1.72 -OPDEF(OP_ADD,           22,         "add",          1,      2,  1)
    1.73 -OPDEF(OP_SUB,           23,         "sub",          1,      2,  1)
    1.74 -OPDEF(OP_MUL,           24,         "mul",          1,      2,  1)
    1.75 -OPDEF(OP_DIV,           25,         "div",          1,      2,  1)
    1.76 -OPDEF(OP_MOD,           26,         "mod",          1,      2,  1)
    1.77 +OPDEF(OP_ADD,           "add",          1,      2,  1)
    1.78 +OPDEF(OP_SUB,           "sub",          1,      2,  1)
    1.79 +OPDEF(OP_MUL,           "mul",          1,      2,  1)
    1.80 +OPDEF(OP_DIV,           "div",          1,      2,  1)
    1.81 +OPDEF(OP_MOD,           "mod",          1,      2,  1)
    1.82  
    1.83 -OPDEF(OP_LT,            27,         "lt",           1,      2,  1)
    1.84 -OPDEF(OP_LE,            28,         "le",           1,      2,  1)
    1.85 -OPDEF(OP_GE,            29,         "ge",           1,      2,  1)
    1.86 -OPDEF(OP_GT,            30,         "gt",           1,      2,  1)
    1.87 -OPDEF(OP_EQ,            31,         "eq",           1,      2,  1)
    1.88 -OPDEF(OP_NE,            32,         "ne",           1,      2,  1)
    1.89 +OPDEF(OP_LT,            "lt",           1,      2,  1)
    1.90 +OPDEF(OP_LE,            "le",           1,      2,  1)
    1.91 +OPDEF(OP_GE,            "ge",           1,      2,  1)
    1.92 +OPDEF(OP_GT,            "gt",           1,      2,  1)
    1.93 +OPDEF(OP_EQ,            "eq",           1,      2,  1)
    1.94 +OPDEF(OP_NE,            "ne",           1,      2,  1)
    1.95  
    1.96 -OPDEF(OP_NOT,           33,         "not",          1,      1,  1)
    1.97 -OPDEF(OP_NEG,           34,         "neg",          1,      1,  1)
    1.98 +OPDEF(OP_NOT,           "not",          1,      1,  1)
    1.99 +OPDEF(OP_NEG,           "neg",          1,      1,  1)
   1.100  
   1.101 -OPDEF(OP_POP,           35,         "pop",          1,      1,  0)
   1.102 +OPDEF(OP_POP,           "pop",          1,      1,  0)
   1.103  
   1.104  // Unconditional terminator placed at the end of code. If a function returns
   1.105  // void, this acts as a RETURNVOID. Otherwise, it must be unreachable.
   1.106 -OPDEF(OP_STOP,          36,         "stop",         1,      0,  0)
   1.107 +OPDEF(OP_STOP,          "stop",         1,      0,  0)
   1.108  
   1.109  // Call a function with N arguments. The target function must be the last item
   1.110  // on the stack.
   1.111 -OPDEF(OP_CALL,          37,         "call",         1,      -1, 1)
   1.112 +OPDEF(OP_CALL,          "call",         1,      -1, 1)
   1.113  
   1.114  // Similar to GET/LOCAL, except for arguments.
   1.115 -OPDEF(OP_GETARG,        38,         "getarg",       5,      0,  1)
   1.116 -OPDEF(OP_SETARG,        39,         "setarg",       5,      1,  1)
   1.117 +OPDEF(OP_GETARG,        "getarg",       5,      0,  1)
   1.118 +OPDEF(OP_SETARG,        "setarg",       5,      1,  1)
   1.119  
   1.120  // Allocates either:
   1.121  //   A fixed array, 
   1.122 @@ -113,83 +92,83 @@
   1.123  //
   1.124  // Format:
   1.125  //  [u8 op] [u8 tenure] [u32 index]
   1.126 -OPDEF(OP_NEWFIXED,      40,         "newfixed",     6,      0, 1)
   1.127 -OPDEF(OP_NEWEMPTY,      41,         "newempty",     6,      0, 1)
   1.128 -OPDEF(OP_NEWSIZED,      42,         "newsized",     6,     -1, 1)
   1.129 +OPDEF(OP_NEWFIXED,      "newfixed",     6,      0, 1)
   1.130 +OPDEF(OP_NEWEMPTY,      "newempty",     6,      0, 1)
   1.131 +OPDEF(OP_NEWSIZED,      "newsized",     6,     -1, 1)
   1.132  
   1.133  // Performs an array-to-array assignment.
   1.134  //   Left = pop()
   1.135  //   Right = pop()
   1.136  //   copy(Left, Right)
   1.137  //   push(Left)
   1.138 -OPDEF(OP_COPYARRAY,     43,         "arraycopy",    1,      2,  1)
   1.139 +OPDEF(OP_COPYARRAY,     "arraycopy",    1,      2,  1)
   1.140  
   1.141  // Reads or writes an integer element to an unsafe array.
   1.142  //  index = pop()
   1.143  //  ref = pop()
   1.144  //  ref[index]
   1.145  //
   1.146 -OPDEF(OP_GETELEM,       44,         "getelem",      1,      2,  1)
   1.147 -OPDEF(OP_SETELEM,       45,         "setelem",      1,      3,  1)
   1.148 +OPDEF(OP_GETELEM,       "getelem",      1,      2,  1)
   1.149 +OPDEF(OP_SETELEM,       "setelem",      1,      3,  1)
   1.150  
   1.151  // Pushes a 32-bit IEEE-754 floating point immediate onto the stack.
   1.152 -OPDEF(OP_FLOAT,         46,         "float",        5,      0,  1)
   1.153 +OPDEF(OP_FLOAT,         "float",        5,      0,  1)
   1.154  
   1.155  // Converts an integer to a 32-bit IEEE-754 floating point immediate.
   1.156 -OPDEF(OP_CVT_I2F,       47,         "cvt.i2f",      1,      1,  1)
   1.157 +OPDEF(OP_CVT_I2F,       "cvt.i2f",      1,      1,  1)
   1.158  
   1.159  // Stack transitions for these binary operators:
   1.160  // rhs = pop()
   1.161  // lhs = pop()
   1.162  // push(lhs OP rhs)
   1.163 -OPDEF(OP_ADD_F,         48,         "add.f",        1,      2,  1)
   1.164 -OPDEF(OP_SUB_F,         49,         "sub.f",        1,      2,  1)
   1.165 -OPDEF(OP_MUL_F,         50,         "mul.f",        1,      2,  1)
   1.166 -OPDEF(OP_DIV_F,         51,         "div.f",        1,      2,  1)
   1.167 +OPDEF(OP_ADD_F,         "add.f",        1,      2,  1)
   1.168 +OPDEF(OP_SUB_F,         "sub.f",        1,      2,  1)
   1.169 +OPDEF(OP_MUL_F,         "mul.f",        1,      2,  1)
   1.170 +OPDEF(OP_DIV_F,         "div.f",        1,      2,  1)
   1.171  
   1.172 -OPDEF(OP_LT_F,          52,         "lt.f",         1,      2,  1)
   1.173 -OPDEF(OP_LE_F,          53,         "le.f",         1,      2,  1)
   1.174 -OPDEF(OP_GE_F,          54,         "ge.f",         1,      2,  1)
   1.175 -OPDEF(OP_GT_F,          55,         "gt.f",         1,      2,  1)
   1.176 -OPDEF(OP_EQ_F,          56,         "eq.f",         1,      2,  1)
   1.177 -OPDEF(OP_NE_F,          57,         "ne.f",         1,      2,  1)
   1.178 +OPDEF(OP_LT_F,          "lt.f",         1,      2,  1)
   1.179 +OPDEF(OP_LE_F,          "le.f",         1,      2,  1)
   1.180 +OPDEF(OP_GE_F,          "ge.f",         1,      2,  1)
   1.181 +OPDEF(OP_GT_F,          "gt.f",         1,      2,  1)
   1.182 +OPDEF(OP_EQ_F,          "eq.f",         1,      2,  1)
   1.183 +OPDEF(OP_NE_F,          "ne.f",         1,      2,  1)
   1.184  
   1.185 -OPDEF(OP_NOT_F,         58,         "not.f",        1,      1,  1)
   1.186 -OPDEF(OP_NEG_F,         59,         "neg.f",        1,      1,  1)
   1.187 +OPDEF(OP_NOT_F,         "not.f",        1,      1,  1)
   1.188 +OPDEF(OP_NEG_F,         "neg.f",        1,      1,  1)
   1.189  
   1.190  // Bitwise operators.
   1.191 -OPDEF(OP_SHL,           60,         "shl",          1,      2,  1)
   1.192 -OPDEF(OP_SHR,           61,         "shr",          1,      2,  1)
   1.193 -OPDEF(OP_USHR,          62,         "ushr",         1,      2,  1)
   1.194 -OPDEF(OP_BITAND,        63,         "bitand",       1,      2,  1)
   1.195 -OPDEF(OP_BITOR,         64,         "bitor",        1,      2,  1)
   1.196 -OPDEF(OP_BITXOR,        65,         "bitxor",       1,      2,  1)
   1.197 -OPDEF(OP_BITNOT,        66,         "bitnot",       1,      1,  1)
   1.198 +OPDEF(OP_SHL,           "shl",          1,      2,  1)
   1.199 +OPDEF(OP_SHR,           "shr",          1,      2,  1)
   1.200 +OPDEF(OP_USHR,          "ushr",         1,      2,  1)
   1.201 +OPDEF(OP_BITAND,        "bitand",       1,      2,  1)
   1.202 +OPDEF(OP_BITOR,         "bitor",        1,      2,  1)
   1.203 +OPDEF(OP_BITXOR,        "bitxor",       1,      2,  1)
   1.204 +OPDEF(OP_BITNOT,        "bitnot",       1,      1,  1)
   1.205  
   1.206  // Saves or restores the position of the LIFO heap to/from a local slot.
   1.207 -OPDEF(OP_SAVELIFO,      67,         "savelifo",     5,      0,  0)
   1.208 -OPDEF(OP_UNWINDLIFO,    68,         "unwindlifo",   5,      0,  0)
   1.209 +OPDEF(OP_SAVELIFO,      "savelifo",     5,      0,  0)
   1.210 +OPDEF(OP_UNWINDLIFO,    "unwindlifo",   5,      0,  0)
   1.211  
   1.212  // Composes a variable reference to a stack slot or argument.
   1.213 -OPDEF(OP_VARREF_LIFO,   69,         "varref.lifo",  5,      0,  1)
   1.214 -OPDEF(OP_ARGREF_LIFO,   70,         "argref.lifo",  5,      0,  1)
   1.215 -OPDEF(OP_SLOTREF_LIFO,  71,         "slotref.lifo", 1,      1,  1)
   1.216 -OPDEF(OP_GETREF_I,      72,         "getref.i",     1,      1,  1)
   1.217 -OPDEF(OP_SETREF_I,      73,         "setref.i",     1,      2,  1)
   1.218 -OPDEF(OP_GETREF_F,      74,         "getref.f",     1,      1,  1)
   1.219 -OPDEF(OP_SETREF_F,      75,         "setref.f",     1,      2,  1)
   1.220 +OPDEF(OP_VARREF_LIFO,   "varref.lifo",  5,      0,  1)
   1.221 +OPDEF(OP_ARGREF_LIFO,   "argref.lifo",  5,      0,  1)
   1.222 +OPDEF(OP_SLOTREF_LIFO,  "slotref.lifo", 1,      1,  1)
   1.223 +OPDEF(OP_GETREF_I,      "getref.i",     1,      1,  1)
   1.224 +OPDEF(OP_SETREF_I,      "setref.i",     1,      2,  1)
   1.225 +OPDEF(OP_GETREF_F,      "getref.f",     1,      1,  1)
   1.226 +OPDEF(OP_SETREF_F,      "setref.f",     1,      2,  1)
   1.227  
   1.228  // Pushes an object reference onto the stack.
   1.229 -OPDEF(OP_OBJECT,        76,         "object",       5,      0,  1)
   1.230 +OPDEF(OP_OBJECT,        "object",       5,      0,  1)
   1.231  
   1.232  // Duplicates the top item on the stack.
   1.233 -OPDEF(OP_DUP,           77,         "dup",          1,      1,  2)
   1.234 +OPDEF(OP_DUP,           "dup",          1,      1,  2)
   1.235  
   1.236  // Duplicates the top two items on the stack.
   1.237 -OPDEF(OP_DUP2,          78,         "dup2",         1,      2,  4)
   1.238 +OPDEF(OP_DUP2,          "dup2",         1,      2,  4)
   1.239  
   1.240  // Swaps the two items at the top of the stack.
   1.241 -OPDEF(OP_SWAP,          79,         "swap",         1,      2,  2)
   1.242 +OPDEF(OP_SWAP,          "swap",         1,      2,  2)
   1.243  
   1.244  // Roll operation is the same as Forth. It steals a value on the stack,
   1.245  // shifting all stack values down, and then places the stolen value back at
   1.246 @@ -199,77 +178,68 @@
   1.247  //  sp[-3] = sp[-2]
   1.248  //  sp[-2] = sp[-1]
   1.249  //  sp[-1] = p
   1.250 -OPDEF(OP_ROLL3,         80,         "roll3",        1,      3, 3)
   1.251 +OPDEF(OP_ROLL3,         "roll3",        1,      3, 3)
   1.252  
   1.253  // Pick operation is the same as Forth. It pushes a copy of a slot at a
   1.254  // specific depth.
   1.255  //
   1.256  // push(sp[-n])
   1.257 -OPDEF(OP_PICK2,         81,         "pick2",        1,      2, 3)
   1.258 -OPDEF(OP_PICK3,         82,         "pick3",        1,      3, 4)
   1.259 +OPDEF(OP_PICK2,         "pick2",        1,      2, 3)
   1.260 +OPDEF(OP_PICK3,         "pick3",        1,      3, 4)
   1.261  
   1.262  // Calls a native function. During the course of calling a native, arguments
   1.263  // on the stack are re-pushed to match the cell-based native calling
   1.264  // convention expected by ISourcePawnEngine.
   1.265  //
   1.266  // Unlike the normal CALL instruction, natives take truly variadic arguments
   1.267 -// and so we must specify the number of arguments. The format is:
   1.268 +// and so we must specify the number of arguments.
   1.269  //
   1.270 -// [u8 Opcode] [u32 Index] [u32 ArgCount]
   1.271 +// [u8 Opcode] [u32 ArgCount]
   1.272  //
   1.273 -OPDEF(OP_CALLNATIVE,    83,         "callnative",   9,      -1, 1)
   1.274 +OPDEF(OP_CALLNATIVE,    "callnative",   5,     -1, 1)
   1.275  
   1.276  // Returns from a function that does return a value.
   1.277 -OPDEF(OP_RETURNVOID,    84,         "returnvoid",   1,      0, 0)
   1.278 -
   1.279 -// Loads the module of the running function.
   1.280 -OPDEF(OP_MODULE,        85,         "module",       1,      0, 1)
   1.281 +OPDEF(OP_RETURNVOID,    "returnvoid",   1,      0, 0)
   1.282  
   1.283 -// Loads a function from a module object. The operand is the slot number
   1.284 -// in the module.
   1.285 -OPDEF(OP_GETMODULE_FN,  86,         "getmodule.fn", 5,      1, 1)
   1.286 -
   1.287 -// Opcodes for accessing an environment slot in the global scope.
   1.288 -OPDEF(OP_SETGLOBAL_I,   87,         "setglobal.i",  5,      1, 1)
   1.289 -OPDEF(OP_SETGLOBAL_F,   88,         "setglobal.f",  5,      1, 1)
   1.290 -OPDEF(OP_SETGLOBAL_O,   89,         "setglobal.o",  5,      1, 1)
   1.291 -OPDEF(OP_GETGLOBAL_I,   90,         "getglobal.i",  5,      0, 1)
   1.292 -OPDEF(OP_GETGLOBAL_F,   91,         "getglobal.f",  5,      0, 1)
   1.293 -OPDEF(OP_GETGLOBAL_O,   92,         "getglobal.o",  5,      0, 1)
   1.294 +// Opcodes for accessing an environment slot in the global scope. The index
   1.295 +// maps into the code object's string table, and represents the name of the
   1.296 +// global variable.
   1.297 +OPDEF(OP_SETGLOBAL,     "setglobal",    5,      1, 1)
   1.298 +OPDEF(OP_GETGLOBAL,     "getglobal",    5,      0, 1)
   1.299  
   1.300  // Reinterprets a 32-bit integer as a float, or vice-versa.
   1.301 -OPDEF(OP_BITS_I2F,      93,         "bits.i2f",     1,      1, 1)
   1.302 -OPDEF(OP_BITS_F2I,      94,         "bits.f2i",     1,      1, 1)
   1.303 +OPDEF(OP_BITS_I2F,      "bits.i2f",     1,      1, 1)
   1.304 +OPDEF(OP_BITS_F2I,      "bits.f2i",     1,      1, 1)
   1.305  
   1.306  // Pushes a boolean value.
   1.307 -OPDEF(OP_TRUE,          95,         "true",         1,      0, 1)
   1.308 -OPDEF(OP_FALSE,         96,         "false",        1,      0, 1)
   1.309 +OPDEF(OP_TRUE,          "true",         1,      0, 1)
   1.310 +OPDEF(OP_FALSE,         "false",        1,      0, 1)
   1.311  
   1.312  // Allocate a struct. The HeapTenure is stored as a byte following pc. The
   1.313  // StructMap to use is specified as an index into the script's Map table.
   1.314  //
   1.315  // Format:
   1.316  //  [u8 op] [u8 tenure] [u32 index]
   1.317 -OPDEF(OP_NEWSTRUCT,     97,         "newstruct",    6,      0, 1)
   1.318 +OPDEF(OP_NEWSTRUCT,     "newstruct",    6,      0, 1)
   1.319  
   1.320  // Performs a struct-to-struct assignment.
   1.321  //   Left = pop()
   1.322  //   Right = pop()
   1.323  //   copy(Left, Right)
   1.324  //   push(Left)
   1.325 -OPDEF(OP_COPYSTRUCT,    98,         "structcopy",   1,      2, 1)
   1.326 +OPDEF(OP_COPYSTRUCT,    "structcopy",   1,      2, 1)
   1.327  
   1.328  // Sets or gets a property in a struct. The index of the field is specified as
   1.329  // a 32-bit integer. Note that these opcodes follow a new style of deriving
   1.330  // their types at runtime.
   1.331 -OPDEF(OP_GETFIELD,      99,         "getfield",     5,      1, 1)
   1.332 -OPDEF(OP_SETFIELD,      100,        "setfield",     5,      2, 1)
   1.333 -
   1.334 -OPDEF(OP_FIELDREF_LIFO, 101,        "fieldref.lifo", 5,     1, 1)
   1.335 +OPDEF(OP_GETFIELD,      "getfield",     5,      1, 1)
   1.336 +OPDEF(OP_SETFIELD,      "setfield",     5,      2, 1)
   1.337  
   1.338  // Table-based jump.
   1.339  // [u8 op] [i32 low] [i32 high] [u32 jump] [u32 jumps...]
   1.340 -OPDEF(OP_TABLESWITCH,   102,        "tableswitch",  9,      1, 0)
   1.341 +OPDEF(OP_TABLESWITCH,   "tableswitch",  9,      1, 0)
   1.342  
   1.343 -OPDEF(OP_SIZEOF,        103,        "sizeof",       1,      1, 1)
   1.344 +OPDEF(OP_SIZEOF,        "sizeof",       1,      1, 1)
   1.345  
   1.346 +// Registers a function as a publicly exported name.
   1.347 +OPDEF(OP_PUBLIC,        "public",       1,      1, 0)
   1.348 \ No newline at end of file