[前][次][番号順一覧][スレッド一覧]

ruby-changes:49618

From: shyouhei <ko1@a...>
Date: Tue, 9 Jan 2018 22:40:36 +0900 (JST)
Subject: [ruby-changes:49618] shyouhei:r61735 (trunk): insns_info.inc: position independent

shyouhei	2018-01-09 22:30:34 +0900 (Tue, 09 Jan 2018)

  New Revision: 61735

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61735

  Log:
    insns_info.inc: position independent
    
    * template/insns_info.inc.tmpl (insn_name_info): make position
      independent for large strings.

  Modified files:
    trunk/tool/ruby_vm/views/_insn_name_info.erb
    trunk/tool/ruby_vm/views/_insn_operand_info.erb
Index: tool/ruby_vm/views/_insn_name_info.erb
===================================================================
--- tool/ruby_vm/views/_insn_name_info.erb	(revision 61734)
+++ tool/ruby_vm/views/_insn_name_info.erb	(revision 61735)
@@ -5,26 +5,38 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_name_info.erb#L5
 %# 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]];
 }
Index: tool/ruby_vm/views/_insn_operand_info.erb
===================================================================
--- tool/ruby_vm/views/_insn_operand_info.erb	(revision 61734)
+++ tool/ruby_vm/views/_insn_operand_info.erb	(revision 61735)
@@ -5,6 +5,12 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_operand_info.erb#L5
 %# 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 * https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_insn_operand_info.erb#L18
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]