aboutsummaryrefslogtreecommitdiff
path: root/tests/z_double_label.c
blob: 4817d8c43938e688945727caac1a5f497c3146fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <ejit/ejit.h>
#include <assert.h>
#include "do_jit.h"

int main(int argc, char *argv[])
{
	(void)argv;
	bool do_jit = argc > 1;
	struct ejit_func *f = ejit_create_func(EJIT_INT32, 0, NULL);
	ejit_movi(f, EJIT_GPR(0), 0);

	struct ejit_reloc l1 = ejit_jmp(f);
	struct ejit_label mid = ejit_label(f);
	struct ejit_reloc l2 = ejit_jmp(f);

	/* patch relocs to same address with two separate labels. */
	ejit_patch(f, l1, ejit_label(f));
	ejit_patch(f, l2, ejit_label(f));

	/* we came from the first jump, jump to the end */
	struct ejit_reloc end = ejit_beqi(f, EJIT_GPR(0), 1);

	/* set r0 to 1 to indicate that we've done the first jump */
	ejit_movi(f, EJIT_GPR(0), 1);

	/* jump in between the two jumps */
	ejit_patch(f, ejit_jmp(f), mid);

	ejit_patch(f, end, ejit_label(f));
	ejit_reti(f, 0);


	ejit_select_compile_func(f, 1, 0, false, do_jit, true);

	assert(ejit_run_func_i(f, 0, NULL) == 0);

	ejit_destroy_func(f);
}