diff options
author | Mike Pall <mike> | 2013-05-13 17:04:19 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-05-13 17:04:19 +0200 |
commit | 2369f5d00ab0a391dd23091af42d893ddceafa76 (patch) | |
tree | 23f91f19c5d2652d77d6d2b737ece7958ec47d97 | |
parent | 101780c69bffb67959d110fbb930677ad0021b19 (diff) | |
download | luajit-2369f5d00ab0a391dd23091af42d893ddceafa76.tar.gz luajit-2369f5d00ab0a391dd23091af42d893ddceafa76.tar.bz2 luajit-2369f5d00ab0a391dd23091af42d893ddceafa76.zip |
Abstract out default BUFHDR emitter.
-rw-r--r-- | src/lj_ffrecord.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index dd8912ee..97c24836 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -647,6 +647,13 @@ static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd) | |||
647 | 647 | ||
648 | /* -- String library fast functions --------------------------------------- */ | 648 | /* -- String library fast functions --------------------------------------- */ |
649 | 649 | ||
650 | /* Emit BUFHDR for the global temporary buffer. */ | ||
651 | static TRef recff_bufhdr(jit_State *J) | ||
652 | { | ||
653 | return emitir(IRT(IR_BUFHDR, IRT_P32), | ||
654 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
655 | } | ||
656 | |||
650 | /* Specialize to relative starting position for string. */ | 657 | /* Specialize to relative starting position for string. */ |
651 | static TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr, | 658 | static TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr, |
652 | TRef trlen, TRef tr0) | 659 | TRef trlen, TRef tr0) |
@@ -764,9 +771,7 @@ static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd) | |||
764 | J->base[i] = emitir(IRT(IR_TOSTR, IRT_STR), tr, IRTOSTR_CHAR); | 771 | J->base[i] = emitir(IRT(IR_TOSTR, IRT_STR), tr, IRTOSTR_CHAR); |
765 | } | 772 | } |
766 | if (i > 1) { /* Concatenate the strings, if there's more than one. */ | 773 | if (i > 1) { /* Concatenate the strings, if there's more than one. */ |
767 | TRef hdr = emitir(IRT(IR_BUFHDR, IRT_P32), | 774 | TRef hdr = recff_bufhdr(J), tr = hdr; |
768 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
769 | TRef tr = hdr; | ||
770 | for (i = 0; J->base[i] != 0; i++) | 775 | for (i = 0; J->base[i] != 0; i++) |
771 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, J->base[i]); | 776 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, J->base[i]); |
772 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | 777 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); |
@@ -784,15 +789,13 @@ static void LJ_FASTCALL recff_string_rep(jit_State *J, RecordFFData *rd) | |||
784 | int32_t vrep = argv2int(J, &rd->argv[1]); | 789 | int32_t vrep = argv2int(J, &rd->argv[1]); |
785 | emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1)); | 790 | emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1)); |
786 | if (vrep > 1) { | 791 | if (vrep > 1) { |
787 | TRef hdr2 = emitir(IRT(IR_BUFHDR, IRT_P32), | 792 | TRef hdr2 = recff_bufhdr(J); |
788 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
789 | TRef tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), hdr2, sep); | 793 | TRef tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), hdr2, sep); |
790 | tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), tr2, str); | 794 | tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), tr2, str); |
791 | str2 = emitir(IRT(IR_BUFSTR, IRT_STR), tr2, hdr2); | 795 | str2 = emitir(IRT(IR_BUFSTR, IRT_STR), tr2, hdr2); |
792 | } | 796 | } |
793 | } | 797 | } |
794 | tr = hdr = emitir(IRT(IR_BUFHDR, IRT_P32), | 798 | tr = hdr = recff_bufhdr(J); |
795 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
796 | if (str2) { | 799 | if (str2) { |
797 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, str); | 800 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, str); |
798 | str = str2; | 801 | str = str2; |
@@ -805,8 +808,7 @@ static void LJ_FASTCALL recff_string_rep(jit_State *J, RecordFFData *rd) | |||
805 | static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd) | 808 | static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd) |
806 | { | 809 | { |
807 | TRef str = lj_ir_tostr(J, J->base[0]); | 810 | TRef str = lj_ir_tostr(J, J->base[0]); |
808 | TRef hdr = emitir(IRT(IR_BUFHDR, IRT_P32), | 811 | TRef hdr = recff_bufhdr(J); |
809 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
810 | TRef tr = lj_ir_call(J, rd->data, hdr, str); | 812 | TRef tr = lj_ir_call(J, rd->data, hdr, str); |
811 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | 813 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); |
812 | } | 814 | } |
@@ -903,8 +905,7 @@ static void LJ_FASTCALL recff_table_concat(jit_State *J, RecordFFData *rd) | |||
903 | TRef tre = (J->base[1] && J->base[2] && !tref_isnil(J->base[3])) ? | 905 | TRef tre = (J->base[1] && J->base[2] && !tref_isnil(J->base[3])) ? |
904 | lj_opt_narrow_toint(J, J->base[3]) : | 906 | lj_opt_narrow_toint(J, J->base[3]) : |
905 | lj_ir_call(J, IRCALL_lj_tab_len, tab); | 907 | lj_ir_call(J, IRCALL_lj_tab_len, tab); |
906 | TRef hdr = emitir(IRT(IR_BUFHDR, IRT_P32), | 908 | TRef hdr = recff_bufhdr(J); |
907 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
908 | TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre); | 909 | TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre); |
909 | emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL)); | 910 | emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL)); |
910 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | 911 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); |