2018-12-27 01:12:09 -05:00
|
|
|
%# -*- C -*-
|
2018-01-12 03:38:09 -05:00
|
|
|
%# 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.
|
|
|
|
%;
|
2019-01-25 09:09:10 -05:00
|
|
|
% body = render_c_expr(insn.expr).gsub(/^#/, '# ')
|
2018-01-12 03:38:09 -05:00
|
|
|
|
|
|
|
/* insn <%= insn.pretty_name %> */
|
|
|
|
INSN_ENTRY(<%= insn.name %>)
|
|
|
|
{
|
2019-01-25 09:09:10 -05:00
|
|
|
/* ### Declare that we have just entered into an instruction. ### */
|
2018-01-12 03:38:09 -05:00
|
|
|
START_OF_ORIGINAL_INSN(<%= insn.name %>);
|
2019-01-25 09:09:10 -05:00
|
|
|
DEBUG_ENTER_INSN(<%=cstr insn.name %>);
|
|
|
|
|
|
|
|
/* ### Declare and assign variables. ### */
|
2018-01-12 03:38:09 -05:00
|
|
|
% insn.preamble.each do |konst|
|
|
|
|
<%= render_c_expr konst -%>
|
|
|
|
% end
|
2019-01-25 09:09:10 -05:00
|
|
|
%
|
2018-01-12 03:38:09 -05:00
|
|
|
% insn.opes.each_with_index do |ope, i|
|
2019-01-25 09:09:10 -05:00
|
|
|
<%= ope[:decl] %> = (<%= ope[:type] %>)GET_OPERAND(<%= i + 1 %>);
|
2018-01-12 03:38:09 -05:00
|
|
|
% end
|
2019-01-25 09:09:10 -05:00
|
|
|
# define INSN_ATTR(x) <%= insn.call_attribute(' ## x ## ') %>
|
2021-12-05 11:02:55 -05:00
|
|
|
const bool leaf = INSN_ATTR(leaf);
|
2018-01-12 03:38:09 -05:00
|
|
|
% insn.pops.reverse_each.with_index.reverse_each do |pop, i|
|
2019-01-25 09:09:10 -05:00
|
|
|
<%= 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] %>;
|
2018-01-12 03:38:09 -05:00
|
|
|
% end
|
2019-01-25 09:09:10 -05:00
|
|
|
|
|
|
|
/* ### Instruction preambles. ### */
|
|
|
|
if (! leaf) ADD_PC(INSN_ATTR(width));
|
2018-07-25 10:55:43 -04:00
|
|
|
% if insn.handles_sp?
|
2018-01-29 01:47:05 -05:00
|
|
|
POPN(INSN_ATTR(popn));
|
2018-09-11 05:48:58 -04:00
|
|
|
% end
|
2020-06-21 13:27:04 -04:00
|
|
|
<%= insn.handle_canary "SETUP_CANARY(leaf)" -%>
|
2018-01-29 01:47:05 -05:00
|
|
|
COLLECT_USAGE_INSN(INSN_ATTR(bin));
|
2018-01-12 03:38:09 -05:00
|
|
|
% insn.opes.each_with_index do |ope, i|
|
2018-01-29 01:47:05 -05:00
|
|
|
COLLECT_USAGE_OPERAND(INSN_ATTR(bin), <%= i %>, <%= ope[:name] %>);
|
2018-01-12 03:38:09 -05:00
|
|
|
% end
|
2019-01-25 09:09:10 -05:00
|
|
|
% 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. ### */
|
2018-01-29 01:47:05 -05:00
|
|
|
CHECK_VM_STACK_OVERFLOW_FOR_INSN(VM_REG_CFP, INSN_ATTR(retn));
|
2020-06-21 13:27:04 -04:00
|
|
|
<%= insn.handle_canary "CHECK_CANARY(leaf, INSN_ATTR(bin))" -%>
|
2018-07-25 10:55:43 -04:00
|
|
|
% if insn.handles_sp?
|
2018-07-19 09:25:22 -04:00
|
|
|
% insn.rets.reverse_each do |ret|
|
2018-01-12 03:38:09 -05:00
|
|
|
PUSH(<%= insn.cast_to_VALUE ret %>);
|
|
|
|
% end
|
2018-07-19 09:25:22 -04:00
|
|
|
% else
|
2018-09-14 03:44:44 -04:00
|
|
|
INC_SP(INSN_ATTR(sp_inc));
|
2018-07-19 09:25:22 -04:00
|
|
|
% insn.rets.reverse_each.with_index do |ret, i|
|
|
|
|
TOPN(<%= i %>) = <%= insn.cast_to_VALUE ret %>;
|
2019-10-11 20:13:02 -04:00
|
|
|
VM_ASSERT(!RB_TYPE_P(TOPN(<%= i %>), T_NONE));
|
|
|
|
VM_ASSERT(!RB_TYPE_P(TOPN(<%= i %>), T_MOVED));
|
2018-07-19 09:25:22 -04:00
|
|
|
% end
|
|
|
|
% end
|
2018-09-14 03:44:44 -04:00
|
|
|
if (leaf) ADD_PC(INSN_ATTR(width));
|
2018-01-29 01:47:05 -05:00
|
|
|
# undef INSN_ATTR
|
2019-01-25 09:09:10 -05:00
|
|
|
|
|
|
|
/* ### Leave the instruction. ### */
|
|
|
|
END_INSN(<%= insn.name %>);
|
2018-01-12 03:38:09 -05:00
|
|
|
}
|