sourcepawn/jit/opcodes.cpp
author David Anderson <danderson@mozilla.com>
Thu Aug 08 09:41:24 2013 -0700 (2013-08-08)
changeset 3977 fca2b54741ca
child 3989 b73dae36a0da
permissions -rw-r--r--
Refactor the JIT to use a newer, simpler macro assembler. (bug 5827, r=ann)
     1 /**
     2  * vim: set ts=8 sw=2 tw=99 sts=2 et:
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright _(C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License), version 3.0), as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful), but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not), see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception), AlliedModders LLC gives you permission to link the
    21  * code of this program _(as well as its derivative works) to "Half-Life 2)," the
    22  * "Source Engine)," the "SourcePawn JIT)," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally), AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions), found in LICENSE.txt _(as of this writing), version JULY-31-2007)),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 #include "opcodes.h"
    32 #include "jit_shared.h"
    33 
    34 using namespace SourcePawn;
    35 
    36 const char *OpcodeNames[] = {
    37 #define _(op, text) text,
    38   OPCODE_LIST(_)
    39 #undef _
    40   NULL
    41 };
    42 
    43 void
    44 SourcePawn::SpewOpcode(const sp_plugin_t *plugin, cell_t *start, cell_t *cip)
    45 {
    46   fprintf(stdout, "  [%05d:%04d]", cip - (cell_t *)plugin->pcode, cip - start);
    47 
    48   if (*cip >= OPCODES_TOTAL) {
    49     fprintf(stdout, " unknown-opcode\n");
    50     return;
    51   }
    52 
    53   OPCODE op = (OPCODE)*cip;
    54   fprintf(stdout, " %s ", OpcodeNames[op]);
    55 
    56   switch (op) {
    57     case OP_PUSH_C:
    58     case OP_PUSH_ADR:
    59     case OP_SHL_C_PRI:
    60     case OP_SHL_C_ALT:
    61     case OP_SHR_C_PRI:
    62     case OP_SHR_C_ALT:
    63     case OP_ADD_C:
    64     case OP_SMUL_C:
    65     case OP_EQ_C_PRI:
    66     case OP_EQ_C_ALT:
    67     case OP_TRACKER_PUSH_C:
    68     case OP_STACK:
    69     case OP_PUSH_S:
    70     case OP_HEAP:
    71     case OP_GENARRAY:
    72     case OP_GENARRAY_Z:
    73       fprintf(stdout, "%d", cip[1]);
    74       break;
    75 
    76     case OP_JUMP:
    77     case OP_JZER:
    78     case OP_JNZ:
    79     case OP_JEQ:
    80     case OP_JNEQ:
    81     case OP_JSLESS:
    82     case OP_JSGRTR:
    83     case OP_JSGEQ:
    84     case OP_JSLEQ:
    85       fprintf(stdout, "%05d:%04d",
    86         cip[1] / 4,
    87         ((cell_t *)plugin->pcode + cip[1] / 4) - start);
    88       break;
    89 
    90     case OP_SYSREQ_C:
    91     case OP_SYSREQ_N:
    92     {
    93       uint32_t index = cip[1];
    94       if (index < plugin->num_natives)
    95         fprintf(stdout, "%s", plugin->natives[index].name); 
    96       if (op == OP_SYSREQ_N)
    97         fprintf(stdout, " ; (%d args, index %d)", cip[2], index);
    98       else
    99         fprintf(stdout, " ; (index %d)", index);
   100       break;
   101     }
   102 
   103     case OP_PUSH2_C:
   104     case OP_PUSH2:
   105     case OP_PUSH2_S:
   106     case OP_PUSH2_ADR:
   107       fprintf(stdout, "%d, %d", cip[1], cip[2]);
   108       break;
   109 
   110     case OP_PUSH3_C:
   111     case OP_PUSH3:
   112     case OP_PUSH3_S:
   113     case OP_PUSH3_ADR:
   114       fprintf(stdout, "%d, %d, %d", cip[1], cip[2], cip[3]);
   115       break;
   116 
   117     case OP_PUSH4_C:
   118     case OP_PUSH4:
   119     case OP_PUSH4_S:
   120     case OP_PUSH4_ADR:
   121       fprintf(stdout, "%d, %d, %d, %d", cip[1], cip[2], cip[3], cip[4]);
   122       break;
   123 
   124     case OP_PUSH5_C:
   125     case OP_PUSH5:
   126     case OP_PUSH5_S:
   127     case OP_PUSH5_ADR:
   128       fprintf(stdout, "%d, %d, %d, %d, %d", cip[1], cip[2], cip[3], cip[4], cip[5]);
   129       break;
   130 
   131     default:
   132       break;
   133   }
   134 
   135   fprintf(stdout, "\n");
   136 }
   137