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

ruby-changes:73694

From: Takashi <ko1@a...>
Date: Fri, 23 Sep 2022 06:45:07 +0900 (JST)
Subject: [ruby-changes:73694] 4e0db2f753 (master): mjit_c.rb doesn't need to be an erb

https://git.ruby-lang.org/ruby.git/commit/?id=4e0db2f753

From 4e0db2f75348fd28ae8ffd242044a020e41afef5 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sun, 18 Sep 2022 23:20:44 +0900
Subject: mjit_c.rb doesn't need to be an erb

---
 .gitignore                       |   1 -
 common.mk                        |   5 --
 mjit_c.rb                        | 137 +++++++++++++++++++++++++++++++++++++++
 tool/mjit/bindgen.rb             |   2 +-
 tool/ruby_vm/views/mjit_c.rb.erb | 137 ---------------------------------------
 5 files changed, 138 insertions(+), 144 deletions(-)
 create mode 100644 mjit_c.rb
 delete mode 100644 tool/ruby_vm/views/mjit_c.rb.erb

diff --git a/.gitignore b/.gitignore
index b7779c0ef2..4bbf24f094 100644
--- a/.gitignore
+++ b/.gitignore
@@ -235,7 +235,6 @@ lcov*.info https://github.com/ruby/ruby/blob/trunk/.gitignore#L235
 # MJIT
 /include/ruby-*/*/rb_mjit_min_header-*.h
 /lib/mjit/instruction.rb
-/mjit_c.rb
 /mjit_config.h
 /rb_mjit_header.h
 
diff --git a/common.mk b/common.mk
index ff0a2ca17f..52f132a2f8 100644
--- a/common.mk
+++ b/common.mk
@@ -239,11 +239,6 @@ $(srcdir)/lib/mjit/instruction.rb: $(tooldir)/insns2vm.rb $(tooldir)/ruby_vm/vie https://github.com/ruby/ruby/blob/trunk/common.mk#L239
 	$(ECHO) generating $@
 	$(Q) $(BASERUBY) -Ku $(tooldir)/insns2vm.rb --basedir="$(srcdir)" $(INSNS2VMOPT) $@
 
-srcs: $(srcdir)/mjit_c.rb
-$(srcdir)/mjit_c.rb: $(tooldir)/insns2vm.rb $(tooldir)/ruby_vm/views/mjit_c.rb.erb
-	$(ECHO) generating $@
-	$(Q) $(BASERUBY) -Ku $(tooldir)/insns2vm.rb --basedir="$(srcdir)" $(INSNS2VMOPT) $@
-
 mjit-headers: $(MJIT_SUPPORT)-mjit-headers
 no-mjit-headers: PHONY
 yes-mjit-headers: mjit_config.h PHONY
diff --git a/mjit_c.rb b/mjit_c.rb
new file mode 100644
index 0000000000..5def975dcc
--- /dev/null
+++ b/mjit_c.rb
@@ -0,0 +1,137 @@ https://github.com/ruby/ruby/blob/trunk/mjit_c.rb#L1
+# Part of this file is generated by tool/mjit/bindgen.rb.
+# Run `make mjit-bindgen` to update code between "MJIT bindgen begin" and "MJIT bindgen end".
+module RubyVM::MJIT
+  C = Object.new
+
+  class << C
+    def ROBJECT_EMBED_LEN_MAX
+      Primitive.cexpr! 'INT2NUM(RBIMPL_EMBED_LEN_MAX_OF(VALUE))'
+    end
+
+    def cdhash_to_hash(cdhash_addr)
+      Primitive.cdhash_to_hash(cdhash_addr)
+    end
+
+    def builtin_compiler(f, bf, index, stack_size, builtin_inline_p)
+      Primitive.builtin_compile(f, bf.to_i, index, stack_size, builtin_inline_p)
+    end
+
+    def has_cache_for_send(cc, insn)
+      Primitive.has_cache_for_send(cc.to_i, insn)
+    end
+
+    def rb_iseq_check(iseq)
+      _iseq_addr = iseq.to_i
+      iseq_addr = Primitive.cexpr! 'PTR2NUM((VALUE)rb_iseq_check((rb_iseq_t *)NUM2PTR(_iseq_addr)))'
+      rb_iseq_t.new(iseq_addr)
+    end
+
+    def rb_iseq_path(iseq)
+      _iseq_addr = iseq.to_i
+      Primitive.cexpr! 'rb_iseq_path((rb_iseq_t *)NUM2PTR(_iseq_addr))'
+    end
+
+    def vm_ci_argc(ci)
+      _ci_addr = ci.to_i
+      Primitive.cexpr! 'UINT2NUM(vm_ci_argc((CALL_INFO)NUM2PTR(_ci_addr)))'
+    end
+
+    def vm_ci_flag(ci)
+      _ci_addr = ci.to_i
+      Primitive.cexpr! 'UINT2NUM(vm_ci_flag((CALL_INFO)NUM2PTR(_ci_addr)))'
+    end
+
+    def rb_splat_or_kwargs_p(ci)
+      _ci_addr = ci.to_i
+      Primitive.cexpr! 'RBOOL(rb_splat_or_kwargs_p((CALL_INFO)NUM2PTR(_ci_addr)))'
+    end
+
+    def fastpath_applied_iseq_p(ci, cc, iseq)
+      _ci_addr = ci.to_i
+      _cc_addr = cc.to_i
+      _iseq_addr = iseq.to_i
+      Primitive.cexpr! 'RBOOL(fastpath_applied_iseq_p((CALL_INFO)NUM2PTR(_ci_addr), (CALL_CACHE)NUM2PTR(_cc_addr), (rb_iseq_t *)NUM2PTR(_iseq_addr)))'
+    end
+
+    def mjit_opts
+      addr = Primitive.cexpr! 'PTR2NUM((VALUE)&mjit_opts)'
+      mjit_options.new(addr)
+    end
+
+    def mjit_call_attribute_sp_inc(insn, operands)
+      _operands_addr = operands.to_i
+      Primitive.cexpr! 'LONG2NUM(mjit_call_attribute_sp_inc(NUM2INT(insn), (VALUE *)NUM2PTR(_operands_addr)))'
+    end
+
+    def mjit_capture_cc_entries(compiled_body, captured_body)
+      _compiled_body_addr = compiled_body.to_i
+      _captured_body_addr = captured_body.to_i
+      Primitive.cexpr! 'INT2NUM(mjit_capture_cc_entries((struct rb_iseq_constant_body *)NUM2PTR(_compiled_body_addr), (struct rb_iseq_constant_body *)NUM2PTR(_captured_body_addr)))'
+    end
+
+    #const struct rb_iseq_constant_body *body, union iseq_inline_storage_entry *is_entries
+    def mjit_capture_is_entries(body, is_entries)
+      _body_addr = body.to_i
+      _is_entries_addr = is_entries.to_i
+      Primitive.cstmt! %{
+        mjit_capture_is_entries((struct rb_iseq_constant_body *)NUM2PTR(_body_addr), (union iseq_inline_storage_entry *)NUM2PTR(_is_entries_addr));
+        return Qnil;
+      }
+    end
+
+    # Convert encoded VM pointers to insn BINs.
+    def rb_vm_insn_decode(encoded)
+      Primitive.cexpr! 'INT2NUM(rb_vm_insn_decode(NUM2PTR(encoded)))'
+    end
+
+    # Convert insn BINs to encoded VM pointers. This one is not used by the compiler, but useful for debugging.
+    def rb_vm_insn_encode(bin)
+      Primitive.cexpr! 'PTR2NUM((VALUE)rb_vm_get_insns_address_table()[NUM2INT(bin)])'
+    end
+
+    def insn_may_depend_on_sp_or_pc(insn, opes)
+      _opes_addr = opes.to_i
+      Primitive.cexpr! 'RBOOL(insn_may_depend_on_sp_or_pc(NUM2INT(insn), (VALUE *)NUM2PTR(_opes_addr)))'
+    end
+
+    # Convert Integer VALUE to an actual Ruby object
+    def to_ruby(value)
+      Primitive.cexpr! '(VALUE)NUM2PTR(value)'
+    end
+
+    # Convert RubyVM::InstructionSequence to C.rb_iseq_t. Not used by the compiler, but useful for debugging.
+    def rb_iseqw_to_iseq(iseqw)
+      iseq_addr = Primitive.cexpr! 'PTR2NUM((VALUE)rb_iseqw_to_iseq(iseqw))'
+      rb_iseq_t.new(iseq_addr)
+    end
+
+    # TODO: remove this after migration
+    def fprintf(f, str)
+      Primitive.cstmt! %{
+        fprintf((FILE *)NUM2PTR(f), "%s", RSTRING_PTR(str));
+        return Qnil;
+      }
+    end
+
+    def rb_cFalseClass; Primitive.cexpr! 'PTR2NUM(rb_cFalseClass)' end
+    def rb_cNilClass;   Primitive.cexpr! 'PTR2NUM(rb_cNilClass)'   end
+    def rb_cTrueClass;  Primitive.cexpr! 'PTR2NUM(rb_cTrueClass)'  end
+    def rb_cInteger;    Primitive.cexpr! 'PTR2NUM(rb_cInteger)'    end
+    def rb_cSymbol;     Primitive.cexpr! 'PTR2NUM(rb_cSymbol)'     end
+    def rb_cFloat;      Primitive.cexpr! 'PTR2NUM(rb_cFloat)'      end
+  end
+
+  ### MJIT bindgen begin ###
+
+  def C.NOT_COMPILED_STACK_SIZE = Primitive.cexpr! %q{ INT2NUM(NOT_COMPILED_STACK_SIZE) }
+
+  def C.USE_LAZY_LOAD = Primitive.cexpr! %q{ RBOOL(USE_LAZY_LOAD != 0) }
+
+  def C.USE_RVARGC = Primitive.cexpr! %q{ RBOOL(USE_RVARGC != 0) }
+
+  def C.VM_CALL_KW_SPLAT = Primitive.cexpr! %q{ INT2NUM(VM_CALL_KW_SPLAT) }
+
+  def C.VM_CALL_TAILCALL = Primitive.cexpr! %q{ INT2NUM(VM_CALL_TAILCALL) }
+
+  ### MJIT bindgen end ###
+end if RubyVM::MJIT.enabled?
diff --git a/tool/mjit/bindgen.rb b/tool/mjit/bindgen.rb
index 8fa20fe64c..5707019266 100755
--- a/tool/mjit/bindgen.rb
+++ b/tool/mjit/bindgen.rb
@@ -308,7 +308,7 @@ class BindingGenerator https://github.com/ruby/ruby/blob/trunk/tool/mjit/bindgen.rb#L308
 end
 
 src_dir = File.expand_path('../..', __dir__)
-src_path = File.join(src_dir, 'tool/ruby_vm/views/mjit_c.rb.erb')
+src_path = File.join(src_dir, 'mjit_c.rb')
 build_dir = File.expand_path(build_dir)
 cflags = [
   src_dir,
diff --git a/tool/ruby_vm/views/mjit_c.rb.erb b/tool/ruby_vm/views/mjit_c.rb.erb
deleted file mode 100644
index 5def975dcc..0000000000
--- a/tool/ruby_vm/views/mjit_c.rb.erb
+++ /dev/null
@@ -1,137 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/tool/mjit/bindgen.rb#L0
-# Part of this file is generated by tool/mjit/bindgen.rb.
-# Run `make mjit-bindgen` to update code between "MJIT bindgen begin" and "MJIT bindgen end".
-module RubyVM::MJIT
-  C = Object.new
-
-  class << C
-    def ROBJECT_EMBED_LEN_MAX
-      Primitive.cexpr! 'INT2NUM(RBIMPL_EMBED_LEN_MAX_OF(VALUE))'
-    end
-
-    def cdhash_to_hash(cdhash_addr)
-      Primitive.cdhash_to_hash(cdhash_addr)
-    end
-
-    def builtin_compiler(f, bf, index, stack_size, builtin_inline_p)
-      Primitive.builtin_compile(f, bf.to_i, index, stack_size, builtin_inline_p)
-    end
-
-    def has_cache_for_send(cc, insn)
-      Primitive.has_cache_for_send(cc.to_i, insn)
-    end
-
-    def rb_iseq_check(iseq)
-      _iseq_addr = iseq.to_i
-      iseq_addr = Primitive.cexpr! 'PTR2NUM((VALUE)rb_iseq_check((rb_iseq_t *)NUM2PTR(_iseq_addr)))'
-      rb_iseq_t.new(iseq_addr)
-    end
-
-    def rb_iseq_path(iseq)
-      _iseq_addr = iseq.to_i
-      Primitive.cexpr! 'rb_iseq_path((rb_iseq_t *)NUM2PTR(_iseq_addr))'
-    end
-
-    def vm_ci_argc(ci)
-      _ci_addr = ci.to_i
-      Primitive.cexpr! 'UINT2NUM(vm_ci_argc((CALL_INFO)NUM2PTR(_ci_addr)))'
-    end
-
-    def vm_ci_flag(ci)
-      _ci_addr = ci.to_i
-      Primitive.cexpr! 'UINT2NUM(vm_ci_flag((CALL_INFO)NUM2PTR(_ci_addr)))'
-    end
-
-    def rb_splat_or_kwargs_p(ci)
-      _ci_addr = ci.to_i
-      Primitive.cexpr! 'RBOOL(rb_splat_or_kwargs_p((CALL_INFO)NUM2PTR(_ci_addr)))'
-    end
-
-    def fastpath_applied_iseq_p(ci, cc, iseq)
-      _ci_addr = ci.to_i
-      _cc_addr = cc.to_i
-      _iseq_addr = iseq.to_i
-      Primitive.cexpr! 'RBOOL(fastpath_applied_iseq_p((CALL_INFO)NUM2PTR(_ci_addr), (CALL_CACHE)NUM2PTR(_cc_addr), (rb_iseq_t *)NUM2PTR(_iseq_addr)))'
-    end
-
-    def mjit_opts
-      addr = Primitive.cexpr! 'PTR2NUM((VALUE)&mjit_opts)'
-      mjit_options.new(addr)
-    end
-
-    def mjit_call_attribute_sp_inc(insn, operands)
-      _operands_addr = operands.to_i
-      Primitive.cexpr! 'LONG2NUM(mjit_call_attribute_sp_inc(NUM2INT(insn), (VALUE *)NUM2PTR(_operands_addr)))'
-    end
-
-    def mjit_capture_cc_entries(compiled_body, captured_body)
-      _compiled_body_addr = compiled_body.to_i
-      _captured_body_addr = captured_body.to_i
-      Primitive.cexpr! 'INT2NUM(mjit_capture_cc_entries((struct rb_iseq_constant_body *)NUM2PTR(_compiled_body_addr), (struct rb_iseq_constant_body *)NUM2PTR(_captured_body_addr (... truncated)

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

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