From fe3d9c7dfbe4190ecf0919abe474e4da4c019566 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 24 Jun 2024 20:33:56 +0300 Subject: add initial compiler framework --- src/ejit.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/ejit.c') 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; +} -- cgit v1.2.3