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

transform_mjit_header.rb: refactor messages and exit

* tool/transform_mjit_header.rb: print non-error messages to
  STDOUT instead of STDERR.  exit with false or abort instead of
  exit 1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-02-04 13:51:02 +00:00
parent ec7dd29902
commit e81687527a

View file

@ -77,7 +77,7 @@ module MJITHeader
unless system("#{cc} #{cflags} #{f.path} 2>#{File::NULL}") unless system("#{cc} #{cflags} #{f.path} 2>#{File::NULL}")
STDERR.puts "error in #{stage} header file:" STDERR.puts "error in #{stage} header file:"
system("#{cc} #{cflags} #{f.path}") system("#{cc} #{cflags} #{f.path}")
exit 1 exit false
end end
end end
end end
@ -111,8 +111,7 @@ module MJITHeader
end end
if ARGV.size != 3 if ARGV.size != 3
STDERR.puts 'Usage: transform_mjit_header.rb <c-compiler> <header file> <out>' abort 'Usage: transform_mjit_header.rb <c-compiler> <header file> <out>'
exit 1
end end
cc = ARGV[0] cc = ARGV[0]
@ -133,11 +132,11 @@ MJITHeader.remove_default_macros!(code)
MJITHeader.check_code!(code, cc, cflags, 'initial') MJITHeader.check_code!(code, cc, cflags, 'initial')
if MJITHeader.windows? # transformation is broken with Windows headers for now if MJITHeader.windows? # transformation is broken with Windows headers for now
STDERR.puts "\nSkipped transforming external functions to static on Windows." puts "\nSkipped transforming external functions to static on Windows."
MJITHeader.write(code, outfile) MJITHeader.write(code, outfile)
exit 0 exit
end end
STDERR.puts "\nTransforming external functions to static:" puts "\nTransforming external functions to static:"
code = MJITHeader.separate_macro_and_code(code) # note: this does not work on MinGW code = MJITHeader.separate_macro_and_code(code) # note: this does not work on MinGW
stop_pos = code.match(/^#/).begin(0) # See `separate_macro_and_code`. This ignores proprocessors. stop_pos = code.match(/^#/).begin(0) # See `separate_macro_and_code`. This ignores proprocessors.
@ -153,12 +152,12 @@ loop do
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)
STDERR.puts "transform_mjit_header: changing definition of '#{decl_name}' to declaration" puts "transform_mjit_header: changing definition of '#{decl_name}' to declaration"
code[decl_range] = decl.sub(/{.+}/m, ';') code[decl_range] = decl.sub(/{.+}/m, ';')
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.
STDERR.puts "transform_mjit_header: making declaration of '#{decl_name}' static inline" puts "transform_mjit_header: making declaration of '#{decl_name}' static inline"
end end
code[decl_range] = "static inline #{decl}" code[decl_range] = "static inline #{decl}"
@ -167,12 +166,12 @@ loop do
decl[match.begin(0)...match.end(0)] = '' decl[match.begin(0)...match.end(0)] = ''
if decl =~ /\bstatic\b/ if decl =~ /\bstatic\b/
STDERR.puts "warning: a static decl inside external definition of '#{decl_name}'" puts "warning: a static decl inside external definition of '#{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.
STDERR.puts "transform_mjit_header: making external definition of '#{decl_name}' static inline" puts "transform_mjit_header: making external definition of '#{decl_name}' static inline"
end end
code[decl_range] = "static inline #{header}#{decl}" code[decl_range] = "static inline #{header}#{decl}"
end end