diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-07 18:50:34 +0200 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-07 18:52:54 +0200 |
commit | ba9145b0b7af2a82c62f8dfa28807958af5d0c8d (patch) | |
tree | 52e14e07d82d57a305334f1300293d6b0af75aca /src/compile/compile.c | |
parent | 6d00dddef440590eaba9acdc9bbd093653d46519 (diff) | |
download | ejit-ba9145b0b7af2a82c62f8dfa28807958af5d0c8d.tar.gz ejit-ba9145b0b7af2a82c62f8dfa28807958af5d0c8d.zip |
make code a bit more robust
+ Should be more difficult to make mistakes in the future, ejit can now
automatically keep track of how many register slots are used and if 64
bit mode is required. Slight runtime overhead, but not too bad.
Diffstat (limited to 'src/compile/compile.c')
-rw-r--r-- | src/compile/compile.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/compile/compile.c b/src/compile/compile.c index 0411a3e..9a97b3a 100644 --- a/src/compile/compile.c +++ b/src/compile/compile.c @@ -63,7 +63,7 @@ static jit_off_t stack_loc_f(struct ejit_func *f, size_t l) static jit_gpr_t getloc(struct ejit_func *f, jit_state_t *j, size_t l, size_t i) { - (void)(f); + assert(l < f->gpr); if (l < jit_v_num()) return jit_v(l); @@ -74,7 +74,7 @@ static jit_gpr_t getloc(struct ejit_func *f, jit_state_t *j, size_t l, size_t i) static jit_fpr_t getloc_f(struct ejit_func *f, jit_state_t *j, size_t l, size_t i) { - (void)(f); + assert(l < f->fpr); if (l < jit_vf_num()) return jit_vf(l); @@ -85,7 +85,7 @@ static jit_fpr_t getloc_f(struct ejit_func *f, jit_state_t *j, size_t l, static jit_fpr_t getloc_d(struct ejit_func *f, jit_state_t *j, size_t l, size_t i) { - (void)(f); + assert(l < f->fpr); if (l < jit_vf_num()) return jit_vf(l); @@ -97,7 +97,7 @@ static jit_fpr_t getloc_d(struct ejit_func *f, jit_state_t *j, size_t l, static jit_gpr_t getgpr(struct ejit_func *f, size_t l, size_t i) { - (void)(f); + assert(l < f->gpr); if (l < jit_v_num()) return jit_v(l); @@ -106,7 +106,7 @@ static jit_gpr_t getgpr(struct ejit_func *f, size_t l, size_t i) static jit_fpr_t getfpr(struct ejit_func *f, size_t l, size_t i) { - (void)(f); + assert(l < f->fpr); if (l < jit_vf_num()) return jit_vf(l); @@ -115,7 +115,7 @@ static jit_fpr_t getfpr(struct ejit_func *f, size_t l, size_t i) static void putloc(struct ejit_func *f, jit_state_t *j, size_t l, jit_gpr_t r) { - (void)(f); + assert(l < f->gpr); if (l < jit_v_num()) { assert(jit_v(l).regno == r.regno); return; @@ -126,6 +126,7 @@ static void putloc(struct ejit_func *f, jit_state_t *j, size_t l, jit_gpr_t r) static void putloc_f(struct ejit_func *f, jit_state_t *j, size_t l, jit_fpr_t r) { + assert(l < f->fpr); if (l < jit_vf_num()) { assert(jit_v(l).regno == r.regno); return; @@ -136,6 +137,7 @@ static void putloc_f(struct ejit_func *f, jit_state_t *j, size_t l, jit_fpr_t r) static void putloc_d(struct ejit_func *f, jit_state_t *j, size_t l, jit_fpr_t r) { + assert(l < f->fpr); if (l < jit_vf_num()) { assert(jit_v(l).regno == r.regno); return; @@ -1992,7 +1994,7 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, case RETVAL_D: compile_retval_d(f, j, i); break; case RETR: { - jit_gpr_t r = getloc(f, j, i.r0, 0); + jit_gpr_t r = getloc(f, j, i.r1, 0); /* R0 won't get overwritten by jit_leave_jit_abi */ jit_movr(j, JIT_R0, r); jit_shrink_stack(j, stack); @@ -2002,7 +2004,7 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, } case RETR_F: { - jit_fpr_t r = getloc_f(f, j, i.r0, 0); + jit_fpr_t r = getloc_f(f, j, i.r1, 0); /* convert float to double so the return types match */ jit_extr_f_d(j, JIT_F0, r); jit_shrink_stack(j, stack); @@ -2012,7 +2014,7 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, } case RETR_D: { - jit_fpr_t r = getloc_d(f, j, i.r0, 0); + jit_fpr_t r = getloc_d(f, j, i.r1, 0); jit_movr_d(j, JIT_F0, r); jit_shrink_stack(j, stack); jit_leave_jit_abi(j, gprs, fprs, frame); @@ -2037,7 +2039,7 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, case PARAM_F: { jit_operand_t to; - if (i.r0 < jit_vf_num()) { + if (i.r2 < jit_vf_num()) { /* regular register */ to = jit_operand_fpr(jit_abi_from(i.r1), jit_vf(i.r2)); @@ -2054,7 +2056,7 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, case PARAM: { jit_operand_t to; - if (i.r0 < jit_v_num()) { + if (i.r2 < jit_v_num()) { /* regular register */ to = jit_operand_gpr(jit_abi_from(i.r1), jit_v(i.r2)); |