diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | include/ejit/ejit.h | 53 | ||||
| -rw-r--r-- | tests/absr_f.c | 11 | ||||
| -rw-r--r-- | tests/addi.c | 34 | ||||
| -rw-r--r-- | tests/addr.c | 21 | ||||
| -rw-r--r-- | tests/addr_d.c | 27 | ||||
| -rw-r--r-- | tests/addr_f.c | 14 | ||||
| -rwxr-xr-x | tests/test-bcode-absr_f | bin | 288432 -> 0 bytes | 
8 files changed, 86 insertions, 75 deletions
| @@ -3,5 +3,6 @@ tests.mk  docs/output  build  ejit.o +test-*  examples/exec  examples/*.d diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h index 895ce9b..e15550d 100644 --- a/include/ejit/ejit.h +++ b/include/ejit/ejit.h @@ -25,6 +25,21 @@ enum ejit_type  	EJIT_DOUBLE,  }; +/* can be kind of dangerous since we default to a pointer, hmm */ +#define EJIT_TYPE(x)\ +	_Generic((typeof(x))(0),\ +			int8_t: EJIT_INT8,\ +			int16_t: EJIT_INT16,\ +			int32_t: EJIT_INT32,\ +			int64_t: EJIT_INT64,\ +			uint8_t: EJIT_UINT8,\ +			uint16_t: EJIT_UINT16,\ +			uint32_t: EJIT_UINT32,\ +			uint64_t: EJIT_UINT64,\ +			float: EJIT_FLOAT,\ +			double: EJIT_DOUBLE,\ +			default: EJIT_POINTER) +  struct ejit_arg {  	union {  		int8_t i8; @@ -155,8 +170,20 @@ void ejit_compile_func(struct ejit_func *f, size_t gpr, size_t fpr);  void ejit_select_compile_func(struct ejit_func *f, size_t gpr, size_t fpr,                                bool try_jit); -long ejit_run_func(struct ejit_func *f, size_t argc, +int64_t ejit_run_func(struct ejit_func *f, size_t argc,                     struct ejit_arg args[argc]); + +static inline int64_t ejit_run_func_1(struct ejit_func *f, struct ejit_arg a0) +{ +	return ejit_run_func(f, 1, &a0); +} + +static inline int64_t ejit_run_func_2(struct ejit_func *f, struct ejit_arg a0, struct ejit_arg a1) +{ +	struct ejit_arg args[2] = {a0, a1}; +	return ejit_run_func(f, 2, args); +} +  double ejit_run_func_f(struct ejit_func *f, size_t argc,                         struct ejit_arg args[argc]); @@ -205,13 +232,28 @@ static inline struct ejit_arg ejit_i32(int32_t a)  	return (struct ejit_arg){.i32 = a, .type = EJIT_INT32};  } +static inline struct ejit_arg ejit_i64(int64_t a) +{ +	return (struct ejit_arg){.i64 = a, .type = EJIT_INT64}; +} + +static inline struct ejit_arg ejit_pointer(void *p) +{ +	return (struct ejit_arg){.p = p, .type = EJIT_POINTER}; +} + +static inline struct ejit_arg ejit_float(float a) +{ +	return (struct ejit_arg){.f = a, .type = EJIT_FLOAT}; +} +  static inline struct ejit_arg ejit_double(double a)  {  	return (struct ejit_arg){.d = a, .type = EJIT_DOUBLE};  } -#define EJIT_ARG(x)                     \ -	_Generic((x),                   \ +#define EJIT_ARG(x, t)                  \ +	_Generic((t)(0),                   \  		 int8_t: ejit_i8,       \  		 int16_t: ejit_i16,     \  		 int32_t: ejit_i32,     \ @@ -222,9 +264,12 @@ static inline struct ejit_arg ejit_double(double a)  		 uint64_t: ejit_i64,    \  		 float: ejit_float,     \  		 double: ejit_double,   \ -		 default: ejit_pointer, \ +		 default: ejit_pointer \  		 )(x) +#define EJIT_AUTO(x) \ +	EJIT_ARG(x, typeof(x)) +  typedef long (*ejit_escape_t)(size_t argc, const struct ejit_arg args[argc]);  typedef double (*ejit_escape_f_t)(size_t argc,                                    const struct ejit_arg args[argc]); diff --git a/tests/absr_f.c b/tests/absr_f.c index cc070b6..94a0e42 100644 --- a/tests/absr_f.c +++ b/tests/absr_f.c @@ -7,13 +7,14 @@ int main()  	struct ejit_operand operands[1] = {  		EJIT_OPERAND_FPR(0, EJIT_DOUBLE)  	}; -	struct ejit_func *f = ejit_create_func(EJIT_DOUBLE, 1, operands); +	struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 1, operands);  	ejit_absr_f(f, EJIT_FPR(0), EJIT_FPR(0));  	ejit_retr_f(f, EJIT_FPR(0));  	ejit_select_compile_func(f, 0, 1, do_jit); -	assert(ejit_run_func_f_1(f, ejit_double(0.0)) == 0.0); -	assert(ejit_run_func_f_1(f, ejit_double(-0.0)) == 0.0); -	assert(ejit_run_func_f_1(f, ejit_double(0.5)) == 0.5); -	assert(ejit_run_func_f_1(f, ejit_double(-0.5)) == 0.5); +	assert(ejit_run_func_f_1(f, EJIT_ARG(0.0, double)) == 0.0); +	assert(ejit_run_func_f_1(f, EJIT_ARG(-0.0, double)) == 0.0); +	assert(ejit_run_func_f_1(f, EJIT_ARG(0.5, double)) == 0.5); +	assert(ejit_run_func_f_1(f, EJIT_ARG(-0.5, double)) == 0.5); +	ejit_destroy_func(f);  } diff --git a/tests/addi.c b/tests/addi.c index 27cdfab..e0471d6 100644 --- a/tests/addi.c +++ b/tests/addi.c @@ -1,25 +1,17 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main()  { -	jit_begin(j, arena_base, arena_size); -	size_t align = jit_enter_jit_abi(j, 0, 0, 0); -	jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0)); +	struct ejit_operand operands[1] = { +		EJIT_OPERAND_GPR(0, EJIT_TYPE(int)) +	}; +	struct ejit_func *f = ejit_create_func(EJIT_TYPE(int), 1, operands); +	ejit_addi(f, EJIT_GPR(0), EJIT_GPR(0), 69); +	ejit_retr(f, EJIT_GPR(0)); +	ejit_select_compile_func(f, 1, 0, do_jit); -	jit_addi(j, JIT_R0, JIT_R0, 69); -	jit_leave_jit_abi(j, 0, 0, align); -	jit_retr(j, JIT_R0); - -	size_t size = 0; -	void* ret = jit_end(j, &size); - -	int (*f)(int) = ret; -	ASSERT(f(42) == 111); -} - -int -main (int argc, char *argv[]) -{ -	return main_helper(argc, argv, run_test); +	assert(ejit_run_func_1(f, EJIT_ARG(42, int)) == 111); +	ejit_destroy_func(f);  } diff --git a/tests/addr.c b/tests/addr.c index f524aa6..099536a 100644 --- a/tests/addr.c +++ b/tests/addr.c @@ -1,23 +1,22 @@  #include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h"  int  main (int argc, char *argv[])  {  	struct ejit_operand operands[2] = { -		EJIT_OPERAND_GPR(0, EJIT_LONG), -		EJIT_OPERAND_GPR(1, EJIT_LONG) +		EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), +		EJIT_OPERAND_GPR(1, EJIT_TYPE(long))  	}; -	struct ejit_func *f = ejit_create_func(EJIT_LONG, 2, operands); +	struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); -	ejit_addr(j, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); -	ejit_retr(j, EJIT_GPR(0)); +	ejit_addr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); +	ejit_retr(f, EJIT_GPR(0)); -	ejit_compile(f); +	ejit_select_compile_func(f, 2, 0, do_jit); -	struct ejit_arg args[2] = { -		EJIT_ARG(42, EJIT_LONG), -		EJIT_ARG(69, EJIT_LONG) -	}; -	ASSERT(ejit_run_func(f, 2, args) == 111); +	assert(ejit_run_func_2(f, EJIT_ARG(42, long), EJIT_ARG(69, long)) == 111); +	ejit_destroy_func(f);  } diff --git a/tests/addr_d.c b/tests/addr_d.c deleted file mode 100644 index 2aa9002..0000000 --- a/tests/addr_d.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "test.h" - -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) -{ -	jit_begin(j, arena_base, arena_size); -	size_t align = jit_enter_jit_abi(j, 0, 0, 0); -	jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0), -	                jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F1)); - -	jit_addr_d(j, JIT_F0, JIT_F0, JIT_F1); -	jit_leave_jit_abi(j, 0, 0, align); -	jit_retr_d(j, JIT_F0); - -	size_t size = 0; -	void* ret = jit_end(j, &size); - -	double (*f)(double, double) = ret; -	ASSERT(f(42., 69.) == 111.); -	ASSERT(f(42.5, 69.5) == 112.); -} - -int -main (int argc, char *argv[]) -{ -	return main_helper(argc, argv, run_test); -} diff --git a/tests/addr_f.c b/tests/addr_f.c index d27ce8b..2aa9002 100644 --- a/tests/addr_f.c +++ b/tests/addr_f.c @@ -5,19 +5,19 @@ run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)  {  	jit_begin(j, arena_base, arena_size);  	size_t align = jit_enter_jit_abi(j, 0, 0, 0); -	jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0), -	                jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1)); +	jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0), +	                jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F1)); -	jit_addr_f(j, JIT_F0, JIT_F0, JIT_F1); +	jit_addr_d(j, JIT_F0, JIT_F0, JIT_F1);  	jit_leave_jit_abi(j, 0, 0, align); -	jit_retr_f(j, JIT_F0); +	jit_retr_d(j, JIT_F0);  	size_t size = 0;  	void* ret = jit_end(j, &size); -	float (*f)(float, float) = ret; -	ASSERT(f(42.f, 69.f) == 111.f); -	ASSERT(f(42.5f, 69.5f) == 112.f); +	double (*f)(double, double) = ret; +	ASSERT(f(42., 69.) == 111.); +	ASSERT(f(42.5, 69.5) == 112.);  }  int diff --git a/tests/test-bcode-absr_f b/tests/test-bcode-absr_fBinary files differ deleted file mode 100755 index 8e902b5..0000000 --- a/tests/test-bcode-absr_f +++ /dev/null | 
