aboutsummaryrefslogtreecommitdiff
path: root/src/ejit.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-06-24 20:33:56 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-06-24 20:33:56 +0300
commitfe3d9c7dfbe4190ecf0919abe474e4da4c019566 (patch)
tree91dd12b6a9980e5945e7dbde761afadd9d118d09 /src/ejit.c
parent5a4da8bac457f0e70e690a572eba9cf754e69a37 (diff)
downloadejit-fe3d9c7dfbe4190ecf0919abe474e4da4c019566.tar.gz
ejit-fe3d9c7dfbe4190ecf0919abe474e4da4c019566.zip
add initial compiler framework
Diffstat (limited to 'src/ejit.c')
-rw-r--r--src/ejit.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ejit.c b/src/ejit.c
index bd5a652..7fe2095 100644
--- a/src/ejit.c
+++ b/src/ejit.c
@@ -57,7 +57,10 @@ void ejit_compile_func(struct ejit_func *f, size_t gpr, size_t fpr)
{
f->gpr = gpr;
f->fpr = fpr;
- /** @todo try to implement JIT */
+
+ if (ejit_compile(f))
+ return;
+
/* otherwise, convert opcodes to address labels */
void **labels;
@@ -188,3 +191,23 @@ struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit
emit_insn_i(s, BLTR, r0.r, r1.r, 0);
return (struct ejit_reloc){.insn = label.addr};
}
+
+long ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc])
+{
+ assert(f->gpr && "trying to run a function that hasn't been compiled");
+ assert(f->rtype == EJIT_VOID || ejit_int_type(f->rtype));
+ if (f->arena)
+ return ((ejit_escape_f_t)f)(argc, args);
+
+ return ejit_interp(f, argc, args, true, NULL).r;
+}
+
+double ejit_run_func_f(struct ejit_func *f, size_t argc, struct ejit_arg args[argc])
+{
+ assert(f->fpr && "trying to run a function that hasn't been compiled");
+ assert(ejit_float_type(f->rtype));
+ if (f->arena)
+ return ((ejit_escape_f_t)f)(argc, args);
+
+ return ejit_interp(f, argc, args, true, NULL).d;
+}