mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-02 04:40:29 +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.
31 lines
807 B
C
31 lines
807 B
C
#include <stdio.h>
|
|
#include <lightning.h>
|
|
|
|
static jit_state_t *_jit;
|
|
|
|
typedef int (*pifi)(int); /* Pointer to Int Function of Int */
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
jit_node_t *in;
|
|
pifi incr;
|
|
|
|
init_jit(argv[0]);
|
|
_jit = jit_new_state();
|
|
|
|
jit_prolog(); /* @t{ prolog } */
|
|
in = jit_arg(); /* @t{ in = arg } */
|
|
jit_getarg(JIT_R0, in); /* @t{ getarg R0 } */
|
|
jit_addi(JIT_R0, JIT_R0, 1); /* @t{ addi R0\, R0\, 1 } */
|
|
jit_retr(JIT_R0); /* @t{ retr R0 } */
|
|
|
|
incr = jit_emit();
|
|
jit_clear_state();
|
|
|
|
/* call the generated code\, passing 5 as an argument */
|
|
printf("%d + 1 = %d\n", 5, incr(5));
|
|
|
|
jit_destroy_state();
|
|
finish_jit();
|
|
return 0;
|
|
}
|