1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* Merge YARV

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2006-12-31 15:02:22 +00:00
parent 3e7566d8fb
commit a3e1b1ce7e
233 changed files with 46004 additions and 13653 deletions

51
tool/asm_parse.rb Normal file
View file

@ -0,0 +1,51 @@
stat = {}
while line = ARGF.gets
if /\[start\] (\w+)/ =~ line
name = $1
puts '--------------------------------------------------------------'
puts line
size = 0
len = 0
while line = ARGF.gets
if /\[start\] (\w+)/ =~ line
puts "\t; # length: #{len}, size: #{size}"
puts "\t; # !!"
stat[name] = [len, size]
#
name = $1
puts '--------------------------------------------------------------'
puts line
size = 0
len = 0
next
end
unless /(\ALM)|(\ALB)|(\A\.)|(\A\/)/ =~ line
puts line
if /\[length = (\d+)\]/ =~ line
len += $1.to_i
size += 1
end
end
if /__NEXT_INSN__/ !~ line && /\[end \] (\w+)/ =~ line
ename = $1
if name != ename
puts "!! start with #{name}, but end with #{ename}"
end
stat[ename] = [len, size]
puts "\t; # length: #{len}, size: #{size}"
break
end
end
end
end
stat.sort_by{|a, b| -b[0] * 1000 - a[0]}.each{|a, b|
puts "#{a}\t#{b.join("\t")}"
}
puts "total length :\t#{stat.inject(0){|r, e| r+e[1][0]}}"
puts "total size :\t#{stat.inject(0){|r, e| r+e[1][1]}}"

67
tool/compile.rb Normal file
View file

@ -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
}

161
tool/eval.rb Normal file
View file

@ -0,0 +1,161 @@
require 'rbconfig'
require 'fileutils'
require 'pp'
Ruby = ENV['RUBY'] ||
File.join(Config::CONFIG["bindir"],
Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"])
#
OPTIONS = %w{
opt-direct-threaded-code
opt-basic-operations
opt-operands-unification
opt-instructions-unification
opt-inline-method-cache
opt-stack-caching
}.map{|opt|
'--disable-' + opt
}
opts = OPTIONS.dup
Configs = OPTIONS.map{|opt|
o = opts.dup
opts.delete(opt)
o
} + [[]]
pp Configs if $DEBUG
def exec_cmd(cmd)
puts cmd
unless system(cmd)
p cmd
raise "error"
end
end
def dirname idx
"ev-#{idx}"
end
def build
Configs.each_with_index{|config, idx|
dir = dirname(idx)
FileUtils.rm_rf(dir) if FileTest.exist?(dir)
Dir.mkdir(dir)
FileUtils.cd(dir){
exec_cmd("#{Ruby} ../extconf.rb " + config.join(" "))
exec_cmd("make clean test-all")
}
}
end
def check
Configs.each_with_index{|c, idx|
puts "= #{idx}"
system("#{Ruby} -r ev-#{idx}/yarvcore -e 'puts YARVCore::OPTS'")
}
end
def bench_each idx
puts "= #{idx}"
5.times{|count|
print count
FileUtils.cd(dirname(idx)){
exec_cmd("make benchmark OPT=-y ITEMS=#{ENV['ITEMS']} > ../b#{idx}-#{count}")
}
}
puts
end
def bench
# return bench_each(6)
Configs.each_with_index{|c, idx|
bench_each idx
}
end
def parse_result data
flag = false
stat = []
data.each{|line|
if flag
if /(\w+)\t([\d\.]+)/ =~ line
stat << [$1, $2.to_f]
else
raise "not a data"
end
end
if /benchmark summary/ =~ line
flag = true
end
}
stat
end
def calc_each data
data.sort!
data.pop # remove max
data.shift # remove min
data.inject(0.0){|res, e|
res += e
} / data.size
end
def calc_stat stats
stat = []
stats[0].each_with_index{|e, idx|
bm = e[0]
vals = stats.map{|st|
st[idx][1]
}
[bm, calc_each(vals)]
}
end
def stat
total = []
Configs.each_with_index{|c, idx|
stats = []
5.times{|count|
file = "b#{idx}-#{count}"
# p file
open(file){|f|
stats << parse_result(f.read)
}
}
# merge stats
total << calc_stat(stats)
total
}
# pp total
total[0].each_with_index{|e, idx|
bm = e[0]
# print "#{bm}\t"
total.each{|st|
print st[idx][1], "\t"
}
puts
}
end
ARGV.each{|cmd|
case cmd
when 'build'
build
when 'check'
check
when 'bench'
bench
when 'stat'
stat
else
raise
end
}

13
tool/getrev.rb Normal file
View file

@ -0,0 +1,13 @@
str = ARGF.gets
if /ChangeLog (\d+)/ =~ str
puts %Q{char *rev = "#{$1}";}
else
raise
end
if /ChangeLog \d+ ([\d-]+)/ =~ str
puts %Q{char *date = "#{$1}";}
else
raise
end

1220
tool/insns2vm.rb Normal file

File diff suppressed because it is too large Load diff

62
tool/makedocs.rb Normal file
View file

@ -0,0 +1,62 @@
#!/usr/bin/env ruby
#
#
require 'rb/insns2vm.rb'
insns = insns_def_new
{ # docs
'/doc/yarvarch.ja' => :desc_ja,
'/doc/yarvarch.en' => :desc_en,
}.each{|fn, s|
fn = $srcdir + fn
p fn
open(fn, 'w'){|f|
f.puts(insns.__send__(s))
}
}
def chg ary
if ary.empty?
return '&nbsp;'
end
ary.map{|e|
if e[0] == '...'
'...'
else
e.join(' ')
end
e[1]
}.join(', ')
end
open($srcdir + '/doc/insnstbl.html', 'w'){|f|
tbl = ''
type = nil
insns.each_with_index{|insn, i|
c = insn.comm[:c]
if type != c
stype = c
type = c
end
tbl << "<tr>\n"
tbl << "<td>#{stype}</td>"
tbl << "<td>#{i}</td>"
tbl << "<td>#{insn.name}</td>"
tbl << "<td>#{chg insn.opes}</td>"
tbl << "<td>#{chg insn.pops.reverse}</td>"
tbl << "<td> =&gt; </td>"
tbl << "<td>#{chg insn.rets.reverse}</td>"
tbl << "</tr>\n"
}
f.puts ERB.new(File.read($srcdir + '/template/insnstbl.html')).result(binding)
}
begin
system('t2n.bat --tmpl doc.tmpl ../doc/yarvarch.ja > ../doc/yarvarch.ja.html')
system('t2n.bat --tmpl doc.tmpl ../doc/yarvarch.en > ../doc/yarvarch.en.html')
rescue
end

13
tool/parse.rb Normal file
View file

@ -0,0 +1,13 @@
$file = ARGV[0]
$str = ARGF.read.sub(/^__END__.*\z/m, '')
puts '# ' + '-' * 70
puts "# target program: "
puts '# ' + '-' * 70
puts $str
puts '# ' + '-' * 70
$parsed = YARVCore::InstructionSequence.compile_file($file)
puts "# disasm result: "
puts '# ' + '-' * 70
puts $parsed.disasm
puts '# ' + '-' * 70

4
tool/runruby.rb Normal file
View file

@ -0,0 +1,4 @@
require 'rbconfig'
$:.unshift File.join('.ext', Config::CONFIG['arch'])
$:.unshift '.ext'
load ARGV[0]

15
tool/vtlh.rb Normal file
View file

@ -0,0 +1,15 @@
# ARGF = open('ha')
cd = `pwd`.chomp + '/'
ARGF.each{|line|
if /^0x([a-z0-9]+),/ =~ line
stat = line.split(',')
addr = stat[0].hex + 0x00400000
retired = stat[2].to_i
ticks = stat[3].to_i
src = `addr2line -e miniruby.exe #{addr.to_s(16)}`.chomp
src.sub!(cd, '')
puts '%-40s 0x%08x %8d %8d' % [src, addr, retired, ticks]
end
}