jitcraft/Opcodes.tbl
author David Anderson <dvander@alliedmods.net>
Tue Jul 10 02:11:13 2012 -0700 (2012-07-10)
changeset 68 b40b0e18a918
parent 47 050939c6181e
child 72 40746ab0a30b
permissions -rw-r--r--
Added support for ISourcePawnEngine natives.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of JITCraft.
     6  *
     7  * JITCraft is free software: you can redistribute it and/or modify it under
     8  * the terms of the GNU General Public License as published by the Free
     9  * Software Foundation, either version 3 of the License, or (at your option)
    10  * any later version.
    11  * 
    12  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * JITCraft. If not, see http://www.gnu.org/licenses/.
    18  */
    19 // Opcode macros:
    20 //  NAME            NUMBER      TEXT                LENGTH  USES  DEFS   
    21 //
    22 // Type suffixes:
    23 //  I = 32-bit integer
    24 //  F = 32-bit IEEE-754 float
    25 //  O = object reference
    26 
    27 // No operation.
    28 OPDEF(OP_NOP,           0,          "nop",          1,      0,  0)
    29 
    30 // Pushes a signed integer immediate onto the stack.
    31 OPDEF(OP_INT,           1,          "int",          5,      0,  1)    
    32 
    33 // Returns from the current routine, propagating the value at the top of the
    34 // stack to the caller.
    35 OPDEF(OP_RETURN,        2,          "return",       1,      1,  0)
    36 
    37 // Stack transitions for these comparison ops:
    38 // rhs = pop()
    39 // lhs = pop()
    40 // if (lhs COMPARE rhs)
    41 //    goto target (immediate, relative to the beginning of the jump instruction)
    42 OPDEF(OP_JL,            3,          "jl",           5,      2,  0)
    43 OPDEF(OP_JLE,           4,          "jle",          5,      2,  0)
    44 OPDEF(OP_JG,            5,          "jg",           5,      2,  0)
    45 OPDEF(OP_JGE,           6,          "jge",          5,      2,  0)
    46 OPDEF(OP_JEQ,           7,          "jeq",          5,      2,  0)
    47 OPDEF(OP_JNE,           8,          "jne",          5,      2,  0)
    48 
    49 // value = pop()
    50 // if (value == [true, false])
    51 //    goto target
    52 OPDEF(OP_JT,            9,          "jt",           5,      1,  0)
    53 OPDEF(OP_JF,            10,         "jf",           5,      1,  0)
    54 
    55 // Unconditional jump.
    56 OPDEF(OP_JUMP,          11,         "jump",         5,      0,  0)
    57 
    58 // Gets or sets the value of a local variable onto the stack. The local
    59 // variable is given by an immediate index.
    60 OPDEF(OP_GETLOCAL,      12,         "getlocal",     5,      0,  1)
    61 OPDEF(OP_SETLOCAL,      13,         "setlocal",     5,      1,  1)
    62 
    63 // Stack transitions for these binary operators:
    64 // rhs = pop()
    65 // lhs = pop()
    66 // push(lhs OP rhs)
    67 OPDEF(OP_ADD,           14,         "add",          1,      2,  1)
    68 OPDEF(OP_SUB,           15,         "sub",          1,      2,  1)
    69 OPDEF(OP_MUL,           16,         "mul",          1,      2,  1)
    70 OPDEF(OP_DIV,           17,         "div",          1,      2,  1)
    71 
    72 OPDEF(OP_POP,           18,         "pop",          1,      1,  0)
    73 
    74 // Unconditional terminator placed at the end of code.
    75 OPDEF(OP_STOP,          19,         "stop",         1,      0,  0)
    76 
    77 // Call a function with N arguments.
    78 //
    79 // CALLGLOBAL - followed by an extra immediate, containing the function index
    80 // in the code's global.
    81 OPDEF(OP_CALLGLOBAL,    20,         "callglobal",   5,      -1, 1)
    82 
    83 // Similar to GET/LOCAL, except for arguments.
    84 OPDEF(OP_GETARG,        21,         "getarg",       5,      0,  1)
    85 OPDEF(OP_SETARG,        22,         "setarg",       5,      1,  1)
    86 
    87 // Reads or writes an integer element to an unsafe array.
    88 //  index = pop()
    89 //  ref = pop()
    90 //  ref[index]
    91 //
    92 OPDEF(OP_GETARRAY_I,    23,         "getarray.i",   1,      2,  1)
    93 OPDEF(OP_SETARRAY_I,    24,         "setarray.i",   1,      3,  1)
    94 OPDEF(OP_GETARRAY_F,    25,         "getarray.f",   1,      2,  1)
    95 OPDEF(OP_SETARRAY_F,    26,         "setarray.f",   1,      3,  1)
    96 OPDEF(OP_GETARRAY_C,    27,         "getarray.c",   1,      2,  1)
    97 OPDEF(OP_SETARRAY_C,    28,         "setarray.c",   1,      3,  1)
    98 OPDEF(OP_GETARRAY_O,    29,         "getarray.o",   1,      2,  1)
    99 
   100 // Allocate an array, info LIFO space if possible. The ArrayMap to use is
   101 // specified as an index into the script's Map table.
   102 //
   103 // Format:
   104 //  [u8 op] [u32 index]
   105 OPDEF(OP_NEWARRAY_LIFO, 30,         "newarray.lifo", 5,     0,  1)
   106 
   107 // Performs a bounds check on an unsafe array.
   108 //
   109 // index = pop()
   110 // array = pop()
   111 // push(array)
   112 // push(index)
   113 OPDEF(OP_BOUNDS,        31,         "bounds",       1,      2,  2)
   114 
   115 // Pushes a 32-bit IEEE-754 floating point immediate onto the stack.
   116 OPDEF(OP_FLOAT,         32,         "float",        5,      0,  1)
   117 
   118 // Converts an integer to a 32-bit IEEE-754 floating point immediate.
   119 OPDEF(OP_CVT_I2F,       33,         "cvt.i2f",      1,      1,  1)
   120 
   121 // Stack transitions for these binary operators:
   122 // rhs = pop()
   123 // lhs = pop()
   124 // push(lhs OP rhs)
   125 OPDEF(OP_ADD_F,         34,         "add.f",        1,      2,  1)
   126 OPDEF(OP_SUB_F,         35,         "sub.f",        1,      2,  1)
   127 OPDEF(OP_MUL_F,         36,         "mul.f",        1,      2,  1)
   128 OPDEF(OP_DIV_F,         37,         "div.f",        1,      2,  1)
   129 
   130 // Bitwise operators.
   131 OPDEF(OP_SHL,           38,         "shl",          1,      2,  1)
   132 OPDEF(OP_SHR,           39,         "shr",          1,      2,  1)
   133 OPDEF(OP_USHR,          40,         "ushr",         1,      2,  1)
   134 OPDEF(OP_BITAND,        41,         "bitand",       1,      2,  1)
   135 OPDEF(OP_BITOR,         42,         "bitor",        1,      2,  1)
   136 OPDEF(OP_BITXOR,        43,         "bitxor",       1,      2,  1)
   137 
   138 // Saves or restores the position of the LIFO heap to/from a local slot.
   139 OPDEF(OP_SAVELIFO,      44,         "savelifo",     5,      0,  0)
   140 OPDEF(OP_UNWINDLIFO,    45,         "unwindlifo",   5,      0,  0)
   141 
   142 // Composes a variable reference to a stack slot or argument.
   143 OPDEF(OP_VARREF_LIFO,   46,         "varref.lifo",  5,      0,  1)
   144 OPDEF(OP_ARGREF_LIFO,   47,         "argref.lifo",  5,      0,  1)
   145 OPDEF(OP_SLOTREF_LIFO,  48,         "slotref.lifo", 1,      1,  1)
   146 OPDEF(OP_ARRAYREF_LIFO, 49,         "arrayref.lifo",1,      2,  1)
   147 OPDEF(OP_GETREF_I,      50,         "getref.i",     1,      1,  1)
   148 OPDEF(OP_SETREF_I,      51,         "setref.i",     1,      2,  1)
   149 OPDEF(OP_GETREF_F,      52,         "getref.f",     1,      1,  1)
   150 OPDEF(OP_SETREF_F,      53,         "setref.f",     1,      2,  1)
   151 
   152 // Pushes an object reference onto the stack.
   153 OPDEF(OP_OBJECT,        54,         "object",       5,      0,  1)
   154 
   155 // Performs an array-to-array assignment.
   156 //   Left = pop()
   157 //   Right = pop()
   158 //   copy(Left, Right)
   159 //   push(Left)
   160 OPDEF(OP_ARRAYCOPY,     55,         "arraycopy",    1,      2,  1)
   161 
   162 // Duplicates the top item on the stack.
   163 OPDEF(OP_DUP,           56,         "dup",          1,      1,  2)
   164 
   165 // Duplicates the top two items on the stack.
   166 OPDEF(OP_DUP2,          57,         "dup2",         1,      2,  4)
   167 
   168 // Swaps the two items at the top of the stack.
   169 OPDEF(OP_SWAP,          58,         "swap",         1,      2,  2)
   170 
   171 // Roll operation is the same as Forth. It steals a value on the stack,
   172 // shifting all stack values down, and then places the stolen value back at
   173 // the top of the stack.
   174 //
   175 //  p = sp[-3]
   176 //  sp[-3] = sp[-2]
   177 //  sp[-2] = sp[-1]
   178 //  sp[-1] = p
   179 OPDEF(OP_ROLL3,         59,         "roll3",        1,      3, 3)
   180 
   181 // Pick operation is the same as Forth. It pushes a copy of a slot at a
   182 // specific depth.
   183 //
   184 // push(sp[-n])
   185 OPDEF(OP_PICK2,         60,         "pick2",        1,      2, 3)
   186 OPDEF(OP_PICK3,         61,         "pick3",        1,      3, 4)
   187 
   188 // Calls a native function. During the course of calling a native, arguments
   189 // on the stack are re-pushed to match the cell-based native calling
   190 // convention expected by ISourcePawnEngine.
   191 //
   192 // Unlike the normal CALL instruction, natives take truly variadic arguments
   193 // and so we must specify the number of arguments. The format is:
   194 //
   195 // [u8 Opcode] [u32 Index] [u32 ArgCount]
   196 //
   197 OPDEF(OP_CALLNATIVE,    62,         "callnative",   9,      -1, 1)