src/Opcodes.tbl
author David Anderson <dvander@alliedmods.net>
Sun Jan 06 13:52:21 2013 -0800 (2013-01-06)
changeset 256 3c184218462d
parent 247 7721042bdb67
permissions -rw-r--r--
Initial implementation of module imports.
[email protected]
     1
/* vim: set ts=4 sw=4 tw=99 et:
[email protected]
     2
 *
[email protected]
     3
 * Copyright (C) 2012 David Anderson
[email protected]
     4
 *
[email protected]
     5
 * This file is part of JITCraft.
[email protected]
     6
 *
[email protected]
     7
 * JITCraft is free software: you can redistribute it and/or modify it under
[email protected]
     8
 * the terms of the GNU General Public License as published by the Free
[email protected]
     9
 * Software Foundation, either version 3 of the License, or (at your option)
[email protected]
    10
 * any later version.
[email protected]
    11
 * 
[email protected]
    12
 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
[email protected]
    13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
[email protected]
    14
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
[email protected]
    15
 *
[email protected]
    16
 * You should have received a copy of the GNU General Public License along with
[email protected]
    17
 * JITCraft. If not, see http://www.gnu.org/licenses/.
[email protected]
    18
 */
[email protected]
    19
// Opcode macros:
[email protected]
    20
//  NAME                TEXT            LENGTH  USES  DEFS   
[email protected]
    21
//
[email protected]
    22
// Type suffixes:
[email protected]
    23
//  I = 32-bit integer
[email protected]
    24
//  F = 32-bit IEEE-754 float
[email protected]
    25
//  O = object reference
[email protected]
    26
[email protected]
    27
// No operation.
[email protected]
    28
OPDEF(OP_NOP,           "nop",          1,      0,  0)
[email protected]
    29
[email protected]
    30
// Pushes a signed integer immediate onto the stack.
[email protected]
    31
OPDEF(OP_INT,           "int",          5,      0,  1)    
[email protected]
    32
[email protected]
    33
// Returns from the current routine, propagating the value at the top of the
[email protected]
    34
// stack to the caller.
[email protected]
    35
OPDEF(OP_RETURN,        "return",       1,      1,  0)
[email protected]
    36
[email protected]
    37
// value = pop()
[email protected]
    38
// if (value == [true, false])
[email protected]
    39
//    goto target
[email protected]
    40
OPDEF(OP_JT,            "jt",           5,      1,  0)
[email protected]
    41
OPDEF(OP_JF,            "jf",           5,      1,  0)
[email protected]
    42
[email protected]
    43
// Unconditional jump.
[email protected]
    44
OPDEF(OP_JUMP,          "jump",         5,      0,  0)
[email protected]
    45
[email protected]
    46
// Aliases for JUMP, that automatically leave LR regions.
[email protected]
    47
OPDEF(OP_BREAK,         "break",        5,      0,  0)
[email protected]
    48
OPDEF(OP_CONTINUE,      "continue",     5,      0,  0)
[email protected]
    49
[email protected]
    50
// Gets or sets the value of a local variable onto the stack. The local
[email protected]
    51
// variable is given by an immediate index.
[email protected]
    52
OPDEF(OP_GETLOCAL,      "getlocal",     5,      0,  1)
[email protected]
    53
OPDEF(OP_SETLOCAL,      "setlocal",     5,      1,  1)
[email protected]
    54
[email protected]
    55
// Stack transitions for these binary operators:
[email protected]
    56
// rhs = pop()
[email protected]
    57
// lhs = pop()
[email protected]
    58
// push(lhs OP rhs)
[email protected]
    59
OPDEF(OP_ADD,           "add",          1,      2,  1)
[email protected]
    60
OPDEF(OP_SUB,           "sub",          1,      2,  1)
[email protected]
    61
OPDEF(OP_MUL,           "mul",          1,      2,  1)
[email protected]
    62
OPDEF(OP_DIV,           "div",          1,      2,  1)
[email protected]
    63
OPDEF(OP_MOD,           "mod",          1,      2,  1)
[email protected]
    64
[email protected]
    65
OPDEF(OP_LT,            "lt",           1,      2,  1)
[email protected]
    66
OPDEF(OP_LE,            "le",           1,      2,  1)
[email protected]
    67
OPDEF(OP_GE,            "ge",           1,      2,  1)
[email protected]
    68
OPDEF(OP_GT,            "gt",           1,      2,  1)
[email protected]
    69
OPDEF(OP_EQ,            "eq",           1,      2,  1)
[email protected]
    70
OPDEF(OP_NE,            "ne",           1,      2,  1)
[email protected]
    71
[email protected]
    72
OPDEF(OP_NOT,           "not",          1,      1,  1)
[email protected]
    73
OPDEF(OP_NEG,           "neg",          1,      1,  1)
[email protected]
    74
[email protected]
    75
OPDEF(OP_POP,           "pop",          1,      1,  0)
[email protected]
    76
[email protected]
    77
// Unconditional terminator placed at the end of code. If a function returns
[email protected]
    78
// void, this acts as a RETURNVOID. Otherwise, it must be unreachable.
[email protected]
    79
OPDEF(OP_STOP,          "stop",         1,      0,  0)
[email protected]
    80
[email protected]
    81
// Call a function with N arguments. The target function must be the last item
[email protected]
    82
// on the stack.
[email protected]
    83
OPDEF(OP_CALL,          "call",         1,      -1, 1)
[email protected]
    84
[email protected]
    85
// Similar to GET/LOCAL, except for arguments.
[email protected]
    86
OPDEF(OP_GETARG,        "getarg",       5,      0,  1)
[email protected]
    87
OPDEF(OP_SETARG,        "setarg",       5,      1,  1)
[email protected]
    88
[email protected]
    89
// Allocates either:
[email protected]
    90
//   A fixed array, 
[email protected]
    91
//   A 0-length dynamic array, or
[email protected]
    92
//   A dynamic array whose size is specified on the stack.
[email protected]
    93
//
[email protected]
    94
// The HeapTenure is stored as a byte following the pc. The ArrayMap to use
[email protected]
    95
// is specified as an index into the script's object table.
[email protected]
    96
//
[email protected]
    97
// Format:
[email protected]
    98
//  [u8 op] [u8 tenure] [u32 index]
[email protected]
    99
OPDEF(OP_NEWFIXED,      "newfixed",     6,      0, 1)
[email protected]
   100
OPDEF(OP_NEWEMPTY,      "newempty",     6,      0, 1)
[email protected]
   101
OPDEF(OP_NEWSIZED,      "newsized",     6,     -1, 1)
[email protected]
   102
[email protected]
   103
// Creates a duplicate copy of an array. This is a deep clone, rather than
[email protected]
   104
// COPYARRAY, which is shallow.
[email protected]
   105
OPDEF(OP_DUPARRAY,      "duparray",     1,      1, 1)
[email protected]
   106
[email protected]
   107
// Performs an array-to-array assignment.
[email protected]
   108
//   Left = pop()
[email protected]
   109
//   Right = pop()
[email protected]
   110
//   copy(Left, Right)
[email protected]
   111
//   push(Left)
[email protected]
   112
OPDEF(OP_COPYARRAY,     "copyarray",    1,      2,  1)
[email protected]
   113
[email protected]
   114
// Reads or writes an integer element to an unsafe array.
[email protected]
   115
//  index = pop()
[email protected]
   116
//  ref = pop()
[email protected]
   117
//  ref[index]
[email protected]
   118
//
[email protected]
   119
OPDEF(OP_GETELEM,       "getelem",      1,      2,  1)
[email protected]
   120
OPDEF(OP_SETELEM,       "setelem",      1,      3,  1)
[email protected]
   121
[email protected]
   122
// Pushes a 32-bit IEEE-754 floating point immediate onto the stack.
[email protected]
   123
OPDEF(OP_FLOAT,         "float",        5,      0,  1)
[email protected]
   124
[email protected]
   125
// Converts an integer to a 32-bit IEEE-754 floating point immediate.
[email protected]
   126
OPDEF(OP_CVT_I2F,       "cvt.i2f",      1,      1,  1)
[email protected]
   127
OPDEF(OP_CVT_I2B,       "cvt.i2b",      1,      1,  1)
[email protected]
   128
[email protected]
   129
// Stack transitions for these binary operators:
[email protected]
   130
// rhs = pop()
[email protected]
   131
// lhs = pop()
[email protected]
   132
// push(lhs OP rhs)
[email protected]
   133
OPDEF(OP_ADD_F,         "add.f",        1,      2,  1)
[email protected]
   134
OPDEF(OP_SUB_F,         "sub.f",        1,      2,  1)
[email protected]
   135
OPDEF(OP_MUL_F,         "mul.f",        1,      2,  1)
[email protected]
   136
OPDEF(OP_DIV_F,         "div.f",        1,      2,  1)
[email protected]
   137
[email protected]
   138
OPDEF(OP_LT_F,          "lt.f",         1,      2,  1)
[email protected]
   139
OPDEF(OP_LE_F,          "le.f",         1,      2,  1)
[email protected]
   140
OPDEF(OP_GE_F,          "ge.f",         1,      2,  1)
[email protected]
   141
OPDEF(OP_GT_F,          "gt.f",         1,      2,  1)
[email protected]
   142
OPDEF(OP_EQ_F,          "eq.f",         1,      2,  1)
[email protected]
   143
OPDEF(OP_NE_F,          "ne.f",         1,      2,  1)
[email protected]
   144
[email protected]
   145
OPDEF(OP_NOT_F,         "not.f",        1,      1,  1)
[email protected]
   146
OPDEF(OP_NEG_F,         "neg.f",        1,      1,  1)
[email protected]
   147
[email protected]
   148
// Bitwise operators.
[email protected]
   149
OPDEF(OP_SHL,           "shl",          1,      2,  1)
[email protected]
   150
OPDEF(OP_SHR,           "shr",          1,      2,  1)
[email protected]
   151
OPDEF(OP_USHR,          "ushr",         1,      2,  1)
[email protected]
   152
OPDEF(OP_BITAND,        "bitand",       1,      2,  1)
[email protected]
   153
OPDEF(OP_BITOR,         "bitor",        1,      2,  1)
[email protected]
   154
OPDEF(OP_BITXOR,        "bitxor",       1,      2,  1)
[email protected]
   155
OPDEF(OP_BITNOT,        "bitnot",       1,      1,  1)
[email protected]
   156
[email protected]
   157
// Saves or restores the position of the LIFO heap to/from a local slot.
[email protected]
   158
OPDEF(OP_SAVELIFO,      "savelifo",     5,      0,  0)
[email protected]
   159
OPDEF(OP_UNWINDLIFO,    "unwindlifo",   5,      0,  0)
[email protected]
   160
[email protected]
   161
// Composes a variable reference to a stack slot or argument.
[email protected]
   162
OPDEF(OP_VARREF_LIFO,   "varref.lifo",  5,      0,  1)
[email protected]
   163
OPDEF(OP_ARGREF_LIFO,   "argref.lifo",  5,      0,  1)
[email protected]
   164
OPDEF(OP_SLOTREF_LIFO,  "slotref.lifo", 1,      1,  1)
[email protected]
   165
OPDEF(OP_GETREF_I,      "getref.i",     1,      1,  1)
[email protected]
   166
OPDEF(OP_SETREF_I,      "setref.i",     1,      2,  1)
[email protected]
   167
OPDEF(OP_GETREF_F,      "getref.f",     1,      1,  1)
[email protected]
   168
OPDEF(OP_SETREF_F,      "setref.f",     1,      2,  1)
[email protected]
   169
[email protected]
   170
// Pushes an object reference onto the stack.
[email protected]
   171
OPDEF(OP_OBJECT,        "object",       5,      0,  1)
[email protected]
   172
[email protected]
   173
// Duplicates the top item on the stack.
[email protected]
   174
OPDEF(OP_DUP,           "dup",          1,      1,  2)
[email protected]
   175
[email protected]
   176
// Duplicates the top two items on the stack.
[email protected]
   177
OPDEF(OP_DUP2,          "dup2",         1,      2,  4)
[email protected]
   178
[email protected]
   179
// Swaps the two items at the top of the stack.
[email protected]
   180
OPDEF(OP_SWAP,          "swap",         1,      2,  2)
[email protected]
   181
[email protected]
   182
// Roll operation is the same as Forth. It steals a value on the stack,
[email protected]
   183
// shifting all stack values down, and then places the stolen value back at
[email protected]
   184
// the top of the stack.
[email protected]
   185
//
[email protected]
   186
//  p = sp[-3]
[email protected]
   187
//  sp[-3] = sp[-2]
[email protected]
   188
//  sp[-2] = sp[-1]
[email protected]
   189
//  sp[-1] = p
[email protected]
   190
OPDEF(OP_ROLL3,         "roll3",        1,      3, 3)
[email protected]
   191
[email protected]
   192
// Pick operation is the same as Forth. It pushes a copy of a slot at a
[email protected]
   193
// specific depth.
[email protected]
   194
//
[email protected]
   195
// push(sp[-n])
[email protected]
   196
OPDEF(OP_PICK2,         "pick2",        1,      2, 3)
[email protected]
   197
OPDEF(OP_PICK3,         "pick3",        1,      3, 4)
[email protected]
   198
[email protected]
   199
// Calls a native function. During the course of calling a native, arguments
[email protected]
   200
// on the stack are re-pushed to match the cell-based native calling
[email protected]
   201
// convention expected by ISourcePawnEngine.
[email protected]
   202
//
[email protected]
   203
// Unlike the normal CALL instruction, natives take truly variadic arguments
[email protected]
   204
// and so we must specify the number of arguments.
[email protected]
   205
//
[email protected]
   206
// [u8 Opcode] [u32 ArgCount]
[email protected]
   207
//
[email protected]
   208
OPDEF(OP_CALLNATIVE,    "callnative",   5,     -1, 1)
[email protected]
   209
[email protected]
   210
// Returns from a function that does return a value.
[email protected]
   211
OPDEF(OP_RETURNVOID,    "returnvoid",   1,      0, 0)
[email protected]
   212
[email protected]
   213
// Opcodes for accessing an environment slot in the global scope. The index
[email protected]
   214
// maps into the code object's string table, and represents the name of the
[email protected]
   215
// global variable.
[email protected]
   216
OPDEF(OP_SETGLOBAL,     "setglobal",    5,      1, 1)
[email protected]
   217
OPDEF(OP_GETGLOBAL,     "getglobal",    5,      0, 1)
[email protected]
   218
[email protected]
   219
// Reinterpret casts from one 32-bit POD type to another. The new type pointer
[email protected]
   220
// is encoded into the object table, for the JITs' type flow.
[email protected]
   221
OPDEF(OP_BITCAST,       "BITCAST",      5,      1, 1)
[email protected]
   222
[email protected]
   223
// Pushes a boolean value.
[email protected]
   224
OPDEF(OP_TRUE,          "true",         1,      0, 1)
[email protected]
   225
OPDEF(OP_FALSE,         "false",        1,      0, 1)
[email protected]
   226
[email protected]
   227
// Allocate a struct. The HeapTenure is stored as a byte following pc. The
[email protected]
   228
// StructMap to use is specified as an index into the script's Map table.
[email protected]
   229
//
[email protected]
   230
// Format:
[email protected]
   231
//  [u8 op] [u8 tenure] [u32 index]
[email protected]
   232
OPDEF(OP_NEWSTRUCT,     "newstruct",    6,      0, 1)
[email protected]
   233
[email protected]
   234
// Performs a struct-to-struct assignment.
[email protected]
   235
//   Left = pop()
[email protected]
   236
//   Right = pop()
[email protected]
   237
//   copy(Left, Right)
[email protected]
   238
//   push(Left)
[email protected]
   239
OPDEF(OP_COPYSTRUCT,    "structcopy",   1,      2, 1)
[email protected]
   240
[email protected]
   241
// Sets or gets a property in a struct. The index of the field is specified as
[email protected]
   242
// a 32-bit integer. Note that these opcodes follow a new style of deriving
[email protected]
   243
// their types at runtime.
[email protected]
   244
OPDEF(OP_GETFIELD,      "getfield",     5,      1, 1)
[email protected]
   245
OPDEF(OP_SETFIELD,      "setfield",     5,      2, 1)
[email protected]
   246
[email protected]
   247
// Table-based jump.
[email protected]
   248
// [u8 op] [i32 low] [i32 high] [u32 jump] [u32 jumps...]
[email protected]
   249
OPDEF(OP_TABLESWITCH,   "tableswitch",  9,      1, 0)
[email protected]
   250
[email protected]
   251
OPDEF(OP_SIZEOF,        "sizeof",       1,      1, 1)
[email protected]
   252
[email protected]
   253
// Registers a function as a publicly exported name.
[email protected]
   254
OPDEF(OP_PUBLIC,        "public",       1,      1, 0)
[email protected]
   255
[email protected]
   256
// Enter and leave loop bodies. This is to track positions in the LIFO stack.
[email protected]
   257
// This is only used for the outermost scope inside loop bodies. BREAK and
[email protected]
   258
// CONTINUE implicitly perform a LEAVELOOP.
[email protected]
   259
//
[email protected]
   260
// If the second byte to ENTERLOOP is 0, then no LIFO region is needed.
[email protected]
   261
OPDEF(OP_ENTERLOOP,     "enterloop",    2,      0, 0)
[email protected]
   262
OPDEF(OP_LEAVELOOP,     "leaveloop",    1,      0, 0)
[email protected]
   263
[email protected]
   264
// Create a new dependent array. The type to use is encoded as an index.
[email protected]
   265
//  index = POP()
[email protected]
   266
//  base = POP()
[email protected]
   267
//  PUSH(array)
[email protected]
   268
OPDEF(OP_DEPARRAY,      "deparray",     5,      2, 1)
[email protected]
   269
[email protected]
   270
// Grabs an import object from the import table.
[email protected]
   271
OPDEF(OP_IMPORT,        "import",       5,      0, 1)