ruby-changes:49620
From: shyouhei <ko1@a...>
Date: Tue, 9 Jan 2018 22:55:36 +0900 (JST)
Subject: [ruby-changes:49620] shyouhei:r61736 (trunk): insns_info.inc.tmpl: share large tablese
shyouhei 2018-01-09 22:30:35 +0900 (Tue, 09 Jan 2018) New Revision: 61736 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61736 Log: insns_info.inc.tmpl: share large tablese Modified files: trunk/tool/ruby_vm/views/_insn_len_info.erb trunk/tool/ruby_vm/views/_insn_name_info.erb trunk/tool/ruby_vm/views/_insn_operand_info.erb Index: tool/ruby_vm/views/_insn_len_info.erb =================================================================== --- tool/ruby_vm/views/_insn_len_info.erb (revision 61735) +++ tool/ruby_vm/views/_insn_len_info.erb (revision 61736) @@ -6,15 +6,18 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_len_info.erb#L6 %# conditions mentioned in the file COPYING are met. Consult the file for %# details. CONSTFUNC(MAYBE_UNUSED(static int insn_len(VALUE insn))); +extern const char rb_vm_insn_len_info[]; + +#ifdef RUBY_VM_INSNS_INFO +const char rb_vm_insn_len_info[] = { +% RubyVM::Instructions.each_slice 25 do |a| + <%= a.map(&:width).join(', ') -%>, +% end +}; +#endif int insn_len(VALUE i) { - static const char t[] = { -% RubyVM::Instructions.each_slice 16 do |a| - <%= a.map(&:width).join(', ') -%>, -% end - }; - - return t[i]; + return rb_vm_insn_len_info[i]; } Index: tool/ruby_vm/views/_insn_name_info.erb =================================================================== --- tool/ruby_vm/views/_insn_name_info.erb (revision 61735) +++ tool/ruby_vm/views/_insn_name_info.erb (revision 61736) @@ -12,31 +12,36 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_name_info.erb#L12 % c.pop % CONSTFUNC(MAYBE_UNUSED(static const char *insn_name(VALUE insn))); +extern const char *rb_vm_insn_name_info; +extern const unsigned short rb_vm_insn_name_offset[]; -const char * -insn_name(VALUE i) -{ - static const unsigned short o[] = { +#ifdef RUBY_VM_INSNS_INFO +const unsigned short rb_vm_insn_name_offset[] = { % c.each_slice 12 do |d| - <%= d.map {|i| sprintf("%4d", i) }.join(', ') %>, + <%= d.map {|i| sprintf("%4d", i) }.join(', ') %>, % end - }; +}; +ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_name_offset); - PACKED_STRUCT(static const struct { +PACKED_STRUCT(struct rb_vm_insn_name_info_tag { % b.each_slice 3 do |d| - <%= d.map {|i| - sprintf("const char L%03d[%2d]", i, a[i].length + 1) - }.join('; ') %>; + <%= d.map {|i| + sprintf("const char L%03d[%2d]", i, a[i].length + 1) + }.join('; ') %>; % end +}); - }) t = { +static const struct rb_vm_insn_name_info_tag rb_vm_insn_name_base = { % a.each_slice 2 do |d| - <%= d.map {|i| sprintf("%-30s", cstr(i)) }.join(', ') %>, + <%= d.map {|i| sprintf("%-30s", cstr(i)) }.join(', ') %>, % end - }; +}; - ASSERT_VM_INSTRUCTION_SIZE(o); - static const char *p = (const char *)&t; +const char *rb_vm_insn_name_info = (const char *)&rb_vm_insn_name_base; +#endif - return &p[o[i]]; +const char * +insn_name(VALUE i) +{ + return &rb_vm_insn_name_info[rb_vm_insn_name_offset[i]]; } Index: tool/ruby_vm/views/_insn_operand_info.erb =================================================================== --- tool/ruby_vm/views/_insn_operand_info.erb (revision 61735) +++ tool/ruby_vm/views/_insn_operand_info.erb (revision 61736) @@ -11,35 +11,40 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_operand_info.erb#L11 % 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)); +CONSTFUNC(MAYBE_UNUSED(static const char *insn_op_types(VALUE insn))); +CONSTFUNC(MAYBE_UNUSED(static int insn_op_type(VALUE insn, long pos))); +extern const char *rb_vm_insn_op_info; +extern const unsigned short rb_vm_insn_op_offset[]; -const char * -insn_op_types(VALUE i) -{ - static const unsigned short o[] = { +#ifdef RUBY_VM_INSNS_INFO +const unsigned short rb_vm_insn_op_offset[] = { % c.each_slice 14 do |d| - <%= d.map {|i| sprintf("%3d", i) }.join(', ') %>, + <%= d.map {|i| sprintf("%3d", i) }.join(', ') %>, % end - }; +}; +ASSERT_VM_INSTRUCTION_SIZE(rb_vm_insn_op_offset); - PACKED_STRUCT(static const struct { +PACKED_STRUCT(struct rb_vm_insn_op_info_tag { % b.each_slice 3 do |d| - <%= d.map {|i| - sprintf("const char L%03d[%2d]", i, a[i].length + 1) - }.join('; ') %>; + <%= d.map {|i| + sprintf("const char L%03d[%2d]", i, a[i].length + 1) + }.join('; ') %>; % end +}); - }) t = { +static const struct rb_vm_insn_op_info_tag rb_vm_insn_op_base = { % a.each_slice 8 do |d| - <%= d.map {|i| sprintf("%-6s", cstr(i)) }.join(', ') %>, + <%= d.map {|i| sprintf("%-6s", cstr(i)) }.join(', ') %>, % end - }; +}; - ASSERT_VM_INSTRUCTION_SIZE(o); - static const char *p = (const char *)&t; +const char *rb_vm_insn_op_info = (const char *)&rb_vm_insn_op_base; +#endif - return &p[o[i]]; +const char * +insn_op_types(VALUE i) +{ + return &rb_vm_insn_op_info[rb_vm_insn_op_offset[i]]; } int -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/