aboutsummaryrefslogtreecommitdiff
path: root/tests/escapei_10.c
blob: ec48df08288536acd4684444e0807f70ba83f474 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <ejit/ejit.h>
#include <assert.h>
#include "do_jit.h"

static int32_t func(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
                    int32_t f, int32_t g, int32_t h, int32_t i, int32_t j)
{
	assert(a == 0);
	assert(b == 1);
	assert(c == 2);
	assert(d == 3);
	assert(e == 4);
	assert(f == 5);
	assert(g == 6);
	assert(h == 7);
	assert(i == 8);
	assert(j == 9);
	return 42;
}

static long escape_func(size_t argc, const struct ejit_arg args[argc])
{
	assert(argc == 10);
	int32_t a = EJIT_PARAM(argc, args, 0, int32_t);
	int32_t b = EJIT_PARAM(argc, args, 1, int32_t);
	int32_t c = EJIT_PARAM(argc, args, 2, int32_t);
	int32_t d = EJIT_PARAM(argc, args, 3, int32_t);
	int32_t e = EJIT_PARAM(argc, args, 4, int32_t);
	int32_t f = EJIT_PARAM(argc, args, 5, int32_t);
	int32_t g = EJIT_PARAM(argc, args, 6, int32_t);
	int32_t h = EJIT_PARAM(argc, args, 7, int32_t);
	int32_t i = EJIT_PARAM(argc, args, 8, int32_t);
	int32_t j = EJIT_PARAM(argc, args, 9, int32_t);
	return func(a, b, c, d, e, f, g, h, i, j);
}

int main(int argc, char *argv[])
{
	(void)argv;
	bool do_jit = argc > 1;
	struct ejit_operand operands[1] = {
		EJIT_OPERAND_GPR(0, EJIT_POINTER)
	};
	struct ejit_func *f = ejit_create_func(EJIT_INT32, 1, operands);
	/* move from argument array to registers */
	for (size_t i = 0; i < 10; ++i) {
		ejit_ldxi_i32(f, EJIT_GPR(i + 1), EJIT_GPR(0),
		              i * sizeof(int32_t));
	}

	struct ejit_operand args[10] = {
		EJIT_OPERAND_GPR( 1, EJIT_INT32),
		EJIT_OPERAND_GPR( 2, EJIT_INT32),
		EJIT_OPERAND_GPR( 3, EJIT_INT32),
		EJIT_OPERAND_GPR( 4, EJIT_INT32),
		EJIT_OPERAND_GPR( 5, EJIT_INT32),
		EJIT_OPERAND_GPR( 6, EJIT_INT32),
		EJIT_OPERAND_GPR( 7, EJIT_INT32),
		EJIT_OPERAND_GPR( 8, EJIT_INT32),
		EJIT_OPERAND_GPR( 9, EJIT_INT32),
		EJIT_OPERAND_GPR(10, EJIT_INT32),
	};
	ejit_escapei_i(f, escape_func, 10, args);
	ejit_retval(f, EJIT_GPR(0));
	ejit_retr(f, EJIT_GPR(0));

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

	int32_t iargs[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	assert(erfi1(f, EJIT_ARG(iargs, void *)) == 42);

	ejit_destroy_func(f);
}