diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-11 21:31:18 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-11 21:48:28 -0800 |
commit | 50c5f94ed71707030f03ef1ce699367f021e0aa3 (patch) | |
tree | fc3fcf963d0e955288354682c09f6eb4ad082058 /tool/rjit | |
parent | 58f7e8b7f83babeefb39d1a919d43de237c36c8a (diff) |
RJIT: Introduce constants under RubyVM::RJIT::C
Diffstat (limited to 'tool/rjit')
-rwxr-xr-x | tool/rjit/bindgen.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb index abff60fdc3..a34ac9649b 100755 --- a/tool/rjit/bindgen.rb +++ b/tool/rjit/bindgen.rb @@ -106,15 +106,17 @@ class BindingGenerator attr_reader :src # @param src_path [String] + # @param consts [Hash{ Symbol => Array<String> }] # @param values [Hash{ Symbol => Array<String> }] # @param funcs [Array<String>] # @param types [Array<String>] # @param dynamic_types [Array<String>] #ifdef-dependent immediate types, which need Primitive.cexpr! for type detection # @param skip_fields [Hash{ Symbol => Array<String> }] Struct fields that are skipped from bindgen # @param ruby_fields [Hash{ Symbol => Array<String> }] Struct VALUE fields that are considered Ruby objects - def initialize(src_path:, values:, funcs:, types:, dynamic_types:, skip_fields:, ruby_fields:) + def initialize(src_path:, consts:, values:, funcs:, types:, dynamic_types:, skip_fields:, ruby_fields:) @preamble, @postamble = split_ambles(src_path) @src = String.new + @consts = consts.transform_values(&:sort) @values = values.transform_values(&:sort) @funcs = funcs.sort @types = types.sort @@ -128,6 +130,15 @@ class BindingGenerator println @preamble # Define macros/enums + @consts.each do |type, values| + values.each do |value| + raise "#{value} isn't a valid constant name" unless ('A'..'Z').include?(value[0]) + println " C::#{value} = Primitive.cexpr! %q{ #{type}2NUM(#{value}) }" + end + end + println + + # Define variables @values.each do |type, values| values.each do |value| println " def C.#{value}" @@ -137,6 +148,7 @@ class BindingGenerator end end + # Define function pointers @funcs.each do |func| println " def C.#{func}" println " Primitive.cexpr! %q{ SIZET2NUM((size_t)#{func}) }" @@ -351,11 +363,13 @@ end nodes = HeaderParser.new(File.join(src_dir, 'rjit_c.h'), cflags: cflags).parse generator = BindingGenerator.new( src_path: src_path, - values: { + consts: { LONG: %w[ VM_ENV_DATA_INDEX_ME_CREF VM_ENV_DATA_INDEX_SPECVAL ], + }, + values: { SIZET: %w[ ARRAY_REDEFINED_OP_FLAG BOP_AND |