diff options
| author | KOBAYASHI Shuji <[email protected]> | 2021-01-27 20:47:10 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2021-01-27 20:47:10 +0900 |
| commit | 3104aed8c67754f14093ea73b2df4f995e4242d3 (patch) | |
| tree | 92370cd2eae6b40a1aaccd13559eb52cdafe04f9 /lib | |
| parent | 251fd743151bb66cde3a3879d3b4b4b8c4ee7356 (diff) | |
| download | mruby-3104aed8c67754f14093ea73b2df4f995e4242d3.tar.gz mruby-3104aed8c67754f14093ea73b2df4f995e4242d3.zip | |
Split `presym_table` for reduced program size
Because a structure that is an element of `presym_table` has padding, split
it into individual arrays for name and length.
#### Result (64-bit CPU with full-core gembox)
| | mruby | libmruby.a |
|--------|------------|------------|
| Before | 1,087,444B | 1,476,872B |
| After | 1,079,340B | 1,469,784B |
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mruby/presym.rb | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/lib/mruby/presym.rb b/lib/mruby/presym.rb index 75a903dba..b00940a65 100644 --- a/lib/mruby/presym.rb +++ b/lib/mruby/presym.rb @@ -67,34 +67,53 @@ module MRuby File.binwrite(list_path, presyms.join("\n") << "\n") end - def write_header(presyms) + def write_id_header(presyms) prefix_re = Regexp.union(*SYMBOL_TO_MACRO.keys.map(&:first).uniq) suffix_re = Regexp.union(*SYMBOL_TO_MACRO.keys.map(&:last).uniq) sym_re = /\A(#{prefix_re})?([\w&&\D]\w*)(#{suffix_re})?\z/o - _pp "GEN", header_path.relative_path - mkdir_p(File.dirname(header_path)) - File.open(header_path, "w:binary") do |f| - f.puts "/* MRB_PRESYM_NAMED(lit, num, type, name) */" - f.puts "/* MRB_PRESYM_UNNAMED(lit, num) */" + _pp "GEN", id_header_path.relative_path + File.open(id_header_path, "w:binary") do |f| + f.puts "enum mruby_presym {" presyms.each.with_index(1) do |sym, num| if sym_re =~ sym && (affixes = SYMBOL_TO_MACRO[[$1, $3]]) - f.puts %|MRB_PRESYM_NAMED("#{sym}", #{num}, #{affixes * 'SYM'}, #{$2})| + f.puts " MRB_#{affixes * 'SYM'}__#{$2} = #{num}," elsif name = OPERATORS[sym] - f.puts %|MRB_PRESYM_NAMED("#{sym}", #{num}, OPSYM, #{name})| - elsif - f.puts %|MRB_PRESYM_UNNAMED("#{sym}", #{num})| + f.puts " MRB_OPSYM__#{name} = #{num}," end end + f.puts "};" + f.puts f.puts "#define MRB_PRESYM_MAX #{presyms.size}" end end + def write_table_header(presyms) + _pp "GEN", table_header_path.relative_path + File.open(table_header_path, "w:binary") do |f| + f.puts "const uint16_t presym_length_table[] = {" + presyms.each{|sym| f.puts " #{sym.bytesize},"} + f.puts "};" + f.puts + f.puts "const char * const presym_name_table[] = {" + presyms.each{|sym| f.puts %| "#{sym}",|} + f.puts "};" + end + end + def list_path @list_pat ||= "#{@build.build_dir}/presym".freeze end - def header_path - @header_path ||= "#{@build.build_dir}/include/mruby/presym.inc".freeze + def header_dir; + @header_dir ||= "#{@build.build_dir}/include/mruby/presym".freeze + end + + def id_header_path + @id_header_path ||= "#{header_dir}/id.h".freeze + end + + def table_header_path + @table_header_path ||= "#{header_dir}/table.h".freeze end private |
