diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-24 20:33:56 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-24 20:33:56 +0300 |
commit | fe3d9c7dfbe4190ecf0919abe474e4da4c019566 (patch) | |
tree | 91dd12b6a9980e5945e7dbde761afadd9d118d09 /src | |
parent | 5a4da8bac457f0e70e690a572eba9cf754e69a37 (diff) | |
download | ejit-fe3d9c7dfbe4190ecf0919abe474e4da4c019566.tar.gz ejit-fe3d9c7dfbe4190ecf0919abe474e4da4c019566.zip |
add initial compiler framework
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/compile/compile.c | 8 | ||||
-rw-r--r-- | src/compile/nocompile.c | 7 | ||||
-rw-r--r-- | src/ejit.c | 25 | ||||
-rw-r--r-- | src/interp.c | 12 | ||||
-rw-r--r-- | src/source.mk | 5 |
6 files changed, 44 insertions, 15 deletions
diff --git a/src/common.h b/src/common.h index 21e881b..e93e920 100644 --- a/src/common.h +++ b/src/common.h @@ -123,4 +123,6 @@ union interp_ret { union interp_ret ejit_interp(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], bool run, void ***labels_wb); +bool ejit_compile(struct ejit_func *f); + #endif /* EJIT_COMMON_H */ diff --git a/src/compile/compile.c b/src/compile/compile.c new file mode 100644 index 0000000..513e0e1 --- /dev/null +++ b/src/compile/compile.c @@ -0,0 +1,8 @@ +#include <ejit/ejit.h> +#include "../../deps/lightening/lightening/lightening.c" +#include "../common.h" + +bool ejit_compile(struct ejit_func *f) +{ + return false; +} diff --git a/src/compile/nocompile.c b/src/compile/nocompile.c new file mode 100644 index 0000000..065d466 --- /dev/null +++ b/src/compile/nocompile.c @@ -0,0 +1,7 @@ +#include <ejit/ejit.h> + +bool ejit_compile(struct ejit_func *f) +{ + (void)(f); + return false; +} @@ -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; +} diff --git a/src/interp.c b/src/interp.c index 4678aa1..bbf461b 100644 --- a/src/interp.c +++ b/src/interp.c @@ -176,15 +176,3 @@ out_float: free(fpr); return (union interp_ret){.d = retval_f}; } - -long ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) -{ - assert(f->rtype == EJIT_VOID || ejit_int_type(f->rtype)); - 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(ejit_float_type(f->rtype)); - return ejit_interp(f, argc, args, true, NULL).d; -} diff --git a/src/source.mk b/src/source.mk index 907befa..870550d 100644 --- a/src/source.mk +++ b/src/source.mk @@ -1,2 +1,3 @@ -LOCAL_SOURCES != echo src/*.c -EJIT_SOURCES := $(EJIT_SOURCES) $(LOCAL_SOURCES) +SRCS != echo src/*.c +COMPILE_SOURCE != ./scripts/select-compile $(ARCH) +EJIT_SOURCES := $(EJIT_SOURCES) $(SRCS) $(COMPILE_SOURCE) |