summaryrefslogtreecommitdiff
path: root/tool/ruby_vm/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'tool/ruby_vm/scripts')
-rw-r--r--tool/ruby_vm/scripts/converter.rb29
-rw-r--r--tool/ruby_vm/scripts/insns2vm.rb100
2 files changed, 129 insertions, 0 deletions
diff --git a/tool/ruby_vm/scripts/converter.rb b/tool/ruby_vm/scripts/converter.rb
new file mode 100644
index 0000000000..4e7c28d67b
--- /dev/null
+++ b/tool/ruby_vm/scripts/converter.rb
@@ -0,0 +1,29 @@
+# This script was needed only once when I converted the old insns.def.
+# Consider historical.
+#
+# ruby converter.rb insns.def | sponge insns.def
+
+BEGIN { $str = ARGF.read }
+END { puts $str }
+
+# deal with spaces
+$str.gsub! %r/\r\n|\r|\n|\z/, "\n"
+$str.gsub! %r/([^\t\n]*)\t/ do
+ x = $1
+ y = 8 - x.length % 8
+ next x + ' ' * y
+end
+$str.gsub! %r/\s+$/, "\n"
+
+# deal with comments
+$str.gsub! %r/@c.*?@e/m, ''
+$str.gsub! %r/@j.*?\*\//m, '*/'
+$str.gsub! %r/\n(\s*\n)+/, "\n\n"
+$str.gsub! %r/\/\*\*?\s*\n\s*/, "/* "
+$str.gsub! %r/\n\s+\*\//, " */"
+$str.gsub! %r/^(?!.*\/\*.+\*\/$)(.+?)\s*\*\//, "\\1\n */"
+
+# deal with sp_inc
+$str.gsub! %r/ \/\/ inc -= (.*)/, ' // inc += -\\1'
+$str.gsub! %r/\s+\/\/ inc \+= (.*)/, "\n// attr rb_snum_t sp_inc = \\1;"
+$str.gsub! %r/;;$/, ";"
diff --git a/tool/ruby_vm/scripts/insns2vm.rb b/tool/ruby_vm/scripts/insns2vm.rb
new file mode 100644
index 0000000000..ad8603b1a8
--- /dev/null
+++ b/tool/ruby_vm/scripts/insns2vm.rb
@@ -0,0 +1,100 @@
+# -*- Ruby -*-
+# -*- frozen_string_literal: true; -*-
+# -*- warn_indent: true; -*-
+#
+# Copyright (c) 2017 Urabe, Shyouhei. All rights reserved.
+#
+# This file is a part of the programming language Ruby. Permission is hereby
+# 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.
+
+require 'optparse'
+require_relative '../controllers/application_controller.rb'
+
+module RubyVM::Insns2VM
+ def self.router argv
+ options = { destdir: nil, basedir: nil }
+ targets = generate_parser(options).parse argv
+ return targets.map do |i|
+ next ApplicationController.new.generate i, options[:destdir], options[:basedir]
+ end
+ end
+
+ def self.generate_parser(options)
+ OptionParser.new do |this|
+ this.on "-I", "--srcdir=DIR", <<-'end'
+ Historically this option has been passed to the script. This is
+ supposedly because at the beginning the script was placed
+ outside of the ruby source tree. Decades passed since the merge
+ of YARV, now I can safely assume this feature is obsolescent.
+ Just ignore the passed value here.
+ end
+
+ this.on "-L", "--vpath=SPEC", <<-'end'
+ Likewise, this option is no longer supported.
+ end
+
+ this.on "--path-separator=SEP", /\A(?:\W\z|\.(\W).+)/, <<-'end'
+ Old script says this option is a "separator for vpath". I am
+ confident we no longer need this option.
+ end
+
+ this.on "-Dname", "--enable=name[,name...]", Array, <<-'end'
+ This option was used to override VM option that is defined in
+ vm_opts.h. Now it is officially unsupported because vm_opts.h to
+ remain mismatched with this option must break things. Just edit
+ vm_opts.h directly.
+ end
+
+ this.on "-Uname", "--disable=name[,name...]", Array, <<-'end'
+ This option was used to override VM option that is defined in
+ vm_opts.h. Now it is officially unsupported because vm_opts.h to
+ remain mismatched with this option must break things. Just edit
+ vm_opts.h directly.
+ end
+
+ this.on "-i", "--insnsdef=FILE", "--instructions-def", <<-'end'
+ This option was used to specify alternative path to insns.def. For
+ the same reason to ignore -I, we no longer support this.
+ end
+
+ this.on "-o", "--opt-operanddef=FILE", "--opt-operand-def", <<-'end'
+ This option was used to specify alternative path to opt_operand.def.
+ For the same reason to ignore -I, we no longer support this.
+ end
+
+ this.on "-u", "--opt-insnunifdef=FILE", "--opt-insn-unif-def", <<-'end'
+ This option was used to specify alternative path to
+ opt_insn_unif.def. For the same reason to ignore -I, we no
+ longer support this.
+ end
+
+ this.on "-C", "--[no-]use-const", <<-'end'
+ We use const whenever possible now so this option is ignored.
+ The author believes that C compilers can constant-fold.
+ end
+
+ this.on "-d", "--destdir", "--output-directory=DIR", <<-'begin' do |dir|
+ THIS IS THE ONLY OPTION THAT WORKS today. Change destination
+ directory from the current working directory to the given path.
+ begin
+ raise "directory was not found in '#{dir}'" unless Dir.exist?(dir)
+ 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
+ end
+ end
+ private_class_method :generate_parser
+end