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

Reduce the number of lines used by transform_mjit_header

This commit is contained in:
Takashi Kokubun 2020-03-22 15:46:52 -07:00
parent dec0f582e4
commit a55f670757
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD

View file

@ -243,10 +243,10 @@ end
# Check initial file correctness in the manner of final output. # Check initial file correctness in the manner of final output.
MJITHeader.check_code!(code_to_check, cc, cflags, 'initial') MJITHeader.check_code!(code_to_check, cc, cflags, 'initial')
puts "\nTransforming external functions to static:"
stop_pos = -1 stop_pos = -1
extern_names = [] extern_names = []
transform_logs = Hash.new { |h, k| h[k] = [] }
# This loop changes function declarations to static inline. # This loop changes function declarations to static inline.
while (decl_range = MJITHeader.find_decl(code, stop_pos)) while (decl_range = MJITHeader.find_decl(code, stop_pos))
@ -255,7 +255,7 @@ while (decl_range = MJITHeader.find_decl(code, stop_pos))
decl_name = MJITHeader.decl_name_of(decl) decl_name = MJITHeader.decl_name_of(decl)
if MJITHeader::IGNORED_FUNCTIONS.include?(decl_name) && /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl) if MJITHeader::IGNORED_FUNCTIONS.include?(decl_name) && /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)
puts "#{PROGRAM}: changing definition of '#{decl_name}' to declaration" transform_logs[:def_to_decl] << decl_name
code[decl_range] = decl.sub(/{.+}/m, ';') code[decl_range] = decl.sub(/{.+}/m, ';')
elsif MJITHeader::ALWAYS_INLINED_FUNCTIONS.include?(decl_name) && match = /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl) elsif MJITHeader::ALWAYS_INLINED_FUNCTIONS.include?(decl_name) && match = /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)
header = match[0].sub(/{\z/, '').strip header = match[0].sub(/{\z/, '').strip
@ -265,13 +265,13 @@ while (decl_range = MJITHeader.find_decl(code, stop_pos))
elsif extern_names.include?(decl_name) && (decl =~ /#{MJITHeader::FUNC_HEADER_REGEXP};/) elsif extern_names.include?(decl_name) && (decl =~ /#{MJITHeader::FUNC_HEADER_REGEXP};/)
decl.sub!(/(extern|static|inline) /, ' ') decl.sub!(/(extern|static|inline) /, ' ')
unless decl_name =~ /\Aattr_\w+_\w+\z/ # skip too-many false-positive warnings in insns_info.inc. unless decl_name =~ /\Aattr_\w+_\w+\z/ # skip too-many false-positive warnings in insns_info.inc.
puts "#{PROGRAM}: making declaration of '#{decl_name}' static inline" transform_logs[:static_inline_decl] << decl_name
end end
code[decl_range] = "static inline #{decl}" code[decl_range] = "static inline #{decl}"
elsif (match = /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)) && (header = match[0]) !~ /static/ elsif (match = /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)) && (header = match[0]) !~ /static/
unless decl_name.match(MJITHeader::TARGET_NAME_REGEXP) unless decl_name.match(MJITHeader::TARGET_NAME_REGEXP)
puts "#{PROGRAM}: SKIPPED to transform #{decl_name}" transform_logs[:skipped] << decl_name
next next
end end
@ -279,12 +279,12 @@ while (decl_range = MJITHeader.find_decl(code, stop_pos))
decl[match.begin(0)...match.end(0)] = '' decl[match.begin(0)...match.end(0)] = ''
if decl =~ /\bstatic\b/ if decl =~ /\bstatic\b/
puts "warning: a static decl inside external definition of '#{decl_name}'" transform_logs[:static_inside_extern] << decl_name
end end
header.sub!(/(extern|inline) /, ' ') header.sub!(/(extern|inline) /, ' ')
unless decl_name =~ /\Aattr_\w+_\w+\z/ # skip too-many false-positive warnings in insns_info.inc. unless decl_name =~ /\Aattr_\w+_\w+\z/ # skip too-many false-positive warnings in insns_info.inc.
puts "#{PROGRAM}: making external definition of '#{decl_name}' static inline" transform_logs[:static_inline_def] << decl_name
end end
code[decl_range] = "static inline #{header}#{decl}" code[decl_range] = "static inline #{header}#{decl}"
end end
@ -296,3 +296,14 @@ code << macro
MJITHeader.check_code!(code, cc, cflags, 'final') MJITHeader.check_code!(code, cc, cflags, 'final')
MJITHeader.write(code, outfile) MJITHeader.write(code, outfile)
messages = {
def_to_decl: 'changing definition to declaration',
static_inline_def: 'making external definition static inline',
static_inline_decl: 'making declaration static inline',
static_inside_extern: 'a static decl inside external definition',
skipped: 'SKIPPED to transform',
}
transform_logs.each do |key, decl_names|
puts("#{PROGRAM}: #{messages.fetch(key)}: #{decl_names.map { |s| "\e[1m#{s}\e[0m" }.join(', ')}")
end