diff options
Diffstat (limited to 'src/lj_crecord.c')
-rw-r--r-- | src/lj_crecord.c | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index b4bfd0c2..2ecd2867 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
@@ -670,14 +670,79 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id) | |||
670 | } | 670 | } |
671 | } | 671 | } |
672 | 672 | ||
673 | /* Record argument conversions. */ | ||
674 | static TRef crec_call_args(jit_State *J, RecordFFData *rd, | ||
675 | CTState *cts, CType *ct) | ||
676 | { | ||
677 | TRef args[CCI_NARGS_MAX]; | ||
678 | MSize i, n; | ||
679 | TRef tr; | ||
680 | args[0] = TREF_NIL; | ||
681 | for (n = 0; J->base[n+1]; n++) { | ||
682 | CType *d; | ||
683 | do { | ||
684 | if (!ct->sib) | ||
685 | lj_trace_err(J, LJ_TRERR_NYICALL); | ||
686 | ct = ctype_get(cts, ct->sib); | ||
687 | } while (ctype_isattrib(ct->info)); | ||
688 | if (!ctype_isfield(ct->info)) | ||
689 | lj_trace_err(J, LJ_TRERR_NYICALL); | ||
690 | d = ctype_rawchild(cts, ct); | ||
691 | if (ctype_isenum(d->info)) d = ctype_child(cts, d); | ||
692 | if (!(ctype_isnum(d->info) || ctype_isptr(d->info))) | ||
693 | lj_trace_err(J, LJ_TRERR_NYICALL); | ||
694 | args[n] = crec_ct_tv(J, d, 0, J->base[n+1], &rd->argv[n+1]); | ||
695 | } | ||
696 | tr = args[0]; | ||
697 | for (i = 1; i < n; i++) | ||
698 | tr = emitir(IRT(IR_CARG, IRT_NIL), tr, args[i]); | ||
699 | return tr; | ||
700 | } | ||
701 | |||
702 | /* Record function call. */ | ||
703 | static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | ||
704 | { | ||
705 | CTState *cts = ctype_ctsG(J2G(J)); | ||
706 | CType *ct = ctype_raw(cts, cd->typeid); | ||
707 | IRType tp = IRT_PTR; | ||
708 | if (ctype_isptr(ct->info)) { | ||
709 | tp = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32; | ||
710 | ct = ctype_rawchild(cts, ct); | ||
711 | } | ||
712 | if (ctype_isfunc(ct->info)) { | ||
713 | TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR); | ||
714 | CType *ctr = ctype_rawchild(cts, ct); | ||
715 | IRType t = crec_ct2irt(ctr); | ||
716 | TRef tr; | ||
717 | if (ctype_isenum(ctr->info)) ctr = ctype_child(cts, ctr); | ||
718 | if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info)) || | ||
719 | ctype_isbool(ctr->info) || (ct->info & CTF_VARARG) || | ||
720 | #if LJ_TARGET_X86 | ||
721 | ctype_cconv(ct->info) != CTCC_CDECL || | ||
722 | #endif | ||
723 | t == IRT_CDATA || (LJ_32 && (t == IRT_I64 || t == IRT_U64))) | ||
724 | lj_trace_err(J, LJ_TRERR_NYICALL); | ||
725 | tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); | ||
726 | if (t == IRT_FLOAT || t == IRT_U32) { | ||
727 | tr = emitconv(tr, IRT_NUM, t, 0); | ||
728 | } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) || | ||
729 | (LJ_64 && (t == IRT_I64 || t == IRT_U64))) { | ||
730 | TRef trid = lj_ir_kint(J, ctype_cid(ct->info)); | ||
731 | tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr); | ||
732 | } | ||
733 | J->base[0] = tr; | ||
734 | return 1; | ||
735 | } | ||
736 | return 0; | ||
737 | } | ||
738 | |||
673 | void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd) | 739 | void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd) |
674 | { | 740 | { |
675 | GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]); | 741 | GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]); |
676 | if (cd->typeid == CTID_CTYPEID) { | 742 | if (cd->typeid == CTID_CTYPEID) |
677 | crec_alloc(J, rd, crec_constructor(J, cd, J->base[0])); | 743 | crec_alloc(J, rd, crec_constructor(J, cd, J->base[0])); |
678 | } else { | 744 | else if (!crec_call(J, rd, cd)) |
679 | lj_trace_err(J, LJ_TRERR_BADTYPE); | 745 | lj_trace_err(J, LJ_TRERR_BADTYPE); |
680 | } | ||
681 | } | 746 | } |
682 | 747 | ||
683 | static TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm) | 748 | static TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm) |