From e43fec9a6f053ea28821bed25fe66f75eec6e08b Mon Sep 17 00:00:00 2001 From: shyouhei Date: Tue, 9 Jan 2018 13:30:34 +0000 Subject: insns_info.inc: position independent * template/insns_info.inc.tmpl (insn_name_info): make position independent for large strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/ruby_vm/views/_insn_name_info.erb | 32 +++++++++++++++++++++---------- tool/ruby_vm/views/_insn_operand_info.erb | 31 ++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 20 deletions(-) (limited to 'tool/ruby_vm') diff --git a/tool/ruby_vm/views/_insn_name_info.erb b/tool/ruby_vm/views/_insn_name_info.erb index da65632a28..c8c305e556 100644 --- a/tool/ruby_vm/views/_insn_name_info.erb +++ b/tool/ruby_vm/views/_insn_name_info.erb @@ -5,26 +5,38 @@ %# 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. +% +% a = RubyVM::Instructions.map {|i| i.name } +% b = (0...a.size) +% c = a.inject([0]) {|r, i| r << (r[-1] + i.length + 1) } +% c.pop +% CONSTFUNC(MAYBE_UNUSED(static const char *insn_name(VALUE insn))); const char * insn_name(VALUE i) { static const unsigned short o[] = { -% a = RubyVM::Instructions.map {|i| i.name } -% o = 0 -% a.each_slice 12 do |b| - <%= b.map {|i| - j = o; o += i.size + 1; sprintf("%4d", j) - }.join(', ') %>, +% c.each_slice 12 do |d| + <%= d.map {|i| sprintf("%4d", i) }.join(', ') %>, % end }; - static const char t[] = { -% a.each_slice 2 do |b| - <%= b.map {|i| sprintf("%-30s", cstr(i)) }.join(' "\0" ') %> "\0" + + PACKED_STRUCT(static const struct { +% b.each_slice 3 do |d| + <%= d.map {|i| + sprintf("const char L%03d[%2d]", i, a[i].length + 1) + }.join('; ') %>; +% end + + }) t = { +% a.each_slice 2 do |d| + <%= d.map {|i| sprintf("%-30s", cstr(i)) }.join(', ') %>, % end }; ASSERT_VM_INSTRUCTION_SIZE(o); - return &t[o[i]]; + static const char *p = (const char *)&t; + + return &p[o[i]]; } diff --git a/tool/ruby_vm/views/_insn_operand_info.erb b/tool/ruby_vm/views/_insn_operand_info.erb index 8e848ea915..688c466eda 100644 --- a/tool/ruby_vm/views/_insn_operand_info.erb +++ b/tool/ruby_vm/views/_insn_operand_info.erb @@ -5,6 +5,12 @@ %# 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. +% +% a = RubyVM::Instructions.map {|i| i.operands_info } +% b = (0...a.size) +% c = a.inject([0]) {|r, i| r << (r[-1] + i.length + 1) } +% c.pop +% MAYBE_UNUSED(static const char *insn_op_types(VALUE insn)); MAYBE_UNUSED(static int insn_op_type(VALUE insn, long pos)); @@ -12,23 +18,28 @@ const char * insn_op_types(VALUE i) { static const unsigned short o[] = { -% a = RubyVM::Instructions.map {|i| i.operands_info } -% o = 0 -% a.each_slice 14 do |b| - <%= b.map {|i| - j = o; o += i.size + 1; sprintf("%3d", j) - }.join(', ') %>, +% c.each_slice 14 do |d| + <%= d.map {|i| sprintf("%3d", i) }.join(', ') %>, % end }; - static const char t[] = { -% a.each_slice 6 do |b| - <%= b.map {|i| sprintf("%-6s", cstr(i)) }.join(' "\0" ') %> "\0" + + PACKED_STRUCT(static const struct { +% b.each_slice 3 do |d| + <%= d.map {|i| + sprintf("const char L%03d[%2d]", i, a[i].length + 1) + }.join('; ') %>; +% end + + }) t = { +% a.each_slice 8 do |d| + <%= d.map {|i| sprintf("%-6s", cstr(i)) }.join(', ') %>, % end }; ASSERT_VM_INSTRUCTION_SIZE(o); + static const char *p = (const char *)&t; - return &t[o[i]]; + return &p[o[i]]; } int -- cgit v1.2.3