summaryrefslogtreecommitdiff
path: root/tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb
blob: 084a3dd6c83f8fcac38217adc0f504a298391654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% # Copyright (c) 2018 Takashi Kokubun.  All rights reserved.
% #
% # This file is a part of  the programming language Ruby.  Permission is hereby
% # granted, to either  redistribute and/or modify this file,  provided that the
% # conditions mentioned  in the  file COPYING  are met.   Consult the  file for
% # details.
%
% # JIT: Move pc so that catch table lookup condition is met. If the ISeq might not catch an exception,
% # the pc motion is optimized away and thus pc should be set properly before `goto cancel`.
        if (body->catch_except_p) {
% if insn.handles_frame?
            fprintf(f, "    reg_cfp->pc = original_body_iseq + %d;\n", next_pos); /* ADD_PC(INSN_ATTR(width)); */
% else
            fprintf(f, "    reg_cfp->pc = original_body_iseq + %d;\n", pos);
% end
        }
%
% # JIT: move sp to use or preserve stack variables
        if (status->local_stack_p) {
% # sp motion is optimized away for `handles_frame? #=> false` case.
% # Thus sp should be set properly before `goto cancel`.
% if insn.handles_frame?
            fprintf(f, "    reg_cfp->sp = (VALUE *)reg_cfp->bp + stack_size + 1 - <%= insn.pops.size %>;\n"); /* POPN(INSN_ATTR(popn)); */
%
%           # JIT-only behavior (pushing JIT's local variables to VM's stack):
            {
                rb_snum_t i, push_size;
                push_size = -<%= insn.call_attribute('sp_inc') %> + <%= insn.rets.size %> - <%= insn.pops.size %>;
                for (i = 0; i < push_size; i++) { /* TODO: use memcpy? */
                    fprintf(f, "    *(reg_cfp->sp + %ld) = stack[%ld];\n", i - push_size, (rb_snum_t)b->stack_size - push_size + i);
                }
            }
% end
        }
        else {
% if insn.handles_frame?
            fprintf(f, "    reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1 - <%= insn.pops.size %>); /* POPN(INSN_ATTR(popn)); */
% else
            fprintf(f, "    reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1);
% end
        }