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