/*
 * NOTE: The result type is already set in const_result.
 */
static int
apply_conv(jit_constant_t *const_result, jit_value_t value, int overflow_check)
{
	jit_type_t srctype;
	jit_constant_t const_value;

	srctype = jit_type_promote_int(jit_type_normalize(value->type));
	if(!srctype)
	{
		return 0;
	}
	const_value.type = srctype;
	switch(srctype->kind)
	{
		case JIT_TYPE_INT:
		{
			const_value.un.int_value = value->address;
		}
		break;

		case JIT_TYPE_UINT:
		{
			const_value.un.uint_value = value->address;
		}
		break;

		case JIT_TYPE_LONG:
		{
#ifdef JIT_NATIVE_INT64
			const_value.un.long_value = value->address;
#else
			const_value.un.long_value = *(jit_long *)(value->address);
#endif
		}
		break;

		case JIT_TYPE_ULONG:
		{
#ifdef JIT_NATIVE_INT64
			const_value.un.ulong_value = value->address;
#else
			const_value.un.ulong_value = *(jit_ulong *)(value->address);
#endif
		}
		break;

		case JIT_TYPE_FLOAT32:
		{
			const_value.un.float32_value = *(jit_float32 *)(value->address);
		}
		break;

		case JIT_TYPE_FLOAT64:
		{
			const_value.un.float64_value = *(jit_float64 *)(value->address);
		}
		break;

		case JIT_TYPE_NFLOAT:
		{
			const_value.un.nfloat_value = *(jit_nfloat *)(value->address);
		}
		break;

		default:
		{
			return 0;
		}
	}
	return jit_constant_convert(const_result, &const_value,
				    const_result->type, overflow_check);
}
Exemple #2
0
/*@
 * @deftypefun void jit_dump_value (FILE *@var{stream}, jit_function_t @var{func}, jit_value_t @var{value}, const char *@var{prefix})
 * Dump the name of a value to a stdio stream.  If @var{prefix} is not
 * NULL, then it indicates a type prefix to add to the value name.
 * If @var{prefix} is NULL, then this function intuits the type prefix.
 * @end deftypefun
@*/
void jit_dump_value(FILE *stream, jit_function_t func, jit_value_t value, const char *prefix)
{
	jit_pool_block_t block;
	unsigned int block_size;
	unsigned int posn;

	/* Bail out if we have insufficient informaition for the dump */
	if(!stream || !func || !(func->builder) || !value)
	{
		return;
	}

	/* Handle constants and non-local variables */
	if(value->is_constant)
	{
		jit_constant_t const_value;
		char buf[64];
		char *name;
		const_value = jit_value_get_constant(value);
		switch((jit_type_promote_int
					(jit_type_normalize(const_value.type)))->kind)
		{
			case JIT_TYPE_INT:
			{
				if(const_value.un.int_value < 0)
				{
					name = format_integer
						(buf, 1, (jit_ulong)(jit_uint)
							(-(const_value.un.int_value)));
				}
				else
				{
					name = format_integer
						(buf, 0, (jit_ulong)(jit_uint)
							(const_value.un.int_value));
				}
			}
			break;

			case JIT_TYPE_UINT:
			{
				name = format_integer
					(buf, 0, (jit_ulong)(const_value.un.uint_value));
			}
			break;

			case JIT_TYPE_LONG:
			{
				if(const_value.un.long_value < 0)
				{
					name = format_integer
						(buf, 1, (jit_ulong)(-(const_value.un.long_value)));
				}
				else
				{
					name = format_integer
						(buf, 0, (jit_ulong)(const_value.un.long_value));
				}
			}
			break;

			case JIT_TYPE_ULONG:
			{
				name = format_integer(buf, 0, const_value.un.ulong_value);
			}
			break;

			case JIT_TYPE_FLOAT32:
			{
				jit_snprintf(buf, sizeof(buf), "%f",
							 (double)(const_value.un.float32_value));
				name = buf;
			}
			break;

			case JIT_TYPE_FLOAT64:
			{
				jit_snprintf(buf, sizeof(buf), "%f",
							 (double)(const_value.un.float64_value));
				name = buf;
			}
			break;

			case JIT_TYPE_NFLOAT:
			{
				jit_snprintf(buf, sizeof(buf), "%f",
							 (double)(const_value.un.nfloat_value));
				name = buf;
			}
			break;

			default:
			{
				name = "<unknown-constant>";
			}
			break;
		}
		fputs(name, stream);
		return;
	}
	else if(value->is_local && value->block->func != func)
	{
		/* Accessing a local variable in an outer function frame */
		int scope = 0;
		while(func && func->builder && func != value->block->func)
		{
			++scope;
			func = func->nested_parent;
		}
		fprintf(stream, "{%d}", scope);
		if(!func || !(func->builder))
		{
			return;
		}
	}

	/* Intuit the prefix if one was not supplied */
	if(!prefix)
	{
		switch(jit_type_normalize(jit_value_get_type(value))->kind)
		{
			case JIT_TYPE_VOID:			prefix = "v"; break;
			case JIT_TYPE_SBYTE:		prefix = "i"; break;
			case JIT_TYPE_UBYTE:		prefix = "i"; break;
			case JIT_TYPE_SHORT:		prefix = "i"; break;
			case JIT_TYPE_USHORT:		prefix = "i"; break;
			case JIT_TYPE_INT:			prefix = "i"; break;
			case JIT_TYPE_UINT:			prefix = "i"; break;
			case JIT_TYPE_LONG:			prefix = "l"; break;
			case JIT_TYPE_ULONG:		prefix = "l"; break;
			case JIT_TYPE_FLOAT32:		prefix = "f"; break;
			case JIT_TYPE_FLOAT64:		prefix = "d"; break;
			case JIT_TYPE_NFLOAT:		prefix = "D"; break;
			case JIT_TYPE_STRUCT:		prefix = "s"; break;
			case JIT_TYPE_UNION:		prefix = "u"; break;
			default:					prefix = "?"; break;
		}
	}

	/* Get the position of the value within the function's value pool */
	block = func->builder->value_pool.blocks;
	block_size = func->builder->value_pool.elem_size *
				 func->builder->value_pool.elems_per_block;
	posn = 1;
	while(block != 0)
	{
		if(((char *)value) >= block->data &&
		   ((char *)value) < (block->data + block_size))
		{
			posn += (((char *)value) - block->data) /
					func->builder->value_pool.elem_size;
			break;
		}
		posn += func->builder->value_pool.elems_per_block;
		block = block->next;
	}

	/* Dump the prefix and the position, as the value's final name */
	fprintf(stream, "%s%u", prefix, posn);
}
Exemple #3
0
/*@
 * @deftypefun int jit_constant_convert (jit_constant_t *@var{result}, const jit_constant_t *@var{value}, jit_type_t @var{type}, int @var{overflow_check})
 * Convert a the constant @var{value} into a new @var{type}, and
 * return its value in @var{result}.  Returns zero if the conversion
 * is not possible, usually due to overflow.
 * @end deftypefun
@*/
int
jit_constant_convert(jit_constant_t *result, const jit_constant_t *value, jit_type_t type,
		     int overflow_check)
{
	jit_type_t srctype;
	jit_type_t desttype;

	/* Normalize the source and destination types.  The source type
	   is also promoted, to reduce the number of cases in the
	   inner switch statements below */
	srctype = jit_type_promote_int(jit_type_normalize(value->type));
	if(!srctype)
	{
		return 0;
	}
	desttype = jit_type_normalize(type);
	if(!desttype)
	{
		return 0;
	}

	/* Determine what kind of conversion to perform */
	result->type = type;
	switch(desttype->kind)
	{
	case JIT_TYPE_SBYTE:
		/* Convert to a signed 8-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			if(overflow_check)
			{
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 value->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_sbyte(value->un.int_value);
			}
			break;

		case JIT_TYPE_UINT:
			if(overflow_check)
			{
				if(!jit_uint_to_int_ovf(&result->un.int_value,
							value->un.uint_value))
				{
					return 0;
				}
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_sbyte(value->un.int_value);
			}
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_int_ovf(&result->un.int_value,
							value->un.long_value))
				{
					return 0;
				}
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_sbyte(jit_long_to_int(value->un.long_value));
			}
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_int_ovf(&result->un.int_value,
							 value->un.ulong_value))
				{
					return 0;
				}
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_sbyte(jit_ulong_to_int(value->un.ulong_value));
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_int_ovf(&result->un.int_value,
							   value->un.float32_value))
				{
					return 0;
				}
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_sbyte(jit_float32_to_int(value->un.float32_value));
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_int_ovf(&result->un.int_value,
							   value->un.float64_value))
				{
					return 0;
				}
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_sbyte(jit_float64_to_int(value->un.float64_value));
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_int_ovf(&result->un.int_value,
							  value->un.nfloat_value))
				{
					return 0;
				}
				if(!jit_int_to_sbyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_sbyte(jit_nfloat_to_int(value->un.nfloat_value));
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_UBYTE:
		/* Convert to an unsigned 8-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			if(overflow_check)
			{
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 value->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_ubyte(value->un.int_value);
			}
			break;

		case JIT_TYPE_UINT:
			if(overflow_check)
			{
				if(!jit_uint_to_int_ovf(&result->un.int_value,
							value->un.uint_value))
				{
					return 0;
				}
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_ubyte(value->un.int_value);
			}
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_int_ovf(&result->un.int_value,
							value->un.long_value))
				{
					return 0;
				}
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ubyte(jit_long_to_int(value->un.long_value));
			}
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_int_ovf(&result->un.int_value,
							 value->un.ulong_value))
				{
					return 0;
				}
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ubyte(jit_ulong_to_int(value->un.ulong_value));
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_int_ovf(&result->un.int_value,
							   value->un.float32_value))
				{
					return 0;
				}
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ubyte(jit_float32_to_int(value->un.float32_value));
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_int_ovf(&result->un.int_value,
							   value->un.float64_value))
				{
					return 0;
				}
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ubyte(jit_float64_to_int(value->un.float64_value));
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_int_ovf(&result->un.int_value,
							  value->un.nfloat_value))
				{
					return 0;
				}
				if(!jit_int_to_ubyte_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ubyte(jit_nfloat_to_int(value->un.nfloat_value));
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_SHORT:
		/* Convert to a signed 16-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			if(overflow_check)
			{
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 value->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_short(value->un.int_value);
			}
			break;

		case JIT_TYPE_UINT:
			if(overflow_check)
			{
				if(!jit_uint_to_int_ovf(&result->un.int_value,
							value->un.uint_value))
				{
					return 0;
				}
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_short(value->un.int_value);
			}
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_int_ovf(&result->un.int_value,
							value->un.long_value))
				{
					return 0;
				}
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_short(
						jit_long_to_int(value->un.long_value));
			}
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_int_ovf(&result->un.int_value,
							 value->un.ulong_value))
				{
					return 0;
				}
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_short(
						jit_ulong_to_int(value->un.ulong_value));
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_int_ovf(&result->un.int_value,
							   value->un.float32_value))
				{
					return 0;
				}
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_short(
						jit_float32_to_int(value->un.float32_value));
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_int_ovf(&result->un.int_value,
							   value->un.float64_value))
				{
					return 0;
				}
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_short(
						jit_float64_to_int(value->un.float64_value));
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_int_ovf(&result->un.int_value,
							  value->un.nfloat_value))
				{
					return 0;
				}
				if(!jit_int_to_short_ovf(&result->un.int_value,
							 result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_short(
						jit_nfloat_to_int(value->un.nfloat_value));
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_USHORT:
		/* Convert to an unsigned 16-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			if(overflow_check)
			{
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  value->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_ushort(value->un.int_value);
			}
			break;

		case JIT_TYPE_UINT:
			if(overflow_check)
			{
				if(!jit_uint_to_int_ovf(&result->un.int_value,
							value->un.uint_value))
				{
					return 0;
				}
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_int_to_ushort(value->un.int_value);
			}
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_int_ovf(&result->un.int_value,
							value->un.long_value))
				{
					return 0;
				}
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ushort(
						jit_long_to_int(value->un.long_value));
			}
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_int_ovf(&result->un.int_value,
							 value->un.ulong_value))
				{
					return 0;
				}
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ushort(
						jit_ulong_to_int(value->un.ulong_value));
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_int_ovf(&result->un.int_value,
							   value->un.float32_value))
				{
					return 0;
				}
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ushort(
						jit_float32_to_int(value->un.float32_value));
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_int_ovf(&result->un.int_value,
							   value->un.float64_value))
				{
					return 0;
				}
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ushort(
						jit_float64_to_int(value->un.float64_value));
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_int_ovf(&result->un.int_value,
							  value->un.nfloat_value))
				{
					return 0;
				}
				if(!jit_int_to_ushort_ovf(&result->un.int_value,
							  result->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value =
					jit_int_to_ushort(
						jit_nfloat_to_int(value->un.nfloat_value));
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_INT:
		/* Convert to a signed 32-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			result->un.int_value = value->un.int_value;
			break;

		case JIT_TYPE_UINT:
			if(overflow_check)
			{
				if(!jit_uint_to_int_ovf(&result->un.int_value,
							value->un.uint_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_uint_to_int(value->un.uint_value);
			}
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_int_ovf(&result->un.int_value,
							value->un.long_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_long_to_int(value->un.long_value);
			}
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_int_ovf(&result->un.int_value,
							 value->un.ulong_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_ulong_to_int(value->un.ulong_value);
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_int_ovf(&result->un.int_value,
							   value->un.float32_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_float32_to_int(value->un.float32_value);
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_int_ovf(&result->un.int_value,
							   value->un.float64_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_float64_to_int(value->un.float64_value);
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_int_ovf(&result->un.int_value,
							  value->un.nfloat_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.int_value = jit_nfloat_to_int(value->un.nfloat_value);
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_UINT:
		/* Convert to an unsigned 32-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			if(overflow_check)
			{
				if(!jit_int_to_uint_ovf(&result->un.uint_value,
							value->un.uint_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.uint_value = jit_int_to_uint(value->un.int_value);
			}
			break;

		case JIT_TYPE_UINT:
			result->un.uint_value = value->un.uint_value;
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_uint_ovf(&result->un.uint_value,
							 value->un.long_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.uint_value = jit_long_to_uint(value->un.long_value);
			}
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_uint_ovf(&result->un.uint_value,
							  value->un.ulong_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.uint_value = jit_ulong_to_uint(value->un.ulong_value);
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_uint_ovf(&result->un.uint_value,
							    value->un.float32_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.uint_value = jit_float32_to_uint(value->un.float32_value);
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_uint_ovf(&result->un.uint_value,
							    value->un.float64_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.uint_value = jit_float64_to_uint(value->un.float64_value);
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_uint_ovf(&result->un.uint_value,
							   value->un.nfloat_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.uint_value = jit_nfloat_to_uint(value->un.nfloat_value);
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_LONG:
		/* Convert to a signed 64-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			result->un.long_value =
				jit_int_to_long(value->un.int_value);
			break;

		case JIT_TYPE_UINT:
			result->un.long_value =
				jit_uint_to_long(value->un.int_value);
			break;

		case JIT_TYPE_LONG:
			result->un.long_value = value->un.long_value;
			break;

		case JIT_TYPE_ULONG:
			if(overflow_check)
			{
				if(!jit_ulong_to_long_ovf(&result->un.long_value,
							  value->un.ulong_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.long_value = jit_ulong_to_long(value->un.ulong_value);
			}
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_long_ovf(&result->un.long_value,
							    value->un.float32_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.long_value = jit_float32_to_long(value->un.float32_value);
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_long_ovf(&result->un.long_value,
							    value->un.float64_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.long_value = jit_float64_to_long(value->un.float64_value);
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_long_ovf(&result->un.long_value,
							   value->un.nfloat_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.long_value = jit_nfloat_to_long(value->un.nfloat_value);
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_ULONG:
		/* Convert to an unsigned 64-bit integer */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			if(overflow_check)
			{
				if(!jit_int_to_ulong_ovf(&result->un.ulong_value,
							 value->un.int_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.ulong_value = jit_int_to_ulong(value->un.int_value);
			}
			break;

		case JIT_TYPE_UINT:
			result->un.ulong_value =
				jit_uint_to_ulong(value->un.uint_value);
			break;

		case JIT_TYPE_LONG:
			if(overflow_check)
			{
				if(!jit_long_to_ulong_ovf(&result->un.ulong_value,
							  value->un.long_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.ulong_value = jit_long_to_ulong(value->un.long_value);
			}
			break;

		case JIT_TYPE_ULONG:
			result->un.ulong_value = value->un.ulong_value;
			break;

		case JIT_TYPE_FLOAT32:
			if(overflow_check)
			{
				if(!jit_float32_to_ulong_ovf(&result->un.ulong_value,
							     value->un.float32_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.ulong_value = jit_float32_to_ulong(value->un.float32_value);
			}
			break;

		case JIT_TYPE_FLOAT64:
			if(overflow_check)
			{
				if(!jit_float64_to_ulong_ovf(&result->un.ulong_value,
							     value->un.float64_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.ulong_value = jit_float64_to_ulong(value->un.float64_value);
			}
			break;

		case JIT_TYPE_NFLOAT:
			if(overflow_check)
			{
				if(!jit_nfloat_to_ulong_ovf(&result->un.ulong_value,
							    value->un.nfloat_value))
				{
					return 0;
				}
			}
			else
			{
				result->un.ulong_value = jit_nfloat_to_ulong(value->un.nfloat_value);
			}
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_FLOAT32:
		/* Convert to a 32-bit float */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			result->un.float32_value = jit_int_to_float32(value->un.int_value);
			break;

		case JIT_TYPE_UINT:
			result->un.float32_value = jit_uint_to_float32(value->un.uint_value);
			break;

		case JIT_TYPE_LONG:
			result->un.float32_value = jit_long_to_float32(value->un.long_value);
			break;

		case JIT_TYPE_ULONG:
			result->un.float32_value = jit_ulong_to_float32(value->un.ulong_value);
			break;

		case JIT_TYPE_FLOAT32:
			result->un.float32_value = value->un.float32_value;
			break;

		case JIT_TYPE_FLOAT64:
			result->un.float32_value = jit_float64_to_float32(value->un.float64_value);
			break;

		case JIT_TYPE_NFLOAT:
			result->un.float32_value = jit_nfloat_to_float32(value->un.nfloat_value);
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_FLOAT64:
		/* Convert to a 64-bit float */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			result->un.float64_value = jit_int_to_float64(value->un.int_value);
			break;

		case JIT_TYPE_UINT:
			result->un.float64_value = jit_uint_to_float64(value->un.uint_value);
			break;

		case JIT_TYPE_LONG:
			result->un.float64_value = jit_long_to_float64(value->un.long_value);
			break;

		case JIT_TYPE_ULONG:
			result->un.float64_value = jit_ulong_to_float64(value->un.ulong_value);
			break;

		case JIT_TYPE_FLOAT32:
			result->un.float64_value = jit_float32_to_float64(value->un.float32_value);
			break;

		case JIT_TYPE_FLOAT64:
			result->un.float64_value = value->un.float64_value;
			break;

		case JIT_TYPE_NFLOAT:
			result->un.float64_value = jit_nfloat_to_float64(value->un.nfloat_value);
			break;

		default:
			return 0;
		}
		break;

	case JIT_TYPE_NFLOAT:
		/* Convert to a native float */
		switch(srctype->kind)
		{
		case JIT_TYPE_INT:
			result->un.nfloat_value = jit_int_to_nfloat(value->un.int_value);
			break;

		case JIT_TYPE_UINT:
			result->un.nfloat_value = jit_uint_to_nfloat(value->un.uint_value);
			break;

		case JIT_TYPE_LONG:
			result->un.nfloat_value = jit_long_to_nfloat(value->un.long_value);
			break;

		case JIT_TYPE_ULONG:
			result->un.nfloat_value = jit_ulong_to_nfloat(value->un.ulong_value);
			break;

		case JIT_TYPE_FLOAT32:
			result->un.nfloat_value = jit_float32_to_nfloat(value->un.float32_value);
			break;

		case JIT_TYPE_FLOAT64:
			result->un.nfloat_value	= jit_float64_to_nfloat(value->un.float64_value);
			break;

		case JIT_TYPE_NFLOAT:
			result->un.nfloat_value = value->un.nfloat_value;
			break;

		default:
			return 0;
		}
		break;

	default:
		return 0;
	}
	return 1;
}