Debian Codegraph @

libguile/lightening/tests/jmpi.c

raw
1 #include "test.h"
2
3 void *tail;
4
5 static void *target;
6
7 static void
8 run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
9 {
10 jit_begin(j, arena_base, arena_size);
11 jit_enter_jit_abi(j, 0, 0, 0);
12 jit_movi(j, JIT_R0, 42);
13 jit_jmpi(j, target);
14 // Unreachable.
15 jit_breakpoint(j);
16 int (*f)(void) = jit_end(j, NULL);
17 ASSERT(f() == 42);
18 }
19
20 // Make the tail-call target via a separate main_helper because probably the new
21 // arena will be allocated farther away, forcing nonlocal jumps.
22 static void
23 make_target(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
24 {
25 jit_begin(j, arena_base, arena_size);
26 size_t align = jit_enter_jit_abi(j, 0, 0, 0);
27 // Tail call target assumes tail caller called enter_jit_abi with compatible
28 // parameters.
29 target = jit_address(j);
30 jit_leave_jit_abi(j, 0, 0, align);
31 jit_retr(j, JIT_R0);
32 jit_end(j, NULL);
33
34 main_helper(0, NULL, run_test);
35 }
36
37 int
38 main (int argc, char *argv[])
39 {
40 return main_helper(argc, argv, make_target);
41 }