diff options
| author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-31 15:02:22 +0000 |
|---|---|---|
| committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-31 15:02:22 +0000 |
| commit | 4ef881bd15c9c4e2e9b20da2c091e80d4d530119 (patch) | |
| tree | 7b725552a9a4ded93849ca2faab1b257f7761790 /tool/compile.rb | |
| parent | 182520b0acc5eea4da52bc8734dc5e3280ce5f94 (diff) | |
| download | ruby-4ef881bd15c9c4e2e9b20da2c091e80d4d530119.tar.gz ruby-4ef881bd15c9c4e2e9b20da2c091e80d4d530119.tar.xz ruby-4ef881bd15c9c4e2e9b20da2c091e80d4d530119.zip | |
* Merge YARV
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/compile.rb')
| -rw-r--r-- | tool/compile.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tool/compile.rb b/tool/compile.rb new file mode 100644 index 000000000..5798b8113 --- /dev/null +++ b/tool/compile.rb @@ -0,0 +1,67 @@ +require 'optparse' +require 'pp' + +OutputCompileOption = { + # enable + :peephole_optimization =>true, + :inline_const_cache =>true, + + # disable + :specialized_instruction =>false, + :operands_unification =>false, + :instructions_unification =>false, + :stack_caching =>false, +} + +def compile_to_rb infile, outfile + iseq = YARVCore::InstructionSequence.compile_file(infile, OutputCompileOption) + + open(outfile, 'w'){|f| + f.puts "YARVCore::InstructionSequence.load(" + + "Marshal.load(<<EOS____.unpack('m*')[0])).eval" + f.puts [Marshal.dump(iseq.to_a)].pack('m*') + f.puts "EOS____" + } +end + +def compile_to_rbc infile, outfile, type + iseq = YARVCore::InstructionSequence.compile_file(infile, OutputCompileOption) + + case type + when 'm' + open(outfile, 'wb'){|f| + f.print "RBCM" + f.puts Marshal.dump(iseq.to_a, f) + } + else + raise "Unsupported compile type: #{type}" + end +end + +## main + +outfile = 'a.rb' +type = 'm' +opt = OptionParser.new{|opt| + opt.on('-o file'){|o| + outfile = o + } + opt.on('-t type', '--type type'){|o| + type = o + } + opt.version = '0.0.1' +} + +opt.parse!(ARGV) + +ARGV.each{|file| + case outfile + when /\.rb\Z/ + compile_to_rb file, outfile + when /\.rbc\Z/ + compile_to_rbc file, outfile, type + else + raise + end +} + |
