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