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-07-30 21:36:05 -04:00
|
|
|
PUREFUNC(MAYBE_UNUSED(static int comptime_insn_stack_increase(int depth, int insn, const VALUE *opes)));
|
|
|
|
PUREFUNC(static rb_snum_t comptime_insn_stack_increase_dispatch(enum ruby_vminsn_type insn, const VALUE *opes));
|
2018-01-12 03:38:09 -05:00
|
|
|
|
|
|
|
rb_snum_t
|
2019-07-30 21:36:05 -04:00
|
|
|
comptime_insn_stack_increase_dispatch(enum ruby_vminsn_type insn, const VALUE *opes)
|
2018-01-12 03:38:09 -05:00
|
|
|
{
|
|
|
|
static const signed char t[] = {
|
|
|
|
% RubyVM::Instructions.each_slice 8 do |a|
|
|
|
|
<%= a.map { |i|
|
|
|
|
if i.has_attribute?('sp_inc')
|
|
|
|
'-127'
|
|
|
|
else
|
|
|
|
sprintf("%4d", i.rets.size - i.pops.size)
|
|
|
|
end
|
|
|
|
}.join(', ') -%>,
|
|
|
|
% end
|
|
|
|
};
|
2018-01-12 08:14:53 -05:00
|
|
|
signed char c = t[insn];
|
2018-01-12 03:38:09 -05:00
|
|
|
|
|
|
|
ASSERT_VM_INSTRUCTION_SIZE(t);
|
|
|
|
if (c != -127) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
else switch(insn) {
|
|
|
|
default:
|
|
|
|
UNREACHABLE;
|
|
|
|
% RubyVM::Instructions.each do |i|
|
|
|
|
% next unless i.has_attribute?('sp_inc')
|
2019-07-30 21:36:05 -04:00
|
|
|
% attr_function =
|
|
|
|
% if i.has_attribute?('comptime_sp_inc')
|
|
|
|
% "attr_comptime_sp_inc_#{i.name}"
|
|
|
|
% else
|
|
|
|
% "attr_sp_inc_#{i.name}"
|
|
|
|
% end
|
2018-01-12 03:38:09 -05:00
|
|
|
case <%= i.bin %>:
|
2019-07-30 21:36:05 -04:00
|
|
|
return <%= attr_function %>(<%=
|
2018-01-12 03:38:09 -05:00
|
|
|
i.opes.map.with_index do |v, j|
|
2019-07-30 21:36:05 -04:00
|
|
|
if v[:type] == 'CALL_DATA' && i.has_attribute?('comptime_sp_inc')
|
|
|
|
v = v.dup
|
|
|
|
v[:type] = 'CALL_INFO'
|
|
|
|
end
|
2018-01-13 05:47:33 -05:00
|
|
|
i.cast_from_VALUE v, "opes[#{j}]"
|
|
|
|
end.join(", ")
|
2018-01-12 03:38:09 -05:00
|
|
|
%>);
|
|
|
|
% end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-07-30 21:36:05 -04:00
|
|
|
comptime_insn_stack_increase(int depth, int insn, const VALUE *opes)
|
2018-01-12 03:38:09 -05:00
|
|
|
{
|
|
|
|
enum ruby_vminsn_type itype = (enum ruby_vminsn_type)insn;
|
2019-07-30 21:36:05 -04:00
|
|
|
return depth + (int)comptime_insn_stack_increase_dispatch(itype, opes);
|
2018-01-12 03:38:09 -05:00
|
|
|
}
|