Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/ChangeLog  view on Meta::CPAN

	jit_cache_end_output().

2006-05-05  Aleksey Demakov  <ademakov@gmail.com>

	* jit/jit-reg-alloc.h, jit/jit-reg-alloc.c: fix spilling and many
	problems with stack registers.

2006-05-04  Radek Polak  <psonek2@seznam.cz>

	* jit/jit-dump.c (dump_object_code): Now can dump to any stream
	not just stdout and stderr.

2006-05-01  Aleksey Demakov  <ademakov@gmail.com>

	* jit/jit-rules-x86.sel, jit/jit-rules-x86.ins: fix problem with
	spilling dest register in JIT_OP_ADDRESS_OF rule.

	* jit/jit-rules-x86.ins: rewrite JIT_OP_STORE_RELATIVE_INT rule.

2006-04-23  Aleksey Demakov  <ademakov@gmail.com>

libjit/NEWS  view on Meta::CPAN

	* Add jit_function_from_vtable_pointer function (Klaus Treichel).
        * Add jit_insn_mark_breakpoint_variable function (Radek Polak).
	* Add signal handlers (Kirill Kononenko).
	* Add JIT_OPTION_POSITION_INDEPENDENT context option (not supported
	  by the backends yet) (Aleksey Demakov).
	* Add function indirectors (Klaus Treichel).
	* Allocate function redirectors and indirectors in the code cache
	  (Aleksey Demakov).
	* Use mmap to allocate executable memory where available
	  (Klaus Treichel).
	* Now can dump to any stream not just stdout and stderr (Radek Polak).
	* Use a global lock during context initialization (Aleksey Demakov).
	* Fix problems that take place after compilation is restarted on cache
	  page overflow (Aleksey Demakov).

	Register allocation/instruction selection improvements (Aleksey Demakov):

	* Completely rewrite register allocator. The new allocator works with
	  three-value intermediate instructions rather than with individual
	  values. This allows to fully analyze the effect of the instruction
	  and makes it possible to optimize commutative instructions and 

libjit/attic/jit-rules-alpha.c  view on Meta::CPAN


	alpha_freg = _jit_regclass_create("freg", JIT_REG_FLOAT32 | JIT_REG_FLOAT64 | JIT_REG_NFLOAT, 8,
		ALPHA_FS0, ALPHA_FS1, ALPHA_FS2, ALPHA_FS3, ALPHA_FS4,
		ALPHA_FS5, ALPHA_FS6, ALPHA_FS7, ALPHA_FT0, ALPHA_FT1,
		ALPHA_FT2, ALPHA_FT3, ALPHA_FT4, ALPHA_FT5
	);
}

#define TODO()          \
        do { \
                fprintf(stderr, "TODO at %s, %d\n", __FILE__, (int)__LINE__); \
        } while (0)


/*
 * Get the ELF machine and ABI type information for this platform. The 
 * machine field should be set to one of the EM_* values in 
 * jit-elf-defs.h. The abi field should be set to one of the ELFOSABI_* 
 * values in jit-elf-defs.h (ELFOSABI_SYSV will normally suffice if you 
 * are unsure). The abi_version field should be set to the ABI version, 
 * which is usually zero.

libjit/attic/jit-rules-alpha.c  view on Meta::CPAN

 * for the result to be placed in an appropriate register or memory destination.
 */
void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, jit_block_t block, jit_insn_t insn) {

	switch (insn->opcode) {
		#define JIT_INCLUDE_RULES
			#include "jit-rules-alpha.inc"
		#undef JIT_INCLUDE_RULES

		default:
			fprintf(stderr, "TODO(%x) at %s, %d\n", (int)(insn->opcode), __FILE__, (int)__LINE__);
			break;
	}
}

void _jit_gen_fix_value(jit_value_t value) {

	if (!(value->has_frame_offset) && !(value->is_constant)) {
		jit_nint size = (jit_nint)(ROUND_STACK(jit_type_get_size(value->type)));
		value->block->func->builder->frame_size += size;
		value->frame_offset = -(value->block->func->builder->frame_size);

libjit/dpas/dpas-function.c  view on Meta::CPAN

	main_list[main_list_size++] = func;
}

int dpas_run_main_functions(void)
{
	int index;
	for(index = 0; index < main_list_size; ++index)
	{
		if(!jit_function_apply(main_list[index], 0, 0))
		{
			fprintf(stderr, "Exception 0x%lx thrown past top level\n",
					(long)(jit_nint)(jit_exception_get_last()));
			return 0;
		}
	}
	return 1;
}

libjit/dpas/dpas-main.c  view on Meta::CPAN

		(include_dirs, (num_include_dirs + 1) * sizeof(char *));
	if(!include_dirs)
	{
		dpas_out_of_memory();
	}
	include_dirs[num_include_dirs++] = dir;
}

void dpas_out_of_memory(void)
{
	fputs(progname, stderr);
	fputs(": virtual memory exhausted\n", stderr);
	exit(1);
}

void dpas_import(const char *name)
{
	int posn;
	char *pathname;
	FILE *file;

	/* Bail out if we've already included this name before */

libjit/dpas/dpas-main.c  view on Meta::CPAN

		{
			dpas_load_file(pathname, file);
			fclose(file);
			jit_free(pathname);
			return;
		}
		jit_free(pathname);
	}

	/* If we get here, then we could not find the specified module */
	fprintf(stderr, "%s:%ld: could not locate the module `%s'\n",
			dpas_filename, dpas_linenum, name);
	dpas_error_reported = 1;
}

/*
 * Initialize the system.
 */
static void initialize(void)
{
	jit_init();

libjit/dpas/dpas-parser.y  view on Meta::CPAN

	int posn, outposn;
	dpas_error_reported = 1;
	if(!jit_strcmp(msg, "parse error") || !jit_strcmp(msg, "syntax error"))
	{
		/* This error is pretty much useless at telling the user
		   what is happening.  Try to print a better message
		   based on the current input token */
	simpleError:
		if(text && *text != '\0')
		{
			fprintf(stderr, "%s:%ld: parse error at or near `%s'\n",
					dpas_filename, dpas_linenum, text);
		}
		else
		{
			fprintf(stderr, "%s:%ld: parse error\n",
					dpas_filename, dpas_linenum);
		}
	}
	else if(!jit_strncmp(msg, "parse error, expecting `", 24))
	{
		/* We have to quote the token names in the "%token" declarations
		   within yacc grammars so that byacc doesn't mess up the output.
		   But the quoting causes Bison to output quote characters in
		   error messages which look awful.  This code attempts to fix
		   things up */

libjit/dpas/dpas-parser.y  view on Meta::CPAN

				else
				{
					/* Ordinary character */
					newmsg[outposn++] = newmsg[posn];
				}
				++posn;
			}
			newmsg[outposn] = '\0';
			if(text && *text != '\0')
			{
				fprintf(stderr, "%s:%ld: %s, at or near `%s'\n",
						dpas_filename, dpas_linenum, newmsg, text);
			}
			else
			{
				fprintf(stderr, "%s:%ld: %s\n",
						dpas_filename, dpas_linenum, newmsg);
			}
			jit_free(newmsg);
		}
		else
		{
			if(text && *text != '\0')
			{
				fprintf(stderr, "%s:%ld: %s at or near `%s'\n",
						dpas_filename, dpas_linenum, msg, text);
			}
			else
			{
				fprintf(stderr, "%s:%ld: %s\n",
						dpas_filename, dpas_linenum, msg);
			}
		}
	}
	else if(!jit_strncmp(msg, "parse error, unexpected ", 24))
	{
		/* The error probably has the form "parse error, unexpected ...,
		   expecting ..." - strip out the "unexpected" part */
		posn = 24;
		while(msg[posn] != '\0' &&

libjit/dpas/dpas-parser.y  view on Meta::CPAN

		jit_strcat(newmsg, msg + posn + 12);
		goto expectingError;
	}
	else
	{
		/* The parser has probably included information as to what
		   is expected in this context, so report that */
	defaultError:
		if(text && *text != '\0')
		{
			fprintf(stderr, "%s:%ld: %s at or near `%s'\n",
					dpas_filename, dpas_linenum, msg, text);
		}
		else
		{
			fprintf(stderr, "%s:%ld: %s\n",
					dpas_filename, dpas_linenum, msg);
		}
	}
}

void dpas_error(const char *format, ...)
{
	va_list va;
#ifdef HAVE_STDARG_H
	va_start(va, format);
#else
	va_start(va);
#endif
	fprintf(stderr, "%s:%ld: ", dpas_filename, dpas_linenum);
	vfprintf(stderr, format, va);
	putc('\n', stderr);
	va_end(va);
	dpas_error_reported = 1;
}

void dpas_warning(const char *format, ...)
{
	va_list va;
#ifdef HAVE_STDARG_H
	va_start(va, format);
#else
	va_start(va);
#endif
	fprintf(stderr, "%s:%ld: warning: ", dpas_filename, dpas_linenum);
	vfprintf(stderr, format, va);
	putc('\n', stderr);
	va_end(va);
}

void dpas_error_on_line(const char *filename, long linenum,
                        const char *format, ...)
{
	va_list va;
#ifdef HAVE_STDARG_H
	va_start(va, format);
#else
	va_start(va);
#endif
	fprintf(stderr, "%s:%ld: ", filename, linenum);
	vfprintf(stderr, format, va);
	putc('\n', stderr);
	va_end(va);
	dpas_error_reported = 1;
}

static void dpas_undeclared(const char *name)
{
	dpas_error("`%s' is not declared in the current scope", name);
}

static void dpas_redeclared(const char *name, dpas_scope_item_t item)

libjit/jit/jit-except.c  view on Meta::CPAN

 * @deftypefun void jit_exception_builtin (int @var{exception_type})
 * This function is called to report a builtin exception.
 * The JIT will automatically embed calls to this function wherever a
 * builtin exception needs to be reported.
 *
 * When a builtin exception occurs, the current thread's exception
 * handler is called to construct an appropriate object, which is
 * then thrown.
 *
 * If there is no exception handler set, or the handler returns NULL,
 * then @code{libjit} will print an error message to stderr and cause
 * the program to exit with a status of 1.  You normally don't want
 * this behavior and you should override it if possible.
 *
 * The following builtin exception types are currently supported:
 *
 * @table @code
 * @vindex JIT_RESULT_OK
 * @item JIT_RESULT_OK
 * The operation was performed successfully (value is 1).
 *

libjit/jit/jit-except.c  view on Meta::CPAN

	if(handler)
	{
		object = (*handler)(exception_type);
		if(object)
		{
			jit_exception_throw(object);
		}
	}

	/* We don't have an exception handler, so print a message and exit */
	fputs("A builtin JIT exception could not be handled:\n", stderr);
	exception_type = -(exception_type - 1);
	if(exception_type >= 0 && exception_type < (int)num_messages)
	{
		fputs(messages[exception_type], stderr);
	}
	else
	{
		fprintf(stderr, "Unknown builtin exception %d",
				(-exception_type) + 1);
	}
	putc('\n', stderr);
	exit(1);
}

/*@
 * @deftypefun jit_exception_func jit_exception_set_handler (jit_exception_func @var{handler})
 * Set the builtin exception handler for the current thread.
 * Returns the previous exception handler.
 * @end deftypefun
@*/
jit_exception_func jit_exception_set_handler

libjit/jit/jit-gen-arm.h  view on Meta::CPAN

/**
 * LDR (Load Register), LDRB (Load Register Byte)
 * Load the content of the memory area of size "size" at position basereg+disp+(indexreg<<shift) into the 32-bit "reg", with zero-extension.
 * "scratchreg" is a scratch register that has to be asked to the register allocator; it is 
 * used only when disp!=0; if disp==0, it can have whatever value, since it won't be used
 */
#define arm_mov_reg_memindex(inst,reg,basereg,disp,indexreg,shift,size,scratchreg)	\
do {	\
	if (basereg==ARM_NOBASEREG)	\
	{	\
		fprintf(stderr, "TODO(NOBASEREG) at %s, %d\n", __FILE__, (int)__LINE__);	\
	}	\
	else	\
	{	\
		/* Add the displacement (only if needed)*/\
		int tempreg=(basereg);	\
		if (disp!=0)	\
		{	\
			tempreg=(scratchreg);	\
			assert(tempreg!=basereg);	\
			assert(tempreg!=indexreg);	\

libjit/jit/jit-gen-arm.h  view on Meta::CPAN


/**
 * Store the content of "reg" into a memory area of size "size" at position basereg+disp+(indexreg<<shift)
 * NB: the scratch register has to be asked to the register allocator.
 *     It can't be ARM_WORK, since it's already used
 */
#define arm_mov_memindex_reg(inst,basereg,disp,indexreg,shift,reg,size,scratchreg)	\
do {	\
	if (basereg==ARM_NOBASEREG)	\
	{	\
		fprintf(stderr, "TODO(NOBASEREG) at %s, %d\n", __FILE__, (int)__LINE__);	\
	}	\
	else	\
	{	\
		arm_shift_reg_imm8((inst), ARM_SHL, (ARM_WORK), (indexreg), (shift));	\
		arm_alu_reg_reg((inst), ARM_ADD, (scratchreg), (basereg), ARM_WORK);	\
		arm_mov_membase_reg((inst),(scratchreg),(disp),(reg),(size))	\
	}	\
} while (0);

/*

libjit/jit/jit-rules-arm.c  view on Meta::CPAN

	else
	{
		offset = 0;
	}
	arm_branch_imm(*inst, ARM_CC_AL, offset);
	gen->epilog_fixup = (void *)(arm_inst_get_posn(*inst) - 1);
}

#define	TODO()		\
	do { \
		fprintf(stderr, "TODO at %s, %d\n", __FILE__, (int)__LINE__); \
} while (0)

/*
 * -------------------- End of helper functions ------------------------
 */


/*
 * Initialize the backend.
 */

libjit/jit/jit-rules-arm.c  view on Meta::CPAN

{
	flush_if_too_far(gen);
	switch(insn->opcode)
	{
		#define JIT_INCLUDE_RULES
		#include "jit-rules-arm.inc"
		#undef JIT_INCLUDE_RULES

		default:
		{
			fprintf(stderr, "TODO(%x) at %s, %d\n",
					(int)(insn->opcode), __FILE__, (int)__LINE__);
		}
		break;
	}
}

void _jit_gen_start_block(jit_gencode_t gen, jit_block_t block)
{
	void **fixup;
	void **next;

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

 */
/*
#define HAVE_X86_SSE_4_1 0
#define HAVE_X86_SSE_4 0
#define HAVE_X86_SSE_3 0
#define HAVE_X86_FISTTP 0
*/

#define	TODO() \
do { \
	fprintf(stderr, "TODO at %s, %d\n", __FILE__, (int)__LINE__); \
} while(0)

/*
 * Setup or teardown the x86 code output process.
 */
#define	jit_cache_setup_output(needed)		\
	unsigned char *inst = gen->ptr;		\
	_jit_gen_check_space(gen, (needed))

#define	jit_cache_end_output()	\

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

		}
		else
		{
			fixup = 0;
		}
		block->fixup_list = (void *)inst;
		x86_imm_emit32(inst, fixup);

		if(DEBUG_FIXUPS)
		{
			fprintf(stderr,
					"Block: %lx, Current Fixup: %lx, Next fixup: %lx\n",
					(jit_nint)block, (jit_nint)(block->fixup_list),
					(jit_nint)fixup);
		}
	}
	return inst;
}

/*
 * Jump to the current function's epilog.

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

			case JIT_TYPE_NFLOAT:
			{
				if(IS_FPU_REG(reg))
				{
					if(IS_FPU_REG(src_reg))
					{
						x86_fld_reg(inst, fp_stack_index(gen, src_reg));
					}
					else
					{
						fputs("Unsupported native float reg - reg move\n", stderr);
					}
				}
			}
			break;

			case JIT_TYPE_STRUCT:
			case JIT_TYPE_UNION:
			{
				if(IS_GENERAL_REG(reg))
				{

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

						x86_64_mov_reg_reg_size(inst, _jit_reg_info[reg].cpu_reg,
												_jit_reg_info[src_reg].cpu_reg, 8);
					}
					else if(IS_XMM_REG(src_reg))
					{
						x86_64_movq_reg_xreg(inst, _jit_reg_info[reg].cpu_reg,
											 _jit_reg_info[src_reg].cpu_reg);
					}
					else
					{
						fputs("Unsupported struct/union reg - reg move\n", stderr);
					}
				}
				else if(IS_XMM_REG(reg))
				{
					if(IS_GENERAL_REG(src_reg))
					{
						x86_64_movq_xreg_reg(inst, _jit_reg_info[reg].cpu_reg,
											 _jit_reg_info[src_reg].cpu_reg);
					}
					else if(IS_XMM_REG(src_reg))
					{
						x86_64_movaps_reg_reg(inst, _jit_reg_info[reg].cpu_reg,
											  _jit_reg_info[src_reg].cpu_reg);
					}
					else
					{
						fputs("Unsupported struct/union reg - reg move\n", stderr);
					}
				}
				else
				{
					fputs("Unsupported struct/union reg - reg move\n", stderr);
				}
			}
		}
	}
	else
	{
		/* Fix the position of the value in the stack frame */
		_jit_gen_fix_value(value);
		offset = (int)(value->frame_offset);

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

	_jit_gen_check_space(gen, 48);

	inst = gen->ptr;

	/* Perform fixups on any blocks that jump to the epilog */
	fixup = (jit_int *)(gen->epilog_fixup);
	while(fixup != 0)
	{
		if(DEBUG_FIXUPS)
		{
			fprintf(stderr, "Fixup Address: %lx, Value: %x\n",
					(jit_nint)fixup, fixup[0]);
		}
		next = (jit_int *)_JIT_CALC_NEXT_FIXUP(fixup, fixup[0]);
		fixup[0] = (jit_int)(((jit_nint)inst) - ((jit_nint)fixup) - 4);
		fixup = next;
	}
	gen->epilog_fixup = 0;

	/* Perform fixups on any alloca calls */
	fixup = (jit_int *)(gen->alloca_fixup);
	while (fixup != 0)
	{
		next = (jit_int *)_JIT_CALC_NEXT_FIXUP(fixup, fixup[0]);
		fixup[0] = func->builder->param_area_size;
		if(DEBUG_FIXUPS)
		{
			fprintf(stderr, "Fixup Param Area Size: %lx, Value: %x\n",
					(jit_nint)fixup, fixup[0]);
		}
		fixup = next;
	}
	gen->alloca_fixup = 0;

	/* Restore the used callee saved registers */
	if(gen->stack_changed)
	{
		int frame_size = func->builder->frame_size;

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

	void **absolute_fixup;
	void **absolute_next;

	/* Set the address of this block */
	block->address = (void *)(gen->ptr);

	/* If this block has pending fixups, then apply them now */
	fixup = (jit_int *)(block->fixup_list);
	if(DEBUG_FIXUPS && fixup)
	{
		fprintf(stderr, "Block: %lx\n", (jit_nint)block);
	}
	while(fixup != 0)
	{
		if(DEBUG_FIXUPS)
		{
			fprintf(stderr, "Fixup Address: %lx, Value: %x\n",
					(jit_nint)fixup, fixup[0]);
		}
		next = (jit_int *)_JIT_CALC_NEXT_FIXUP(fixup, fixup[0]);
		fixup[0] = (jit_int)
			(((jit_nint)(block->address)) - ((jit_nint)fixup) - 4);
		fixup = next;
	}
	block->fixup_list = 0;

	/* Absolute fixups contain complete pointers */

libjit/jit/jit-rules-x86-64.c  view on Meta::CPAN

			  jit_block_t block, jit_insn_t insn)
{
	switch(insn->opcode)
	{
	#define JIT_INCLUDE_RULES
	#include "jit-rules-x86-64.inc"
	#undef JIT_INCLUDE_RULES

	default:
		{
			fprintf(stderr, "TODO(%x) at %s, %d\n",
				(int)(insn->opcode), __FILE__, (int)__LINE__);
		}
		break;
	}
}

/*
 * Fixup the passing area after all parameters have been allocated either
 * in registers or on the stack.
 * This is typically used for adding pad words for keeping the stack aligned.

libjit/jit/jit-rules-x86.c  view on Meta::CPAN

			x86_push_reg(inst, temp_reg);
		}
		x86_call_code(inst, jit_memcpy);
		x86_alu_reg_imm(inst, X86_ADD, X86_ESP, 3 * sizeof(void *));
	}
	return inst;
}

#define	TODO()		\
	do { \
		fprintf(stderr, "TODO at %s, %d\n", __FILE__, (int)__LINE__); \
	} while (0)

void _jit_gen_insn(jit_gencode_t gen, jit_function_t func,
				   jit_block_t block, jit_insn_t insn)
{
	switch(insn->opcode)
	{
	#define JIT_INCLUDE_RULES
	#include "jit-rules-x86.inc"
	#undef JIT_INCLUDE_RULES

	default:
		{
			fprintf(stderr, "TODO(%x) at %s, %d\n",
				(int)(insn->opcode), __FILE__, (int)__LINE__);
		}
		break;
	}
}

void _jit_gen_start_block(jit_gencode_t gen, jit_block_t block)
{
	void **fixup;
	void **next;

libjit/jit/jit-varint.c  view on Meta::CPAN

		_jit_varint_encode_uint(&encoder, n + 1);
		_jit_varint_encode_end(&encoder);

		jit_varint_data_t data = _jit_varint_get_data(&encoder);

		jit_varint_decoder_t decoder;
		_jit_varint_init_decoder(&decoder, data);
		v = _jit_varint_decode_uint(&decoder);
		if(v != n)
		{
			fprintf(stderr, "FAILED\n");
		}
		v = _jit_varint_decode_uint(&decoder);
		if(v != n - 1)
		{
			fprintf(stderr, "FAILED\n");
		}
		v = _jit_varint_decode_uint(&decoder);
		if(v != n + 1)
		{
			fprintf(stderr, "FAILED\n");
		}
		_jit_varint_decode_uint(&decoder);
		if(!_jit_varint_decode_end(&decoder))
		{
			fprintf(stderr, "FAILED\n");
		}

		_jit_varint_free_data(data);
	}

}

#endif

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN


@deftypefun {void *} jit_dynlib_get_symbol (jit_dynlib_handle_t @var{handle}, const char *@var{symbol})
Retrieve the symbol @var{symbol} from the specified dynamic library.
Returns NULL if the symbol could not be found.  This will try both
non-prefixed and underscore-prefixed forms of @var{symbol} on platforms
where it makes sense to do so, so there is no need for the caller
to perform prefixing.
@end deftypefun

@deftypefun void jit_dynlib_set_debug (int @var{flag})
Enable or disable additional debug messages to stderr.  Debugging is
disabled by default.  Normally the dynamic library routines will silently
report errors via NULL return values, leaving reporting up to the caller.
However, it can be useful to turn on additional diagnostics when tracking
down problems with dynamic loading.
@end deftypefun

@deftypefun {const char *} jit_dynlib_get_suffix (void)
Get the preferred dynamic library suffix for this platform.
Usually something like @code{so}, @code{dll}, or @code{dylib}.
@end deftypefun

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN

				msg = " (NSObjectFileImageArch)"; break;
			case NSObjectFileImageFormat:
				msg = " (NSObjectFileImageFormat)"; break;
			case NSObjectFileImageAccess:
				msg = " (NSObjectFileImageAccess)"; break;
			default:
				msg = ""; break;
		}
		if(dynlib_debug)
		{
			fprintf(stderr, "%s: could not load dynamic library%s\n",
					name, msg);
		}
		return 0;
	}

	/* Link the module dependencies */
	module = NSLinkModule(file, name,
						  NSLINKMODULE_OPTION_BINDNOW |
						  NSLINKMODULE_OPTION_PRIVATE |
						  NSLINKMODULE_OPTION_RETURN_ON_ERROR);

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN

		value = GetSymbol(handle, newName);
		if(value)
		{
			jit_free(newName);
			return value;
		}
		jit_free(newName);
	}
	if(dynlib_debug)
	{
		fprintf(stderr, "%s: could not find the specified symbol\n", symbol);
	}
	return 0;
}

const char *jit_dynlib_get_suffix(void)
{
	return "dylib";
}

#elif defined(JIT_WIN32_PLATFORM)	/* Native Win32 or Cygwin */

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN

	}

#endif

	/* Attempt to load the library */
	libHandle = (void *)LoadLibrary((newName ? newName : name));
	if(libHandle == 0)
	{
		if(dynlib_debug)
		{
			fprintf(stderr, "%s: could not load dynamic library\n",
					(newName ? newName : name));
		}
		if(newName)
		{
			jit_free(newName);
		}
		return 0;
	}
	if(newName)
	{

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN

}

void *jit_dynlib_get_symbol(jit_dynlib_handle_t handle, const char *symbol)
{
	void *procAddr;
	procAddr = (void *)GetProcAddress((HINSTANCE)handle, symbol);
	if(procAddr == 0)
	{
		if(dynlib_debug)
		{
			fprintf(stderr, "%s: could not resolve symbol", symbol);
		}
		return 0;
	}
	return procAddr;
}

const char *jit_dynlib_get_suffix(void)
{
	return "dll";
}

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN


				/* Reload the original error state */
				handle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
			}
		}

		/* Report the error, or just clear the error state */
		if(dynlib_debug)
		{
			error = dlerror();
			fprintf(stderr, "%s: %s\n", name,
					(error ? error : "could not load dynamic library"));
		}
		else
		{
			dlerror();
		}
		return 0;
	}
	else
	{

libjit/jitdynamic/jit-dynlib.c  view on Meta::CPAN

		error = dlerror();
		if(error == 0)
		{
			jit_free(newName);
			return value;
		}
		jit_free(newName);
	}
	if(dynlib_debug)
	{
		fprintf(stderr, "%s: %s\n", symbol, error);
	}
	return 0;
}

const char *jit_dynlib_get_suffix(void)
{
	return "so";
}

#else	/* No dynamic library support */

jit_dynlib_handle_t jit_dynlib_open(const char *name)
{
	if(dynlib_debug)
	{
		fprintf(stderr, "%s: dynamic libraries are not available\n", name);
	}
	return 0;
}

void jit_dynlib_close(jit_dynlib_handle_t handle)
{
}

void *jit_dynlib_get_symbol(jit_dynlib_handle_t handle, const char *symbol)
{

libjit/jitruby/ext/extconf.rb  view on Meta::CPAN

require 'rbconfig'

if Config::CONFIG['host_os'] =~ /cygwin|win32|windows/ then
  need_windows_h = [ 'windows.h' ]
  $defs << ' -DNEED_WINDOWS_H'
else
  need_windows_h = [ ]
end

if not have_library('jit', 'jit_init', need_windows_h + ["jit/jit.h"]) then
  $stderr.puts "libjit not found"
  exit 1
end

if not have_macro("SIZEOF_VALUE", "ruby.h") then
  check_sizeof("VALUE", "ruby.h")
end

if not have_macro("SIZEOF_ID", "ruby.h") then
  check_sizeof("ID", "ruby.h")
end

libjit/jitruby/ext/rubypp.rb  view on Meta::CPAN

          end
          result = evaluate(str, @linenum)
          puts result if not result.nil?
        else
          puts line
        end
      end
      success = true
    ensure
      if not success then
        $stderr.puts "Error on line #{@linenum}:"
      end
    end
  end

  def evaluate(str, linenum)
    result = eval(str, TOPLEVEL_BINDING, @filename, linenum)
    success = true
    return result
  end

libjit/jitruby/setup.rb  view on Meta::CPAN

  end

end   # class ConfigTable


# This module requires: #verbose?, #no_harm?
module FileOperations

  def mkdir_p(dirname, prefix = nil)
    dirname = prefix + File.expand_path(dirname) if prefix
    $stderr.puts "mkdir -p #{dirname}" if verbose?
    return if no_harm?

    # Does not check '/', it's too abnormal.
    dirs = File.expand_path(dirname).split(%r<(?=/)>)
    if /\A[a-z]:\z/i =~ dirs[0]
      disk = dirs.shift
      dirs[0] = disk + dirs[0]
    end
    dirs.each_index do |idx|
      path = dirs[0..idx].join('')
      Dir.mkdir path unless File.dir?(path)
    end
  end

  def rm_f(path)
    $stderr.puts "rm -f #{path}" if verbose?
    return if no_harm?
    force_remove_file path
  end

  def rm_rf(path)
    $stderr.puts "rm -rf #{path}" if verbose?
    return if no_harm?
    remove_tree path
  end

  def remove_tree(path)
    if File.symlink?(path)
      remove_file path
    elsif File.dir?(path)
      remove_tree0 path
    else

libjit/jitruby/setup.rb  view on Meta::CPAN

    rescue
    end
  end

  def remove_file(path)
    File.chmod 0777, path
    File.unlink path
  end

  def install(from, dest, mode, prefix = nil)
    $stderr.puts "install #{from} #{dest}" if verbose?
    return if no_harm?

    realdest = prefix ? prefix + File.expand_path(dest) : dest
    realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
    str = File.binread(from)
    if diff?(str, realdest)
      verbose_off {
        rm_f realdest if File.exist?(realdest)
      }
      File.open(realdest, 'wb') {|f|

libjit/jitruby/setup.rb  view on Meta::CPAN

      }
    end
  end

  def diff?(new_content, path)
    return true unless File.exist?(path)
    new_content != File.binread(path)
  end

  def command(*args)
    $stderr.puts args.join(' ') if verbose?
    system(*args) or raise RuntimeError,
        "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
  end

  def ruby(*args)
    command config('rubyprog'), *args
  end
  
  def make(task = nil)
    command(*[config('makeprog'), task].compact)

libjit/jitruby/setup.rb  view on Meta::CPAN

    run_hook 'post-distclean'
  end

  #
  # lib
  #

  def each_selected_installers
    Dir.mkdir 'packages' unless File.dir?('packages')
    @selected.each do |pack|
      $stderr.puts "Processing the package `#{pack}' ..." if verbose?
      Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}")
      Dir.chdir "packages/#{pack}"
      yield @installers[pack]
      Dir.chdir '../..'
    end
  end

  def run_hook(id)
    @root_installer.run_hook id
  end

libjit/jitruby/setup.rb  view on Meta::CPAN


  alias setup_dir_data noop
  alias setup_dir_conf noop
  alias setup_dir_man noop

  def update_shebang_line(path)
    return if no_harm?
    return if config('shebang') == 'never'
    old = Shebang.load(path)
    if old
      $stderr.puts "warning: #{path}: Shebang line includes too many args.  It is not portable and your program may not work." if old.args.size > 1
      new = new_shebang(old)
      return if new.to_s == old.to_s
    else
      return unless config('shebang') == 'all'
      new = Shebang.new(config('rubypath'))
    end
    $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
    open_atomic_writer(path) {|output|
      File.open(path, 'rb') {|f|
        f.gets if old   # discard
        output.puts new.to_s
        output.print f.read
      }
    }
  end

  def new_shebang(old)

libjit/jitruby/setup.rb  view on Meta::CPAN

  end

  #
  # TASK test
  #

  TESTDIR = 'test'

  def exec_test
    unless File.directory?('test')
      $stderr.puts 'no test in this package' if verbose?
      return
    end
    $stderr.puts 'Running tests...' if verbose?
    begin
      require 'test/unit'
    rescue LoadError
      setup_rb_error 'test/unit cannot loaded.  You need Ruby 1.8 or later to invoke this task.'
    end
    runner = Test::Unit::AutoRunner.new(true)
    runner.to_run << TESTDIR
    runner.run
  end

libjit/jitruby/setup.rb  view on Meta::CPAN

  alias distclean_dir_man noop

  #
  # Traversing
  #

  def exec_task_traverse(task)
    run_hook "pre-#{task}"
    FILETYPES.each do |type|
      if type == 'ext' and config('without-ext') == 'yes'
        $stderr.puts 'skipping ext/* by user option' if verbose?
        next
      end
      traverse task, type, "#{task}_dir_#{type}"
    end
    run_hook "post-#{task}"
  end

  def traverse(task, rel, mid)
    dive_into(rel) {
      run_hook "pre-#{task}"

libjit/jitruby/setup.rb  view on Meta::CPAN

    }
  end

  def dive_into(rel)
    return unless File.dir?("#{@srcdir}/#{rel}")

    dir = File.basename(rel)
    Dir.mkdir dir unless File.dir?(dir)
    prevdir = Dir.pwd
    Dir.chdir dir
    $stderr.puts '---> ' + rel if verbose?
    @currdir = rel
    yield
    Dir.chdir prevdir
    $stderr.puts '<--- ' + rel if verbose?
    @currdir = File.dirname(rel)
  end

  def run_hook(id)
    path = [ "#{curr_srcdir()}/#{id}",
             "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) }
    return unless path
    $stderr.puts "invoking hook script #{path}" if verbose?
    begin
      instance_eval File.read(path), path, 1
    rescue
      raise if $DEBUG
      setup_rb_error "hook #{path} failed:\n" + $!.message
    end
  end

end   # class Installer

libjit/jitruby/setup.rb  view on Meta::CPAN

end

# $DEBUG = true

if $0 == __FILE__
    ToplevelInstaller.invoke
    # begin
    #   ToplevelInstaller.invoke
    # rescue SetupError
    #   raise if $DEBUG
    #   $stderr.puts $!.message
    #   $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
    #   exit 1
    # end
end

libjit/samples/hellovm.c  view on Meta::CPAN

		perror(argv[1]);
		return 99;
	}

	/* read filetype identification string and length field */
	buf=readbytes(fd, 12);

	/* check filetype identification string */
	if(jit_strcmp("HelloVM", buf)!=0)
	{
		fprintf(stderr, "%s is not in HelloVM format.\n", argv[1]);
		return 99;
	}

	/* check length field and read bytecode data */
	len=*((int*) (buf+8));
	if(len<0)
	{
		fprintf(stderr, "%s: Invalid length field.\n", argv[1]);
		return 99;
	}
	free(buf);
	buf=readbytes(fd, len);
	close(fd);

	/* Now the fun begins :) */
	jit_init();
	context = jit_context_create();
	jit_context_build_start(context);

libjit/samples/hellovm.c  view on Meta::CPAN

					(hellovm_main, "hellovm_exit",
					 (void *)hellovm_exit, 
					 hellovm_signature_exit,
					 NULL, 0,
					 JIT_CALL_NOTHROW|JIT_CALL_NORETURN);
				willexit=1;
			}
			break;
			default:
			{
				fprintf(stderr, "Error: Illegal opcode\n");
				return 99;
			}
		}
	}
	if(willexit)
	{
		if (!jit_function_compile(hellovm_main))
		{
			fprintf(stderr, "JIT compilation error\n");
			return 99;
		}
		jit_context_build_end(context);
		free(buf);
		if (!jit_function_apply(hellovm_main, NULL, &retval))
		{
			fprintf(stderr, "Exception during execution\n");
			return 99;
		}
		/* not reached with the current instruction set */
		return retval;
	}
	else
	{
		jit_function_abandon(hellovm_main);
		fprintf(stderr, "Error: program without exit opcode\n");
		return 99;
	}
}

static void hellovm_output(char *value)
{
	fputs(value, stdout);
}

static void hellovm_nulput(char *value)

libjit/samples/hellovm.c  view on Meta::CPAN

	putchar(0);
}

static void hellovm_exit()
{
	exit(0);
}

static void out_of_memory()
{
	fprintf(stderr, "Out of memory.\n");
	exit(99);	
}

/* This function will not return unless the specified number of bytes
 * has been read successfully */
char* readbytes(int file, int bytestoread)
{
	char *buffer;
	int pos=0;
	int bytesread;

libjit/samples/hellovm.c  view on Meta::CPAN

	while (pos<bytestoread)
	{
		bytesread=read(file, buffer+pos, bytestoread-pos);
		if(bytesread==-1)
		{
			perror("read error in readbytes()");
			exit(99);
		}
		if(bytesread==0)
		{
			fprintf(stderr, "unexpected eof in readbytes()\n");
			exit(99);
		}
		pos+=bytesread;
	}
	return buffer;
}

libjit/tools/gen-ops-parser.y  view on Meta::CPAN

 * Current opcode declaration header
 */
static struct genops_opcode_list *opcode_header = 0;

/*
 * Report error message.
 */
static void
genops_error_message(char *filename, long linenum, char *msg)
{
	fprintf(stderr, "%s(%ld): %s\n", filename, linenum, msg);
}

/*
 * Report error messages from the parser.
 */
static void
yyerror(char *msg)
{
	genops_error_message(genops_filename, genops_linenum, msg);
}

libjit/tools/gen-ops-parser.y  view on Meta::CPAN

			!strcmp(argv[current], "--table"))
		{
			genops_task = TASK_GEN_TABLE;
		}
		else if(!strcmp(argv[current], "--help"))
		{
			return 1;
		}
		else
		{
			fprintf(stderr, "Invalid commandline option %s\n",
				argv[current]);
			return 1;
		}
		++current;
	}
	if(genops_task == TASK_GEN_NONE)
	{
		return 1;
	}
	if(argc > 1)

libjit/tools/gen-ops-parser.y  view on Meta::CPAN

"  -H, --header\tgenerate a header file\n" \
"  -T, --table\tgenerate a file with the opcode table\n" \
"  --help\tdisplay this information\n" \
"\nExactly one of header or table option must be supplied.\n" \
"If file is - standard input is used.\n"

int main(int argc, char *argv[])
{
	if(genops_parseargs(argc, argv))
	{
		fprintf(stderr, USAGE, argv[0]);
		return 1;
	}
	genops_filename = argv[argc - 1];
	genops_linenum = 1;
	yyrestart(genops_file);
	if(yyparse())
	{
		if(genops_file_needs_close)
		{
			fclose(genops_file);

libjit/tools/gen-ops-scanner.l  view on Meta::CPAN

	char *buf = 0;
	int buflen = 0;
	int bufmax = 0;
	int ch;

	ch = input();
	for(;;)
	{
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in code block\n");
			exit(1);
		}
		if(ch == '\n')
		{
			ADD_CH(ch);
			++genops_linenum;
		}
		else if(ch == '%')
		{
			ch = input();

libjit/tools/gen-ops-scanner.l  view on Meta::CPAN

	char *buf = 0;
	int buflen = 0;
	int bufmax = 0;
	int ch;

	ch = input();
	for(;;)
	{
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in code block\n");
			exit(1);
		}
		if(ch == '\n')
		{
			ADD_CH(ch);
			++genops_linenum;
		}
		else if(ch == '%')
		{
			ch = input();

libjit/tools/gen-ops-scanner.l  view on Meta::CPAN

	char *buf = 0;
	int buflen = 0;
	int bufmax = 0;
	int escape = 0;
	int ch;
	for(;;)
	{
		ch = input();
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in string literal\n");
			exit(1);
		}
		if(ch == '\n')
		{
			fprintf(stderr, "Unexpected newline in string literal\n");
			exit(1);
		}
		if(escape)
		{
			escape = 0;
			if(ch == 'n')
			{
				ch = '\n';
			}
			else if(ch == 't')

libjit/tools/gen-rules-parser.y  view on Meta::CPAN

 */
extern char *gensel_filename;
extern long gensel_linenum;

/*
 * Report error message.
 */
static void
gensel_error_message(char *filename, long linenum, char *msg)
{
	fprintf(stderr, "%s(%ld): %s\n", filename, linenum, msg);
}

/*
 * Report error message and exit.
 */
static void
gensel_error(char *filename, long linenum, char *msg)
{
	gensel_error_message(filename, linenum, msg);
	exit(1);

libjit/tools/gen-rules-parser.y  view on Meta::CPAN

" *\n" \
" * You should have received a copy of the GNU Lesser General Public\n" \
" * License along with the libjit library.  If not, see\n" \
" * <http://www.gnu.org/licenses/>.\n"
 
int main(int argc, char *argv[])
{
	FILE *file;
	if(argc != 2)
	{
		fprintf(stderr, "Usage: %s input.sel >output.slc\n", argv[0]);
		return 1;
	}
	file = fopen(argv[1], "r");
	if(!file)
	{
		perror(argv[1]);
		return 1;
	}
	printf("/%c Automatically generated from %s - DO NOT EDIT %c/\n",
		   '*', argv[1], '*');

libjit/tools/gen-rules-scanner.l  view on Meta::CPAN

	int buflen = 0;
	int bufmax = 0;
	int ch;
	int level = 1;
	ADD_CH('{');
	for(;;)
	{
		ch = input();
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in code block\n");
			exit(1);
		}
		ADD_CH(ch);
		if(ch == '{')
		{
			++level;
		}
		else if(ch == '\n')
		{
			++gensel_linenum;

libjit/tools/gen-rules-scanner.l  view on Meta::CPAN

	char *buf = 0;
	int buflen = 0;
	int bufmax = 0;
	int escape = 0;
	int ch;
	for(;;)
	{
		ch = input();
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in string literal\n");
			exit(1);
		}
		if(ch == '\n')
		{
			fprintf(stderr, "Unexpected newline in string literal\n");
			exit(1);
		}
		if(escape)
		{
			escape = 0;
			if(ch == 'n')
			{
				ch = '\n';
			}
			else if(ch == 't')



( run in 0.931 second using v1.01-cache-2.11-cpan-49f99fa48dc )