summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-11 21:31:18 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-11 21:48:28 -0800
commit50c5f94ed71707030f03ef1ce699367f021e0aa3 (patch)
treefc3fcf963d0e955288354682c09f6eb4ad082058 /tool
parent58f7e8b7f83babeefb39d1a919d43de237c36c8a (diff)
downloadruby-50c5f94ed71707030f03ef1ce699367f021e0aa3.tar.gz
RJIT: Introduce constants under RubyVM::RJIT::C
Diffstat (limited to 'tool')
-rw-r--r--tool/mk_builtin_loader.rb3
-rwxr-xr-xtool/rjit/bindgen.rb18
2 files changed, 18 insertions, 3 deletions
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb
index fc6900808f..ba5e3c1ad7 100644
--- a/tool/mk_builtin_loader.rb
+++ b/tool/mk_builtin_loader.rb
@@ -265,7 +265,8 @@ def generate_cexpr(ofile, lineno, line_file, body_lineno, text, locals, func_nam
f = StringIO.new
f.puts '{'
lineno += 1
- locals.reverse_each.with_index{|param, i|
+ # locals is nil outside methods
+ locals&.reverse_each&.with_index{|param, i|
next unless Symbol === param
f.puts "MAYBE_UNUSED(const VALUE) #{param} = rb_vm_lvar(ec, #{-3 - i});"
lineno += 1
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