public/jit/jit_helpers.h
author David Anderson <dvander@alliedmods.net>
Sun Jun 24 04:15:18 2007 +0000 (2007-06-24)
changeset 1009 06fd81fdedfb
parent 706 fea5148668d9
child 1230 fb651202cb8c
permissions -rw-r--r--
- added some jit stuff for cs:s dm
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourcePawn (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ================================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
    16 #define _INCLUDE_SOURCEPAWN_JIT_HELPERS_H_
    17 
    18 #include <sp_vm_types.h>
    19 #include <sp_vm_api.h>
    20 
    21 #if defined HAVE_STDINT_H && !defined WIN32
    22 #include <stdint.h>
    23 typedef int8_t jit_int8_t;
    24 typedef uint8_t jit_uint8_t;
    25 typedef int32_t jit_int32_t;
    26 typedef uint32_t jit_uint32_t;
    27 typedef int64_t jit_int64_t;
    28 typedef uint64_t jit_uint64_t;
    29 #elif defined WIN32
    30 typedef __int8 jit_int8_t;
    31 typedef unsigned __int8 jit_uint8_t;
    32 typedef __int32 jit_int32_t;
    33 typedef unsigned __int32 jit_uint32_t;
    34 typedef __int64 jit_int64_t;
    35 typedef unsigned __int64 jit_uint64_t;
    36 #endif
    37 
    38 typedef char * jitcode_t;
    39 typedef unsigned int jitoffs_t;
    40 typedef signed int jitrel_t;
    41 
    42 class JitWriter
    43 {
    44 public:
    45 	inline cell_t read_cell()
    46 	{
    47 		cell_t val = *(inptr);
    48 		inptr++;
    49 		return val;
    50 	}
    51 	inline cell_t *read_cellptr()
    52 	{
    53 		cell_t *val = *(cell_t **)(inptr);
    54 		inptr++;
    55 		return val;
    56 	}
    57 	inline void write_ubyte(jit_uint8_t c)
    58 	{
    59 		if (outbase)
    60 		{
    61 			*outptr = c;
    62 		}
    63 		outptr++;
    64 	}
    65 	inline void write_ushort(unsigned short c)
    66 	{
    67 		if (outbase)
    68 		{
    69 			*(unsigned short *)outptr = c;
    70 		}
    71 		outptr += sizeof(unsigned short);
    72 	}
    73 	inline void write_byte(jit_int8_t c)
    74 	{
    75 		if (outbase)
    76 		{
    77 			*outptr = c;
    78 		}
    79 		outptr++;
    80 	}
    81 	inline void write_int32(jit_int32_t c)
    82 	{
    83 		if (outbase)
    84 		{
    85 			*(jit_int32_t *)outptr = c;
    86 		}
    87 		outptr += sizeof(jit_int32_t);
    88 	}
    89 	inline void write_uint32(jit_uint32_t c)
    90 	{
    91 		if (outbase)
    92 		{
    93 			*(jit_uint32_t *)outptr = c;
    94 		}
    95 		outptr += sizeof(jit_uint32_t);
    96 	}
    97 	inline jitoffs_t get_outputpos()
    98 	{
    99 		return (outptr - outbase);
   100 	}
   101 	inline void set_outputpos(jitoffs_t offs)
   102 	{
   103 		outptr = outbase + offs;
   104 	}
   105 	inline jitoffs_t get_inputpos()
   106 	{
   107 		return (jitoffs_t)((char *)inptr - (char *)inbase);
   108 	}
   109 public:
   110 	cell_t *inptr;		/* input pointer */
   111 	cell_t *inbase;		/* input base */
   112 	jitcode_t outbase;	/* output pointer */
   113 	jitcode_t outptr;	/* output base */
   114 	SourcePawn::ICompilation *data;	/* compiler live info */
   115 };
   116 
   117 #endif //_INCLUDE_SOURCEPAWN_JIT_HELPERS_H_