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

ruby-changes:73603

From: Takashi <ko1@a...>
Date: Sun, 18 Sep 2022 14:40:53 +0900 (JST)
Subject: [ruby-changes:73603] a988fe0b3e (master): Introduce --basedir to insns2vm.rb

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

From a988fe0b3e4cd5a3955706affdc1f498ff9b5d77 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sun, 18 Sep 2022 14:22:35 +0900
Subject: Introduce --basedir to insns2vm.rb

and leverage that to preserve the directory structure under tool/ruby_vm/views
---
 template/Makefile.in                               |  4 +--
 tool/ruby_vm/controllers/application_controller.rb |  5 +--
 tool/ruby_vm/helpers/dumper.rb                     |  5 +--
 tool/ruby_vm/scripts/insns2vm.rb                   | 12 +++++--
 tool/ruby_vm/views/instruction.rb.erb              | 40 ----------------------
 tool/ruby_vm/views/lib/mjit/instruction.rb.erb     | 40 ++++++++++++++++++++++
 6 files changed, 58 insertions(+), 48 deletions(-)
 delete mode 100644 tool/ruby_vm/views/instruction.rb.erb
 create mode 100644 tool/ruby_vm/views/lib/mjit/instruction.rb.erb

diff --git a/template/Makefile.in b/template/Makefile.in
index 06878d552f..7e12efabb7 100644
--- a/template/Makefile.in
+++ b/template/Makefile.in
@@ -505,9 +505,9 @@ clean-local:: https://github.com/ruby/ruby/blob/trunk/template/Makefile.in#L505
 	-$(Q) $(RMDIRS) $(MJIT_HEADER_INSTALL_DIR) $(MJIT_HEADER_BUILD_DIR) $(TIMESTAMPDIR) 2> $(NULL) || $(NULLCMD)
 
 main: $(srcdir)/lib/mjit/instruction.rb
-$(srcdir)/lib/mjit/instruction.rb: $(tooldir)/ruby_vm/views/instruction.rb.erb $(srcdir)/insns.def
+$(srcdir)/lib/mjit/instruction.rb: $(tooldir)/ruby_vm/views/lib/mjit/instruction.rb.erb $(srcdir)/insns.def
 	$(ECHO) generating $@
-	$(Q) $(BASERUBY) -Ku $(tooldir)/insns2vm.rb $(INSNS2VMOPT) $@
+	$(Q) $(BASERUBY) -Ku $(tooldir)/insns2vm.rb --basedir="$(srcdir)" $(INSNS2VMOPT) $@
 
 # DTrace static library hacks described here:
 # https://marc.info/?l=opensolaris-dtrace-discuss&m=114761203110734&w=4
diff --git a/tool/ruby_vm/controllers/application_controller.rb b/tool/ruby_vm/controllers/application_controller.rb
index 25c10947ed..e03e54e397 100644
--- a/tool/ruby_vm/controllers/application_controller.rb
+++ b/tool/ruby_vm/controllers/application_controller.rb
@@ -16,10 +16,11 @@ require_relative '../models/typemap' https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/controllers/application_controller.rb#L16
 require_relative '../loaders/vm_opts_h'
 
 class ApplicationController
-  def generate i, destdir
+  def generate i, destdir, basedir
     path = Pathname.new i
     dst = destdir ? Pathname.new(destdir).join(i) : Pathname.new(i)
-    dumper = RubyVM::Dumper.new dst
+    base = basedir ? Pathname.new(basedir) : Pathname.pwd
+    dumper = RubyVM::Dumper.new dst, base.expand_path
     return [path, dumper]
   end
 end
diff --git a/tool/ruby_vm/helpers/dumper.rb b/tool/ruby_vm/helpers/dumper.rb
index 7aec9c7631..c8a65e0650 100644
--- a/tool/ruby_vm/helpers/dumper.rb
+++ b/tool/ruby_vm/helpers/dumper.rb
@@ -28,7 +28,7 @@ class RubyVM::Dumper https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/helpers/dumper.rb#L28
     path  = Pathname.new(__FILE__)
     path  = (path.relative_path_from(Pathname.pwd) rescue path).dirname
     path += '../views'
-    path += File.basename(spec)
+    path += Pathname.pwd.join(spec).to_s.sub("#{@base}/", '')
     src   = path.read mode: 'rt:utf-8:utf-8'
   rescue Errno::ENOENT
     raise "don't know how to generate #{path}"
@@ -85,10 +85,11 @@ class RubyVM::Dumper https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/helpers/dumper.rb#L85
       . join
   end
 
-  def initialize dst
+  def initialize dst, base
     @erb   = {}
     @empty = new_binding
     @file  = cstr dst.to_path
+    @base  = base
   end
 
   def render partial, opts = { :locals => {} }
diff --git a/tool/ruby_vm/scripts/insns2vm.rb b/tool/ruby_vm/scripts/insns2vm.rb
index 8325dd364f..47d8da5513 100644
--- a/tool/ruby_vm/scripts/insns2vm.rb
+++ b/tool/ruby_vm/scripts/insns2vm.rb
@@ -15,10 +15,10 @@ require_relative '../controllers/application_controller.rb' https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/scripts/insns2vm.rb#L15
 
 module RubyVM::Insns2VM
   def self.router argv
-    options = { destdir: nil }
+    options = { destdir: nil, basedir: nil }
     targets = generate_parser(options).parse argv
     return targets.map do |i|
-      next ApplicationController.new.generate i, options[:destdir]
+      next ApplicationController.new.generate i, options[:destdir], options[:basedir]
     end
   end
 
@@ -84,6 +84,14 @@ module RubyVM::Insns2VM https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/scripts/insns2vm.rb#L84
         options[:destdir] = dir
       end
 
+      this.on "--basedir=DIR", <<-'begin' do |dir|
+        Change the base directory from the current working directory
+        to the given path. Used for searching the source template.
+      begin
+        raise "directory was not found in '#{dir}'" unless Dir.exist?(dir)
+        options[:basedir] = dir
+      end
+
       this.on "-V", "--[no-]verbose", <<-'end'
         Please let us ignore this and be modest.
       end
diff --git a/tool/ruby_vm/views/instruction.rb.erb b/tool/ruby_vm/views/instruction.rb.erb
deleted file mode 100644
index 1c462de53a..0000000000
--- a/tool/ruby_vm/views/instruction.rb.erb
+++ /dev/null
@@ -1,40 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/scripts/insns2vm.rb#L0
-module RubyVM::MJIT
-  Instruction = Struct.new(
-    :name,
-    :bin,
-    :len,
-    :expr,
-    :declarations,
-    :preamble,
-    :opes,
-    :pops,
-    :rets,
-    :always_leaf?,
-    :leaf_without_check_ints?,
-    :handles_sp?,
-  )
-
-  INSNS = {
-% RubyVM::Instructions.each_with_index do |insn, i|
-%   next if insn.name.start_with?('trace_')
-    <%= i %> => Instruction.new(
-      name: :<%= insn.name %>,
-      bin: <%= i %>, # BIN(<%= insn.name %>)
-      len: <%= insn.width %>, # insn_len
-      expr: <<-EXPR,
-<%= insn.expr.expr.dump.sub(/\A"/, '').sub(/"\z/, '').gsub(/\\n/, "\n").gsub(/\\t/, ' ' * 8) %>
-      EXPR
-      declarations: <%= insn.declarations.inspect %>,
-      preamble: <%= insn.preamble.map(&:expr).inspect %>,
-      opes: <%= insn.opes.inspect %>,
-      pops: <%= insn.pops.inspect %>,
-      rets: <%= insn.rets.inspect %>,
-      always_leaf?: <%= insn.always_leaf? %>,
-      leaf_without_check_ints?: <%= insn.leaf_without_check_ints? %>,
-      handles_sp?: <%= insn.handles_sp? %>,
-    ),
-% end
-  }
-
-  private_constant(*constants)
-end if RubyVM::MJIT.enabled?
diff --git a/tool/ruby_vm/views/lib/mjit/instruction.rb.erb b/tool/ruby_vm/views/lib/mjit/instruction.rb.erb
new file mode 100644
index 0000000000..1c462de53a
--- /dev/null
+++ b/tool/ruby_vm/views/lib/mjit/instruction.rb.erb
@@ -0,0 +1,40 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/lib/mjit/instruction.rb.erb#L1
+module RubyVM::MJIT
+  Instruction = Struct.new(
+    :name,
+    :bin,
+    :len,
+    :expr,
+    :declarations,
+    :preamble,
+    :opes,
+    :pops,
+    :rets,
+    :always_leaf?,
+    :leaf_without_check_ints?,
+    :handles_sp?,
+  )
+
+  INSNS = {
+% RubyVM::Instructions.each_with_index do |insn, i|
+%   next if insn.name.start_with?('trace_')
+    <%= i %> => Instruction.new(
+      name: :<%= insn.name %>,
+      bin: <%= i %>, # BIN(<%= insn.name %>)
+      len: <%= insn.width %>, # insn_len
+      expr: <<-EXPR,
+<%= insn.expr.expr.dump.sub(/\A"/, '').sub(/"\z/, '').gsub(/\\n/, "\n").gsub(/\\t/, ' ' * 8) %>
+      EXPR
+      declarations: <%= insn.declarations.inspect %>,
+      preamble: <%= insn.preamble.map(&:expr).inspect %>,
+      opes: <%= insn.opes.inspect %>,
+      pops: <%= insn.pops.inspect %>,
+      rets: <%= insn.rets.inspect %>,
+      always_leaf?: <%= insn.always_leaf? %>,
+      leaf_without_check_ints?: <%= insn.leaf_without_check_ints? %>,
+      handles_sp?: <%= insn.handles_sp? %>,
+    ),
+% end
+  }
+
+  private_constant(*constants)
+end if RubyVM::MJIT.enabled?
-- 
cgit v1.2.1


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

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