2007-01-25 23:33:15 +01:00
|
|
|
/**
|
2007-03-22 22:50:20 +01:00
|
|
|
* vim: set ts=4 :
|
2007-01-25 23:39:12 +01:00
|
|
|
* ================================================================
|
2007-08-01 03:58:16 +02:00
|
|
|
* SourceMod JIT SDK
|
|
|
|
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
|
2007-01-25 23:39:12 +01:00
|
|
|
* ================================================================
|
2007-01-25 23:33:15 +01:00
|
|
|
*
|
2007-08-01 03:58:16 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License,
|
|
|
|
* version 3.0, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to
|
|
|
|
* link the code of this program (as well as its derivative works) to
|
|
|
|
* "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
|
|
|
|
* Game MODs that run on software by the Valve Corporation. You must
|
|
|
|
* obey the GNU General Public License in all respects for all other
|
|
|
|
* code used. Additionally, AlliedModders LLC grants this exception
|
|
|
|
* to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version
|
|
|
|
* JULY-31-2007), or <http://www.sourcemod.net/license.php>.
|
2007-01-25 23:33:15 +01:00
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2006-09-20 03:59:56 +02:00
|
|
|
#ifndef _INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
|
|
|
|
#define _INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
|
2006-09-20 02:41:24 +02:00
|
|
|
|
|
|
|
#include <sp_vm_types.h>
|
2006-09-20 10:44:21 +02:00
|
|
|
#include <sp_vm_api.h>
|
2006-09-20 02:41:24 +02:00
|
|
|
|
|
|
|
#if defined HAVE_STDINT_H && !defined WIN32
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef int8_t jit_int8_t;
|
|
|
|
typedef uint8_t jit_uint8_t;
|
|
|
|
typedef int32_t jit_int32_t;
|
|
|
|
typedef uint32_t jit_uint32_t;
|
|
|
|
typedef int64_t jit_int64_t;
|
|
|
|
typedef uint64_t jit_uint64_t;
|
|
|
|
#elif defined WIN32
|
|
|
|
typedef __int8 jit_int8_t;
|
|
|
|
typedef unsigned __int8 jit_uint8_t;
|
|
|
|
typedef __int32 jit_int32_t;
|
|
|
|
typedef unsigned __int32 jit_uint32_t;
|
|
|
|
typedef __int64 jit_int64_t;
|
|
|
|
typedef unsigned __int64 jit_uint64_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef char * jitcode_t;
|
|
|
|
typedef unsigned int jitoffs_t;
|
2006-09-23 06:11:01 +02:00
|
|
|
typedef signed int jitrel_t;
|
2006-09-20 02:41:24 +02:00
|
|
|
|
2006-09-20 03:59:56 +02:00
|
|
|
class JitWriter
|
2006-09-20 02:41:24 +02:00
|
|
|
{
|
2006-09-20 03:59:56 +02:00
|
|
|
public:
|
|
|
|
inline cell_t read_cell()
|
|
|
|
{
|
|
|
|
cell_t val = *(inptr);
|
|
|
|
inptr++;
|
|
|
|
return val;
|
|
|
|
}
|
2006-09-20 04:56:20 +02:00
|
|
|
inline cell_t *read_cellptr()
|
2006-09-20 03:59:56 +02:00
|
|
|
{
|
|
|
|
cell_t *val = *(cell_t **)(inptr);
|
|
|
|
inptr++;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
inline void write_ubyte(jit_uint8_t c)
|
|
|
|
{
|
2006-10-10 03:55:08 +02:00
|
|
|
if (outbase)
|
2006-09-20 03:59:56 +02:00
|
|
|
{
|
|
|
|
*outptr = c;
|
|
|
|
}
|
|
|
|
outptr++;
|
|
|
|
}
|
2007-06-24 06:15:18 +02:00
|
|
|
inline void write_ushort(unsigned short c)
|
|
|
|
{
|
|
|
|
if (outbase)
|
|
|
|
{
|
|
|
|
*(unsigned short *)outptr = c;
|
|
|
|
}
|
|
|
|
outptr += sizeof(unsigned short);
|
|
|
|
}
|
2006-09-20 03:59:56 +02:00
|
|
|
inline void write_byte(jit_int8_t c)
|
|
|
|
{
|
2006-10-10 03:55:08 +02:00
|
|
|
if (outbase)
|
2006-09-20 03:59:56 +02:00
|
|
|
{
|
|
|
|
*outptr = c;
|
|
|
|
}
|
|
|
|
outptr++;
|
|
|
|
}
|
|
|
|
inline void write_int32(jit_int32_t c)
|
|
|
|
{
|
2006-10-10 03:55:08 +02:00
|
|
|
if (outbase)
|
2006-09-20 03:59:56 +02:00
|
|
|
{
|
2006-09-20 04:56:20 +02:00
|
|
|
*(jit_int32_t *)outptr = c;
|
2006-09-20 03:59:56 +02:00
|
|
|
}
|
|
|
|
outptr += sizeof(jit_int32_t);
|
|
|
|
}
|
2006-09-20 17:51:05 +02:00
|
|
|
inline void write_uint32(jit_uint32_t c)
|
|
|
|
{
|
2006-10-10 03:55:08 +02:00
|
|
|
if (outbase)
|
2006-09-20 17:51:05 +02:00
|
|
|
{
|
|
|
|
*(jit_uint32_t *)outptr = c;
|
|
|
|
}
|
|
|
|
outptr += sizeof(jit_uint32_t);
|
|
|
|
}
|
2006-10-10 03:55:08 +02:00
|
|
|
inline jitoffs_t get_outputpos()
|
2006-09-20 03:59:56 +02:00
|
|
|
{
|
|
|
|
return (outptr - outbase);
|
|
|
|
}
|
2006-10-10 03:55:08 +02:00
|
|
|
inline void set_outputpos(jitoffs_t offs)
|
2006-09-20 22:11:02 +02:00
|
|
|
{
|
|
|
|
outptr = outbase + offs;
|
|
|
|
}
|
2006-10-10 03:55:08 +02:00
|
|
|
inline jitoffs_t get_inputpos()
|
2006-09-23 06:11:01 +02:00
|
|
|
{
|
|
|
|
return (jitoffs_t)((char *)inptr - (char *)inbase);
|
|
|
|
}
|
2006-09-20 03:59:56 +02:00
|
|
|
public:
|
2006-09-20 02:41:24 +02:00
|
|
|
cell_t *inptr; /* input pointer */
|
2006-09-23 06:11:01 +02:00
|
|
|
cell_t *inbase; /* input base */
|
2006-09-20 02:41:24 +02:00
|
|
|
jitcode_t outbase; /* output pointer */
|
|
|
|
jitcode_t outptr; /* output base */
|
2006-09-20 10:44:21 +02:00
|
|
|
SourcePawn::ICompilation *data; /* compiler live info */
|
2006-09-20 03:59:56 +02:00
|
|
|
};
|
2006-09-20 02:41:24 +02:00
|
|
|
|
2006-09-20 03:59:56 +02:00
|
|
|
#endif //_INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
|