summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-22 04:22:01 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-22 04:22:01 (GMT)
commit7735c1f5fe4eabd97fe63d7113fc12fc25c877b7 (patch)
treedc9ac4c3d0307bfd6c5427f359070c433eb40e40 /template
parent1f89414c20edbe0b36fac7351917f401ccee63a1 (diff)
tool/instruction.rb: move logics to templates
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'template')
-rw-r--r--template/insns.inc.tmpl6
-rw-r--r--template/insns_info.inc.tmpl58
-rw-r--r--template/minsns.inc.tmpl6
-rw-r--r--template/optinsn.inc.tmpl44
-rw-r--r--template/optunifs.inc.tmpl37
-rw-r--r--template/vm.inc.tmpl16
-rw-r--r--template/vmtc.inc.tmpl4
7 files changed, 124 insertions, 47 deletions
diff --git a/template/insns.inc.tmpl b/template/insns.inc.tmpl
index 13b6cb9..112732d 100644
--- a/template/insns.inc.tmpl
+++ b/template/insns.inc.tmpl
@@ -14,8 +14,10 @@
#define BIN(n) YARVINSN_##n
enum ruby_vminsn_type {
-<%= insns %>
- VM_INSTRUCTION_SIZE = <%= @insns.size %>
+% @insns.each do |insn|
+ BIN(<%=insn.name%>),
+% end
+ VM_INSTRUCTION_SIZE
};
#define ASSERT_VM_INSTRUCTION_SIZE(array) \
diff --git a/template/insns_info.inc.tmpl b/template/insns_info.inc.tmpl
index c7f0094..ffbe518 100644
--- a/template/insns_info.inc.tmpl
+++ b/template/insns_info.inc.tmpl
@@ -9,29 +9,39 @@
or tool/insns2vm.rb
*/
-<%= insn_type_chars %>
+% TYPE_CHARS.each do |t, c|
+#define <%=t%> '<%=c%>'
+% end
static const char *const insn_name_info[] = {
-<%= insn_names %>
+% @insns.each do |insn|
+ "<%= insn.name %>",
+% end
};
ASSERT_VM_INSTRUCTION_SIZE(insn_name_info);
static const char *const insn_operand_info[] = {
-<%= operands_info %>
+% @insns.each do |insn|
+ "<% insn.opes.each {|type, _| %><%=TYPE_CHARS.fetch(op2typesig(type))%><%}%>",
+% end
};
ASSERT_VM_INSTRUCTION_SIZE(insn_operand_info);
static const int insn_len_info[] = {
-<%= operands_num_info %>
+% @insns.each do |insn|
+ <%= insn.opes.size + 1 %>,
+% end
};
ASSERT_VM_INSTRUCTION_SIZE(insn_len_info);
#ifdef USE_INSN_RET_NUM
static const int insn_stack_push_num_info[] = {
-<%= stack_num_info %>
+% @insns.each do |insn|
+ <%= insn.rets.size %>,
+% end
};
ASSERT_VM_INSTRUCTION_SIZE(insn_stack_push_num_info);
@@ -41,12 +51,16 @@ ASSERT_VM_INSTRUCTION_SIZE(insn_stack_push_num_info);
static int
insn_stack_increase(int depth, int insn, VALUE *opes)
{
- switch(insn){
-<%= stack_increase %>
- default:
- rb_bug("insn_sp_increase: unreachable");
- }
- return 0;
+ switch (insn) {
+% @insns.each do |insn|
+ case BIN(<%= insn.name %>): {
+ <%= insn.sp_increase_c_expr %>
+ }
+% end
+ default:
+ rb_bug("insn_sp_increase: unreachable");
+ }
+ return 0;
}
#endif
@@ -55,37 +69,37 @@ insn_stack_increase(int depth, int insn, VALUE *opes)
static int
insn_len(VALUE insn)
{
- return insn_len_info[(int)insn];
+ return insn_len_info[(int)insn];
}
static const char *
insn_name(VALUE insn)
{
- return insn_name_info[(int)insn];
+ return insn_name_info[(int)insn];
}
static const char *
insn_op_types(VALUE insn)
{
- return insn_operand_info[(int)insn];
+ return insn_operand_info[(int)insn];
}
static int
insn_op_type(VALUE insn, long pos)
{
- int len = insn_len(insn) - 1;
- if(pos < len){
- return insn_operand_info[(int)insn][pos];
- }
- else{
- return 0;
- }
+ int len = insn_len(insn) - 1;
+ if (pos < len) {
+ return insn_operand_info[(int)insn][pos];
+ }
+ else{
+ return 0;
+ }
}
#ifdef USE_INSN_RET_NUM
static int
insn_ret_num(VALUE insn)
{
- return insn_stack_push_num_info[(int)insn];
+ return insn_stack_push_num_info[(int)insn];
}
#endif
diff --git a/template/minsns.inc.tmpl b/template/minsns.inc.tmpl
index 54b1928..f32b28c 100644
--- a/template/minsns.inc.tmpl
+++ b/template/minsns.inc.tmpl
@@ -9,6 +9,6 @@
or tool/insns2vm.rb
*/
-<%= defs %>
-
-
+% @insns.each_with_index do |insn, i|
+ rb_define_const(mYarvInsns, "I<%=insn.name%>", INT2FIX(<%=i%>));
+% end
diff --git a/template/optinsn.inc.tmpl b/template/optinsn.inc.tmpl
index 3c4f732..186ec46 100644
--- a/template/optinsn.inc.tmpl
+++ b/template/optinsn.inc.tmpl
@@ -13,18 +13,42 @@
*/
static INSN *
-insn_operands_unification(INSN *insnobj){
+insn_operands_unification(INSN *insnobj)
+{
#ifdef OPT_OPERANDS_UNIFICATION
- /* optimize rule */
- switch(insnobj->insn_id){
+ /* optimize rule */
+ switch(insnobj->insn_id){
+% opt_insns_map.each do |originsn, optinsns|
+ case BIN(<%=originsn.name%>):
+% optinsns.each {|opti|
+ if (
+% opti.defopes.each_with_index {|opinfo, i|
+% next if opinfo[1] == '*'
+ insnobj->operands[<%=i%>] == <%=val_as_type(opinfo)%> &&
+% }
+ 1) {
+% idx = 0
+% opti.defopes.each_with_index {|opinfo, n|
+% if opinfo[1] == '*'
+% if idx != n
+ insnobj->operands[<%=idx%>] = insnobj->operands[<%=n%>];
+% end
+% idx += 1
+% end
+% }
+ insnobj->insn_id = BIN(<%=opti.name%>);
+ insnobj->operand_size = <%=idx%>;
+ break;
+ }
+% }
+ break;
+% end
-<%= rule %>
-
- default:
- /* do nothing */;
- break;
- }
+ default:
+ /* do nothing */;
+ break;
+ }
#endif
- return insnobj;
+ return insnobj;
}
diff --git a/template/optunifs.inc.tmpl b/template/optunifs.inc.tmpl
index 63ac4d8..3ac5872 100644
--- a/template/optunifs.inc.tmpl
+++ b/template/optunifs.inc.tmpl
@@ -27,9 +27,40 @@
UNIFIED_insn_nameB, ...};
*/
-<%= unif_insns_each %>
-<%= unif_insns %>
-<%= unif_insns_data %>
+% unif_insns_data = @insns.find_all {|insn| !insn.is_sc}.map do |insn|
+% size = insn.unifs.size
+% if size > 0
+% name = "UNIFIED_#{insn.name}"
+% insn.unifs.sort_by{|unif| -unif[1].size}.each_with_index do |(uni_insn, uni_insns), i|
+% uni_insns = uni_insns[1..-1]
+static const int <%=name%>_<%=i%>[] = {
+ BIN(<%=uni_insn.name%>), <%=uni_insns.size + 2%>,
+ <% uni_insns.map{|e| -%>
+BIN(<%=e.name%>),<% -%>
+% }
+
+};
+% end
+
+static const int *const <%=name%>[] = {(int *)<%=size+1%>,
+% size.times do |e|
+ <%=name%>_<%=e%>,
+% end
+};
+% name
+% end
+% end
+
+static const int *const *const unified_insns_data[] = {<%#-%>
+% unif_insns_data.each_with_index do |insn, i|
+% if (i%8).zero?
+
+ <% -%>
+% end
+ <%=insn || "0"%>,<%#-%>
+% end
+
+};
#undef GET_INSN_NAME
diff --git a/template/vm.inc.tmpl b/template/vm.inc.tmpl
index 11c6d1b..14b6ba3 100644
--- a/template/vm.inc.tmpl
+++ b/template/vm.inc.tmpl
@@ -11,19 +11,23 @@
If you want to fix something, you must edit 'insns.def'
*/
-<%=
-line = 15
-vm_body.gsub(/\n|__CURRENT_LINE__|__CURRENT_FILE__/){
- e = $&
+
+% line = _erbout.count("\n") + 1
+% @insns.each do |insn|
+<%
+line += 1
+make_insn_def(insn).split(/(__CURRENT_LINE__|__CURRENT_FILE__)/).each {|e|
+ %><%=
case e
when '__CURRENT_LINE__'
line.to_s
when '__CURRENT_FILE__'
"vm.inc"
else
- line += 1
+ line += e.count("\n")
e
end
+ %><%
}
%>
-
+% end
diff --git a/template/vmtc.inc.tmpl b/template/vmtc.inc.tmpl
index 3d9935d..3c31311 100644
--- a/template/vmtc.inc.tmpl
+++ b/template/vmtc.inc.tmpl
@@ -13,7 +13,9 @@
*/
static const void *const insns_address_table[] = {
-<%= insns_table %>
+% @insns.each do |insn|
+ LABEL_PTR(<%=insn.name%>),
+% end
};
ASSERT_VM_INSTRUCTION_SIZE(insns_address_table);