2018-01-12 03:38:09 -05:00
|
|
|
#! /your/favourite/path/to/ruby
|
|
|
|
# -*- mode: ruby; coding: utf-8; indent-tabs-mode: nil; ruby-indent-level: 2 -*-
|
|
|
|
# -*- 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'
|
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
module RubyVM::Insns2VM
|
|
|
|
def self.router argv
|
|
|
|
options = { destdir: Dir.getwd }
|
|
|
|
targets = generate_parser(options).parse argv
|
|
|
|
return targets.map do |i|
|
|
|
|
next ApplicationController.new.generate i, options[:destdir]
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
end
|
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
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
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-L", "--vpath=SPEC", <<-'end'
|
|
|
|
Likewise, this option is no longer supported.
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
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
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-Dname", "--enable=name[,name...]", Array, <<-'end'
|
2018-01-26 21:14:20 -05:00
|
|
|
This option was used to override VM option that is defined in
|
2018-01-26 21:14:20 -05:00
|
|
|
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
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-Uname", "--disable=name[,name...]", Array, <<-'end'
|
2018-01-26 21:14:20 -05:00
|
|
|
This option was used to override VM option that is defined in
|
2018-01-26 21:14:20 -05:00
|
|
|
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
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-i", "--insnsdef=FILE", "--instructions-def", <<-'end'
|
2018-01-26 21:14:20 -05:00
|
|
|
This option was used to specify alternative path to insns.def. For
|
2018-01-26 21:14:20 -05:00
|
|
|
the same reason to ignore -I, we no longer support this.
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-o", "--opt-operanddef=FILE", "--opt-operand-def", <<-'end'
|
2018-01-26 21:14:20 -05:00
|
|
|
This option was used to specify alternative path to opt_operand.def.
|
2018-01-26 21:14:20 -05:00
|
|
|
For the same reason to ignore -I, we no longer support this.
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-u", "--opt-insnunifdef=FILE", "--opt-insn-unif-def", <<-'end'
|
2018-01-26 21:14:20 -05:00
|
|
|
This option was used to specify alternative path to
|
2018-01-26 21:14:20 -05:00
|
|
|
opt_insn_unif.def. For the same reason to ignore -I, we no
|
|
|
|
longer support this.
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
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
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
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
|
2018-04-06 16:50:28 -04:00
|
|
|
raise "directory was not found in '#{dir}'" unless Dir.exist?(dir)
|
2018-01-26 21:14:20 -05:00
|
|
|
options[:destdir] = dir
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
|
2018-01-26 21:14:20 -05:00
|
|
|
this.on "-V", "--[no-]verbose", <<-'end'
|
|
|
|
Please let us ignore this and be modest.
|
|
|
|
end
|
2018-01-12 03:38:09 -05:00
|
|
|
end
|
|
|
|
end
|
2018-01-26 21:14:20 -05:00
|
|
|
private_class_method :generate_parser
|
2018-01-12 03:38:09 -05:00
|
|
|
end
|