Alien-LibJIT
view release on metacpan or search on metacpan
libjit/jit/jit-dump.c view on Meta::CPAN
*/
char s_path[BUFSIZ];
char o_path[BUFSIZ];
char *tmp_dir = getenv("TMP");
if(tmp_dir == NULL)
{
tmp_dir = getenv("TEMP");
if(tmp_dir == NULL)
{
tmp_dir = "c:/tmp";
}
}
sprintf(s_path, "%s/libjit-dump.s", tmp_dir);
sprintf(o_path, "%s/libjit-dump.o", tmp_dir);
#else
const char *s_path = "/tmp/libjit-dump.s";
const char *o_path = "/tmp/libjit-dump.o";
#endif
file = fopen(s_path, "w");
if(!file)
{
return;
}
fflush(stream);
while(pc < (unsigned char *)end)
{
fprintf(file, ".byte %d\n", (int)(*pc));
++pc;
}
fclose(file);
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);
( run in 0.711 second using v1.01-cache-2.11-cpan-5b529ec07f3 )