mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 04:10:18 +02:00
* include/lightning.h, lib/lightning.c: Implement the new jit_clear_state and jit_destroy_state calls. jit_clear_state releases all memory not required during jit_execution; that is, leaves only the mmap'ed data and code buffers allocated. jit_destroy_state releases the mmap'ed buffers as well as the jit_state_t object itself, that holds pointers to the code and data buffers, as well as annotation pointers (for disassembly or backtrace) in the data buffer. * lib/jit_note.c: Correct invalid vector offset access. * check/ccall.c, check/lightning.c, doc/ifib.c, doc/incr.c, doc/printf.c, doc/rfib.c, doc/rpn.c: Use the new jit_clear_state and jit_destroy_state calls, to demonstrate the new code to release all jit memory. * doc/body.texi: Add basic documentation and usage description of jit_clear_state and jit_destroy_state.
40 lines
961 B
C
40 lines
961 B
C
#include <stdio.h>
|
|
#include <lightning.h>
|
|
|
|
static jit_state_t *_jit;
|
|
|
|
typedef void (*pvfi)(int); /* Pointer to Void Function of Int */
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
pvfi myFunction; /* ptr to generated code */
|
|
jit_node_t *start, *end; /* a couple of labels */
|
|
jit_node_t *in; /* to get the argument */
|
|
|
|
init_jit(argv[0]);
|
|
_jit = jit_new_state();
|
|
|
|
start = jit_note(__FILE__, __LINE__);
|
|
jit_prolog();
|
|
in = jit_arg();
|
|
jit_getarg(JIT_R1, in);
|
|
jit_pushargi((jit_word_t)"generated %d bytes\n");
|
|
jit_ellipsis();
|
|
jit_pushargr(JIT_R1);
|
|
jit_finishi(printf);
|
|
jit_ret();
|
|
jit_epilog();
|
|
end = jit_note(__FILE__, __LINE__);
|
|
|
|
myFunction = jit_emit();
|
|
|
|
/* call the generated code, passing its size as argument */
|
|
myFunction((char*)jit_address(end) - (char*)jit_address(start));
|
|
jit_clear_state();
|
|
|
|
jit_disassemble();
|
|
|
|
jit_destroy_state();
|
|
finish_jit();
|
|
return 0;
|
|
}
|