1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/mk_builtin_binary.rb
2019-11-08 16:37:42 +09:00

40 lines
795 B
Ruby

#
# make builtin_binary.inc file.
#
def dump_bin iseq
bin = iseq.to_binary
bin.each_byte.with_index{|b, index|
print "\n " if (index%20) == 0
print "0x#{'%02x' % b.ord}, "
}
end
ary = []
RubyVM::each_builtin{|feature, iseq|
ary << [feature, iseq]
}
$stdout = open('builtin_binary.inc', 'wb')
puts <<H
// -*- c -*-
// DO NOT MODIFY THIS FILE DIRECTLY.
// auto-generated file by #{File.basename(__FILE__)}
H
ary.each{|feature, iseq|
puts "static const unsigned char #{feature}_bin[] = {"
dump_bin(iseq)
puts "};"
}
puts "static const struct builtin_binary builtin_binary[] = {"
ary.each{|feature, iseq|
puts " {#{feature.dump}, #{feature}_bin, sizeof(#{feature}_bin)},"
}
puts " {NULL}," # dummy sentry
puts "};"
puts "#define BUILTIN_BINARY_SIZE #{ary.size}"