aboutsummaryrefslogtreecommitdiff
path: root/tests/escapei_10.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-06-30 00:53:34 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-06-30 00:53:34 +0300
commit451797936119d8236843c4e9aee4a47dc5cddd56 (patch)
tree5aed431a0058bbe00627659cefc8fef85a4e18bb /tests/escapei_10.c
parent864a078cf9faf9b85a7a9042b4033d46847aea8f (diff)
downloadejit-451797936119d8236843c4e9aee4a47dc5cddd56.tar.gz
ejit-451797936119d8236843c4e9aee4a47dc5cddd56.zip
continue working through test cases
+ Remove overflow and more complicated floating point tests for now
Diffstat (limited to 'tests/escapei_10.c')
-rw-r--r--tests/escapei_10.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/escapei_10.c b/tests/escapei_10.c
new file mode 100644
index 0000000..2ca1ea2
--- /dev/null
+++ b/tests/escapei_10.c
@@ -0,0 +1,81 @@
+#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);
+ assert(args[0].type == EJIT_INT32);
+ assert(args[1].type == EJIT_INT32);
+ assert(args[3].type == EJIT_INT32);
+ assert(args[4].type == EJIT_INT32);
+ assert(args[5].type == EJIT_INT32);
+ assert(args[6].type == EJIT_INT32);
+ assert(args[7].type == EJIT_INT32);
+ assert(args[8].type == EJIT_INT32);
+ assert(args[9].type == EJIT_INT32);
+
+ int32_t a = args[0].i32;
+ int32_t b = args[1].i32;
+ int32_t c = args[2].i32;
+ int32_t d = args[3].i32;
+ int32_t e = args[4].i32;
+ int32_t f = args[5].i32;
+ int32_t g = args[6].i32;
+ int32_t h = args[7].i32;
+ int32_t i = args[8].i32;
+ int32_t j = args[9].i32;
+ return func(a, b, c, d, e, f, g, h, i, j);
+}
+
+int main()
+{
+ 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(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);
+
+ int32_t iargs[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ assert(ejit_run_func_1(f, EJIT_ARG(iargs, void *)) == 42);
+
+ ejit_destroy_func(f);
+}