diff options
author | Mike Pall <mike> | 2011-11-25 19:36:35 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-11-25 19:36:35 +0100 |
commit | c142b6c53eb8c9cb08ecc3a4db98cc1ff61b5989 (patch) | |
tree | c9f30473126af40cd41a7528ca35002898339a4a /src | |
parent | b3f16cb64d8eef247d3763eb90ece38810f29781 (diff) | |
download | luajit-c142b6c53eb8c9cb08ecc3a4db98cc1ff61b5989.tar.gz luajit-c142b6c53eb8c9cb08ecc3a4db98cc1ff61b5989.tar.bz2 luajit-c142b6c53eb8c9cb08ecc3a4db98cc1ff61b5989.zip |
FFI: Record C function calls with bool return values.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.dep | 2 | ||||
-rw-r--r-- | src/lj_cconv.c | 2 | ||||
-rw-r--r-- | src/lj_crecord.c | 31 | ||||
-rw-r--r-- | src/lj_jit.h | 1 | ||||
-rw-r--r-- | src/lj_record.c | 8 |
5 files changed, 38 insertions, 6 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index b9d0df47..afcf5c12 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
@@ -93,7 +93,7 @@ lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
93 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \ | 93 | lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \ |
94 | lj_gc.h lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ir.h \ | 94 | lj_gc.h lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ir.h \ |
95 | lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h \ | 95 | lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h \ |
96 | lj_record.h lj_ffrecord.h lj_crecord.h | 96 | lj_record.h lj_ffrecord.h lj_snap.h lj_crecord.h |
97 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 97 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
98 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_ccallback.h | 98 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_ccallback.h |
99 | lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 99 | lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
diff --git a/src/lj_cconv.c b/src/lj_cconv.c index d73984f4..9d478355 100644 --- a/src/lj_cconv.c +++ b/src/lj_cconv.c | |||
@@ -391,7 +391,7 @@ int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, | |||
391 | lua_assert(tvisnum(o)); | 391 | lua_assert(tvisnum(o)); |
392 | } | 392 | } |
393 | } else { | 393 | } else { |
394 | uint32_t b = ((*sp) & 1); | 394 | uint32_t b = (*sp != 0); |
395 | setboolV(o, b); | 395 | setboolV(o, b); |
396 | setboolV(&cts->g->tmptv2, b); /* Remember for trace recorder. */ | 396 | setboolV(&cts->g->tmptv2, b); /* Remember for trace recorder. */ |
397 | } | 397 | } |
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 9457b519..313bee81 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "lj_trace.h" | 27 | #include "lj_trace.h" |
28 | #include "lj_record.h" | 28 | #include "lj_record.h" |
29 | #include "lj_ffrecord.h" | 29 | #include "lj_ffrecord.h" |
30 | #include "lj_snap.h" | ||
30 | #include "lj_crecord.h" | 31 | #include "lj_crecord.h" |
31 | #include "lj_dispatch.h" | 32 | #include "lj_dispatch.h" |
32 | 33 | ||
@@ -839,6 +840,26 @@ static TRef crec_call_args(jit_State *J, RecordFFData *rd, | |||
839 | return tr; | 840 | return tr; |
840 | } | 841 | } |
841 | 842 | ||
843 | /* Create a snapshot for the caller, simulating a 'false' return value. */ | ||
844 | static void crec_snap_caller(jit_State *J) | ||
845 | { | ||
846 | lua_State *L = J->L; | ||
847 | TValue *base = L->base, *top = L->top; | ||
848 | const BCIns *pc = J->pc; | ||
849 | TRef ftr = J->base[-1]; | ||
850 | ptrdiff_t delta; | ||
851 | if (!frame_islua(base-1)) | ||
852 | lj_trace_err(J, LJ_TRERR_NYICALL); | ||
853 | J->pc = frame_pc(base-1); delta = 1+bc_a(J->pc[-1]); | ||
854 | L->top = base; L->base = base - delta; | ||
855 | J->base[-1] = TREF_FALSE; | ||
856 | J->base -= delta; J->baseslot -= delta; J->maxslot = delta; J->framedepth--; | ||
857 | lj_snap_add(J); | ||
858 | L->base = base; L->top = top; | ||
859 | J->framedepth++; J->base += delta; J->baseslot += delta; J->maxslot = 1; | ||
860 | J->base[-1] = ftr; J->pc = pc; | ||
861 | } | ||
862 | |||
842 | /* Record function call. */ | 863 | /* Record function call. */ |
843 | static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | 864 | static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) |
844 | { | 865 | { |
@@ -867,8 +888,7 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | |||
867 | ctr = ctype_child(cts, ctr); | 888 | ctr = ctype_child(cts, ctr); |
868 | } | 889 | } |
869 | if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) || | 890 | if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) || |
870 | ctype_isvoid(ctr->info)) || | 891 | ctype_isvoid(ctr->info)) || t == IRT_CDATA) |
871 | ctype_isbool(ctr->info) || t == IRT_CDATA) | ||
872 | lj_trace_err(J, LJ_TRERR_NYICALL); | 892 | lj_trace_err(J, LJ_TRERR_NYICALL); |
873 | if ((ct->info & CTF_VARARG) | 893 | if ((ct->info & CTF_VARARG) |
874 | #if LJ_TARGET_X86 | 894 | #if LJ_TARGET_X86 |
@@ -878,7 +898,12 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | |||
878 | func = emitir(IRT(IR_CARG, IRT_NIL), func, | 898 | func = emitir(IRT(IR_CARG, IRT_NIL), func, |
879 | lj_ir_kint(J, ctype_typeid(cts, ct))); | 899 | lj_ir_kint(J, ctype_typeid(cts, ct))); |
880 | tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); | 900 | tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); |
881 | if (t == IRT_FLOAT || t == IRT_U32) { | 901 | if (ctype_isbool(ctr->info)) { |
902 | crec_snap_caller(J); | ||
903 | lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0)); | ||
904 | J->postproc = LJ_POST_FIXGUARDSNAP; | ||
905 | tr = TREF_TRUE; | ||
906 | } else if (t == IRT_FLOAT || t == IRT_U32) { | ||
882 | tr = emitconv(tr, IRT_NUM, t, 0); | 907 | tr = emitconv(tr, IRT_NUM, t, 0); |
883 | } else if (t == IRT_I8 || t == IRT_I16) { | 908 | } else if (t == IRT_I8 || t == IRT_I16) { |
884 | tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT); | 909 | tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT); |
diff --git a/src/lj_jit.h b/src/lj_jit.h index 11dc9737..8a4c04c8 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h | |||
@@ -122,6 +122,7 @@ typedef enum { | |||
122 | LJ_POST_NONE, /* No action. */ | 122 | LJ_POST_NONE, /* No action. */ |
123 | LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */ | 123 | LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */ |
124 | LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */ | 124 | LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */ |
125 | LJ_POST_FIXGUARDSNAP, /* Fixup and emit pending guard and snapshot. */ | ||
125 | LJ_POST_FIXBOOL, /* Fixup boolean result. */ | 126 | LJ_POST_FIXBOOL, /* Fixup boolean result. */ |
126 | LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */ | 127 | LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */ |
127 | } PostProc; | 128 | } PostProc; |
diff --git a/src/lj_record.c b/src/lj_record.c index a76f5d94..2c27a718 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -1573,8 +1573,14 @@ void lj_record_ins(jit_State *J) | |||
1573 | rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1))); | 1573 | rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1))); |
1574 | /* fallthrough */ | 1574 | /* fallthrough */ |
1575 | case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */ | 1575 | case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */ |
1576 | if (!tvistruecond(&J2G(J)->tmptv2)) | 1576 | case LJ_POST_FIXGUARDSNAP: /* Fixup and emit pending guard and snapshot. */ |
1577 | if (!tvistruecond(&J2G(J)->tmptv2)) { | ||
1577 | J->fold.ins.o ^= 1; /* Flip guard to opposite. */ | 1578 | J->fold.ins.o ^= 1; /* Flip guard to opposite. */ |
1579 | if (J->postproc == LJ_POST_FIXGUARDSNAP) { | ||
1580 | SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; | ||
1581 | J->cur.snapmap[snap->mapofs+snap->nent-1]--; /* False -> true. */ | ||
1582 | } | ||
1583 | } | ||
1578 | lj_opt_fold(J); /* Emit pending guard. */ | 1584 | lj_opt_fold(J); /* Emit pending guard. */ |
1579 | /* fallthrough */ | 1585 | /* fallthrough */ |
1580 | case LJ_POST_FIXBOOL: | 1586 | case LJ_POST_FIXBOOL: |