summaryrefslogtreecommitdiff
path: root/tool/ruby_vm/views/_insn_entry.erb
blob: bdd0fa3c7cb2c9e53e79162382ba490a8fbd8901 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
%# -*- C -*-
%# Copyright (c) 2017 Urabe, Shyouhei.  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.
%;
% body = render_c_expr(insn.expr).gsub(/^#/, '#   ')

/* insn <%= insn.pretty_name %> */
INSN_ENTRY(<%= insn.name %>)
{
    /* ###  Declare that we have just entered into an instruction. ### */
    START_OF_ORIGINAL_INSN(<%= insn.name %>);
    DEBUG_ENTER_INSN(<%=cstr insn.name %>);

    /* ###  Declare and assign variables. ### */
% insn.preamble.each do |konst|
<%= render_c_expr konst -%>
% end
%
% insn.opes.each_with_index do |ope, i|
    <%= ope[:decl] %> = (<%= ope[:type] %>)GET_OPERAND(<%= i + 1 %>);
% end
#   define INSN_ATTR(x) <%= insn.call_attribute(' ## x ## ') %>
    bool leaf = INSN_ATTR(leaf);
% insn.pops.reverse_each.with_index.reverse_each do |pop, i|
    <%= pop[:decl] %> = <%= insn.cast_from_VALUE pop, "TOPN(#{i})"%>;
% end
%
% insn.rets.each do |ret|
%   next if insn.has_ope?(ret) or insn.has_pop?(ret)
    <%= ret[:decl] %>;
% end

    /* ### Instruction preambles. ### */
    if (! leaf) ADD_PC(INSN_ATTR(width));
% if insn.handles_sp?
    POPN(INSN_ATTR(popn));
% end
<%= insn.handle_canary "SETUP_CANARY(leaf)" -%>
    COLLECT_USAGE_INSN(INSN_ATTR(bin));
% insn.opes.each_with_index do |ope, i|
    COLLECT_USAGE_OPERAND(INSN_ATTR(bin), <%= i %>, <%= ope[:name] %>);
% end
% unless body.empty?

    /* ### Here we do the instruction body. ### */
%#  NAME_OF_CURRENT_INSN is used in vm_exec.h
#   define NAME_OF_CURRENT_INSN <%= insn.name %>
<%= body -%>
#   undef NAME_OF_CURRENT_INSN
% end

    /* ### Instruction trailers. ### */
    CHECK_VM_STACK_OVERFLOW_FOR_INSN(VM_REG_CFP, INSN_ATTR(retn));
<%= insn.handle_canary "CHECK_CANARY(leaf, INSN_ATTR(bin))" -%>
% if insn.handles_sp?
%   insn.rets.reverse_each do |ret|
    PUSH(<%= insn.cast_to_VALUE ret %>);
%   end
% else
    INC_SP(INSN_ATTR(sp_inc));
%   insn.rets.reverse_each.with_index do |ret, i|
    TOPN(<%= i %>) = <%= insn.cast_to_VALUE ret %>;
    VM_ASSERT(!RB_TYPE_P(TOPN(<%= i %>), T_NONE));
    VM_ASSERT(!RB_TYPE_P(TOPN(<%= i %>), T_MOVED));
%   end
% end
    if (leaf) ADD_PC(INSN_ATTR(width));
#   undef INSN_ATTR

    /* ### Leave the instruction. ### */
    END_INSN(<%= insn.name %>);
}