diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-04-09 20:20:48 +0300 | 
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-04-09 20:20:48 +0300 | 
| commit | 057131cb20fb1c46e90adecfb4a16eb62f100580 (patch) | |
| tree | 82081321522eaef1b049cce1fb4627a75a6d6664 /tests/taili.c | |
| parent | 6824dd4b1ee22184f0e600115db3998924ed39d6 (diff) | |
| download | ejit-057131cb20fb1c46e90adecfb4a16eb62f100580.tar.gz ejit-057131cb20fb1c46e90adecfb4a16eb62f100580.zip | |
add taili
Diffstat (limited to 'tests/taili.c')
| -rw-r--r-- | tests/taili.c | 39 | 
1 files changed, 39 insertions, 0 deletions
| diff --git a/tests/taili.c b/tests/taili.c new file mode 100644 index 0000000..cc09f59 --- /dev/null +++ b/tests/taili.c @@ -0,0 +1,39 @@ +#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_operand operands[2] = { +		EJIT_OPERAND_GPR(0, EJIT_INT32), /* s */ +		EJIT_OPERAND_GPR(1, EJIT_INT32)  /* n */ +	}; + +	struct ejit_func *f = ejit_create_func(EJIT_INT32, 2, operands); + +	/* n == 0, return s */ +	struct ejit_reloc r = ejit_bnei(f, EJIT_GPR(1), 0); +	ejit_retr(f, EJIT_GPR(0)); +	ejit_patch(f, r, ejit_label(f)); + +	/* s += n */ +	ejit_addr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + +	/* n -= 1 */ +	ejit_subi(f, EJIT_GPR(1), EJIT_GPR(1), 1); + +	struct ejit_operand args[2] = { +		EJIT_OPERAND_GPR(0, EJIT_INT32), /* s */ +		EJIT_OPERAND_GPR(1, EJIT_INT32)  /* n */ +	}; +	ejit_taili(f, f, 2, args); + +	ejit_select_compile_func(f, 2, 0, EJIT_USE64(uintptr_t), do_jit, true); + +	/* arbitrary number but large enough to most likely cause a stack fault +	 * if the tail call leaks memory or something */ +	assert((int32_t)erfi2(f, EJIT_ARG(0, int32_t), EJIT_ARG(1000000, int32_t)) == 1784293664); +	ejit_destroy_func(f); +} | 
