ruby-changes:50167
From: k0kubun <ko1@a...>
Date: Wed, 7 Feb 2018 22:48:54 +0900 (JST)
Subject: [ruby-changes:50167] k0kubun:r62285 (trunk): transform_mjit_header.rb: ignore unsupported cc
k0kubun 2018-02-07 22:48:48 +0900 (Wed, 07 Feb 2018) New Revision: 62285 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62285 Log: transform_mjit_header.rb: ignore unsupported cc to generate MJIT header. Even if we can't build MJIT header, Ruby's build should success. And compilers which are not explicitly supported are likely to fail to transform MJIT header. Also you can pass only gcc or clang to --jit-cc=xxx for now. Thus generating header does never make sense. So I decided to conservatively give up MJIT header generation. But please feel free to add your favorite compiler's macro if you think it's working. (Another workaround is passing -D__GNUC__ :p) [Bug #14447] [Bug #14446] Modified files: trunk/tool/transform_mjit_header.rb Index: tool/transform_mjit_header.rb =================================================================== --- tool/transform_mjit_header.rb (revision 62284) +++ tool/transform_mjit_header.rb (revision 62285) @@ -13,6 +13,13 @@ module MJITHeader https://github.com/ruby/ruby/blob/trunk/tool/transform_mjit_header.rb#L13 FUNC_HEADER_REGEXP = /\A(\s*#{ATTR_REGEXP})*[^\[{(]*\((#{ATTR_REGEXP}|[^()])*\)(\s*#{ATTR_REGEXP})*\s*/ TARGET_NAME_REGEXP = /\A(rb|ruby|vm|insn|attr)_/ + # Predefined macros for compilers which are already supported by MJIT. + # We're going to support cl.exe too (WIP) but `cl.exe -E` can't produce macro. + SUPPORTED_CC_MACROS = [ + '__GNUC__', # gcc + '__clang__', # clang + ] + # For MinGW's ras.h. Those macros have its name in its definition and can't be preprocessed multiple times. RECURSIVE_MACROS = %w[ RASCTRYINFO @@ -121,6 +128,15 @@ module MJITHeader https://github.com/ruby/ruby/blob/trunk/tool/transform_mjit_header.rb#L128 def self.windows? RUBY_PLATFORM =~ /mswin|mingw|msys/ end + + def self.cl_exe?(cc) + cc =~ /\Acl(\z| |\.exe)/ + end + + # If code has macro which only supported compilers predefine, return true. + def self.supported_header?(code) + SUPPORTED_CC_MACROS.any? { |macro| code =~ /^#\s*define\s+#{macro}\b/ } + end end if ARGV.size != 3 @@ -130,12 +146,18 @@ end https://github.com/ruby/ruby/blob/trunk/tool/transform_mjit_header.rb#L146 cc = ARGV[0] code = File.binread(ARGV[1]) # Current version of the header file. outfile = ARGV[2] -if cc =~ /\Acl(\z| |\.exe)/ +if MJITHeader.cl_exe?(cc) cflags = '-DMJIT_HEADER -Zs' else cflags = '-S -DMJIT_HEADER -fsyntax-only -Werror=implicit-function-declaration -Werror=implicit-int -Wfatal-errors' end +if !MJITHeader.cl_exe?(cc) && !MJITHeader.supported_header?(code) + puts "This compiler (#{cc}) looks not supported for MJIT. Giving up to generate MJIT header." + MJITHeader.write("#error MJIT does not support '#{cc}' yet", outfile) + exit +end + if MJITHeader.windows? MJITHeader.remove_harmful_macros!(code) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/