summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-09-20 23:23:50 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2022-09-23 06:44:28 +0900
commit4c6e1556b109367f598e276f72feacefc72805fc (patch)
tree4e8411d731b3447998f9d0ae924ddc2775583399 /tool
parent280ff1707e1e0e5f06d9819dc5f8d8deb38b3f6c (diff)
Bindgen immediate types with builtin
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6418
Diffstat (limited to 'tool')
-rwxr-xr-xtool/mjit/bindgen.rb30
1 files changed, 25 insertions, 5 deletions
diff --git a/tool/mjit/bindgen.rb b/tool/mjit/bindgen.rb
index 9676069b16..793db965dd 100755
--- a/tool/mjit/bindgen.rb
+++ b/tool/mjit/bindgen.rb
@@ -114,14 +114,16 @@ class BindingGenerator
# @param src_path [String]
# @param uses [Array<String>]
# @param ints [Array<String>]
- # @param types [Array<String>] Imported types
+ # @param types [Array<String>]
+ # @param dynamic_types [Array<String>] #ifdef-dependent immediate types, which need Primitive.cexpr! for type detection
# @param ruby_fields [Hash{ Symbol => Array<String> }] Struct VALUE fields that are considered Ruby objects
- def initialize(src_path:, uses:, ints:, types:, ruby_fields:)
+ def initialize(src_path:, uses:, ints:, types:, dynamic_types:, ruby_fields:)
@preamble, @postamble = split_ambles(src_path)
@src = String.new
@uses = uses.sort
@ints = ints.sort
@types = types.sort
+ @dynamic_types = dynamic_types.sort
@ruby_fields = ruby_fields.transform_keys(&:to_s)
@references = Set.new
end
@@ -159,8 +161,19 @@ class BindingGenerator
println
end
+ # Define dynamic types
+ @dynamic_types.each do |type|
+ unless generate_node(nodes_index[type])&.start_with?('CType::Immediate')
+ raise "Non-immediate type is given to dynamic_types: #{type}"
+ end
+ println " def C.#{type}"
+ println " @#{type} ||= CType::Immediate.find(Primitive.cexpr!(\"SIZEOF(#{type})\"), Primitive.cexpr!(\"SIGNED_TYPE_P(#{type})\"))"
+ println " end"
+ println
+ end
+
# Leave a stub for types that are referenced but not targeted
- (@references - @types).each do |type|
+ (@references - @types - @dynamic_types).each do |type|
println " def C.#{type}"
println " #{DEFAULTS[type]}"
println " end"
@@ -257,7 +270,12 @@ class BindingGenerator
push_target(type)
"self.#{type}"
else
- "CType::Immediate.new(#{ctype})"
+ # Convert any function pointers to void* to workaround FILE* vs int*
+ if ctype == Fiddle::TYPE_VOIDP
+ "CType::Immediate.parse(\"void *\")"
+ else
+ "CType::Immediate.parse(#{type.dump})"
+ end
end
end
end
@@ -317,7 +335,6 @@ generator = BindingGenerator.new(
IC
IVC
RB_BUILTIN
- VALUE
compile_branch
compile_status
inlined_call_context
@@ -347,6 +364,9 @@ generator = BindingGenerator.new(
rb_mjit_unit
rb_serial_t
],
+ dynamic_types: %w[
+ VALUE
+ ],
ruby_fields: {
rb_iseq_location_struct: %w[
base_label