public/jit/jit_helpers.h

00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourcePawn JIT SDK
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id: jit_helpers.h 2459 2008-08-15 05:22:26Z dvander $
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
00033 #define _INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
00034 
00035 #include <sp_vm_types.h>
00036 #include <sp_vm_api.h>
00037 
00038 #if defined HAVE_STDINT_H && !defined WIN32
00039 #include <stdint.h>
00040 typedef int8_t jit_int8_t;
00041 typedef uint8_t jit_uint8_t;
00042 typedef int32_t jit_int32_t;
00043 typedef uint32_t jit_uint32_t;
00044 typedef int64_t jit_int64_t;
00045 typedef uint64_t jit_uint64_t;
00046 #elif defined WIN32
00047 typedef __int8 jit_int8_t;
00048 typedef unsigned __int8 jit_uint8_t;
00049 typedef __int32 jit_int32_t;
00050 typedef unsigned __int32 jit_uint32_t;
00051 typedef __int64 jit_int64_t;
00052 typedef unsigned __int64 jit_uint64_t;
00053 #endif
00054 
00055 typedef char * jitcode_t;
00056 typedef unsigned int jitoffs_t;
00057 typedef signed int jitrel_t;
00058 
00059 class JitWriter
00060 {
00061 public:
00062           inline cell_t read_cell()
00063           {
00064                     cell_t val = *(inptr);
00065                     inptr++;
00066                     return val;
00067           }
00068           inline cell_t peek_cell()
00069           {
00070                     return *inptr;
00071           }
00072           inline cell_t *read_cellptr()
00073           {
00074                     cell_t *val = *(cell_t **)(inptr);
00075                     inptr++;
00076                     return val;
00077           }
00078           inline void write_ubyte(jit_uint8_t c)
00079           {
00080                     if (outbase)
00081                     {
00082                               *outptr = c;
00083                     }
00084                     outptr++;
00085           }
00086           inline void write_ushort(unsigned short c)
00087           {
00088                     if (outbase)
00089                     {
00090                               *(unsigned short *)outptr = c;
00091                     }
00092                     outptr += sizeof(unsigned short);
00093           }
00094           inline void write_byte(jit_int8_t c)
00095           {
00096                     if (outbase)
00097                     {
00098                               *outptr = c;
00099                     }
00100                     outptr++;
00101           }
00102           inline void write_int32(jit_int32_t c)
00103           {
00104                     if (outbase)
00105                     {
00106                               *(jit_int32_t *)outptr = c;
00107                     }
00108                     outptr += sizeof(jit_int32_t);
00109           }
00110           inline void write_uint32(jit_uint32_t c)
00111           {
00112                     if (outbase)
00113                     {
00114                               *(jit_uint32_t *)outptr = c;
00115                     }
00116                     outptr += sizeof(jit_uint32_t);
00117           }
00118           inline jitoffs_t get_outputpos()
00119           {
00120                     return (outptr - outbase);
00121           }
00122           inline void set_outputpos(jitoffs_t offs)
00123           {
00124                     outptr = outbase + offs;
00125           }
00126           inline jitoffs_t get_inputpos()
00127           {
00128                     return (jitoffs_t)((char *)inptr - (char *)inbase);
00129           }
00130 public:
00131           cell_t *inptr;                /* input pointer */
00132           cell_t *inbase;               /* input base */
00133           jitcode_t outbase;  /* output pointer */
00134           jitcode_t outptr;   /* output base */
00135           SourcePawn::ICompilation *data;         /* compiler live info */
00136 };
00137 
00138 #endif //_INCLUDE_SOURCEPAWN_JIT_HELPERS_H_

Generated on Fri Nov 21 08:10:11 2008 for SourceMod SDK by  doxygen 1.5.1