git subrepo clone https://git.savannah.gnu.org/git/lightning.git deps/lightning
[pcsx_rearmed.git] / deps / lightning / doc / printf.c
1 #include <stdio.h>
2 #include <lightning.h>
3
4 static jit_state_t *_jit;
5
6 typedef void (*pvfi)(int);    /* Pointer to Void Function of Int */
7
8 int main(int argc, char *argv[])
9 {
10   pvfi          myFunction;             /* ptr to generated code */
11   jit_node_t    *start, *end;           /* a couple of labels */
12   jit_node_t    *in;                    /* to get the argument */
13
14   init_jit(argv[0]);
15   _jit = jit_new_state();
16
17   start = jit_note(__FILE__, __LINE__);
18   jit_prolog();
19   in = jit_arg();
20   jit_getarg(JIT_R1, in);
21   jit_prepare();
22   jit_pushargi((jit_word_t)"generated %d bytes\n");
23   jit_ellipsis();
24   jit_pushargr(JIT_R1);
25   jit_finishi(printf);
26   jit_ret();
27   jit_epilog();
28   end = jit_note(__FILE__, __LINE__);
29
30   myFunction = jit_emit();
31
32   /* call the generated code, passing its size as argument */
33   myFunction((char*)jit_address(end) - (char*)jit_address(start));
34   jit_clear_state();
35
36   jit_disassemble();
37
38   jit_destroy_state();
39   finish_jit();
40   return 0;
41 }