Alien-LibJIT
view release on metacpan or search on metacpan
libjit/jit/jit-dump.c view on Meta::CPAN
{
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);
}
/*
* Dump a temporary value, prefixed by its type.
*/
static void dump_value(FILE *stream, jit_function_t func,
jit_value_t value, int type)
{
/* Normalize the type, so that it reflects JIT_OPCODE_DEST_xxx values */
libjit/jit/jit-dump.c view on Meta::CPAN
sprintf(cmdline, "as %s -o %s", s_path, o_path);
system(cmdline);
sprintf(cmdline, "objdump --adjust-vma=%ld -d %s > %s",
(long)(jit_nint)start, o_path, s_path);
system(cmdline);
file = fopen(s_path, "r");
if(file)
{
while((ch = getc(file)) != EOF)
{
putc(ch, stream);
}
fclose(file);
}
unlink(s_path);
unlink(o_path);
putc('\n', stream);
fflush(stream);
}
#endif /* !JIT_BACKEND_INTERP */
/*@
* @deftypefun void jit_dump_function (FILE *@var{stream}, jit_function_t @var{func}, const char *@var{name})
* Dump the three-address instructions within a function to a stream.
* The @var{name} is attached to the output as a friendly label, but
* has no other significance.
*
* If the function has not been compiled yet, then this will dump the
* three address instructions from the build process. Otherwise it will
* disassemble and dump the compiled native code.
* @end deftypefun
@*/
void jit_dump_function(FILE *stream, jit_function_t func, const char *name)
{
jit_block_t block;
jit_insn_iter_t iter;
jit_insn_t insn;
jit_type_t signature;
unsigned int param;
unsigned int num_params;
jit_value_t value;
jit_label_t label;
/* Bail out if we don't have sufficient information to dump */
if(!stream || !func)
{
return;
}
/* Output the function header */
if(name)
fprintf(stream, "function %s(", name);
else
fprintf(stream, "function 0x%08lX(", (long)(jit_nuint)func);
signature = func->signature;
num_params = jit_type_num_params(signature);
if(func->builder)
{
value = jit_value_get_struct_pointer(func);
if(value || func->nested_parent)
{
/* We have extra hidden parameters */
putc('[', stream);
if(func->nested_parent)
{
fputs("parent_frame", stream);
if(value)
{
fputs(", ", stream);
}
}
if(value)
{
jit_dump_value(stream, func, value, 0);
fputs(" : struct_ptr", stream);
}
putc(']', stream);
if(num_params > 0)
{
fputs(", ", stream);
}
}
for(param = 0; param < num_params; ++param)
{
if(param != 0)
{
fputs(", ", stream);
}
value = jit_value_get_param(func, param);
if(value)
{
jit_dump_value(stream, func, value, 0);
}
else
{
fputs("???", stream);
}
fputs(" : ", stream);
jit_dump_type(stream, jit_type_get_param(signature, param));
}
}
else
{
for(param = 0; param < num_params; ++param)
{
if(param != 0)
{
fputs(", ", stream);
}
jit_dump_type(stream, jit_type_get_param(signature, param));
}
}
fprintf(stream, ") : ");
jit_dump_type(stream, jit_type_get_return(signature));
putc('\n', stream);
/* Should we dump the three address code or the native code? */
if(func->builder)
{
/* Output each of the three address blocks in turn */
block = 0;
while((block = jit_block_next(func, block)) != 0)
{
/* Output the block's labels, if it has any */
label = jit_block_get_label(block);
if(block->label != jit_label_undefined)
( run in 0.466 second using v1.01-cache-2.11-cpan-3d66aa2751a )