From 9f8e914943f812a5036d92648386169079daf51b Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 18 Mar 2023 21:14:35 -0700 Subject: RJIT: Implement checkkeyword --- tool/rjit/bindgen.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'tool') diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb index bcc4ee954a..ad2e5f9e1e 100755 --- a/tool/rjit/bindgen.rb +++ b/tool/rjit/bindgen.rb @@ -156,8 +156,8 @@ class BindingGenerator println end - # TODO: Support nested declarations - nodes_index = nodes.group_by(&:spelling).transform_values do |values| + # Build a hash table for type lookup by name + nodes_index = flatten_nodes(nodes).group_by(&:spelling).transform_values do |values| # Try to search a declaration with definitions node_with_children = values.find { |v| !v.children.empty? } next node_with_children if node_with_children @@ -169,7 +169,7 @@ class BindingGenerator # Define types @types.each do |type| unless definition = generate_node(nodes_index[type]) - raise "Failed to generate type: #{type}" + raise "Failed to find or generate type: #{type}" end println " def C.#{type}" println "@#{type} ||= #{definition}".gsub(/^/, " ").chomp @@ -201,6 +201,18 @@ class BindingGenerator private + # Make an array that includes all top-level and nested nodes + def flatten_nodes(nodes) + result = [] + nodes.each do |node| + unless node.children.empty? + result.concat(flatten_nodes(node.children)) + end + end + result.concat(nodes) # prioritize top-level nodes + result + end + # Return code before BINDGEN_BEG and code after BINDGEN_END def split_ambles(src_path) lines = File.read(src_path).lines @@ -573,6 +585,7 @@ generator = BindingGenerator.new( rb_shape_t rb_thread_struct rb_jit_func_t + rb_iseq_param_keyword rjit_options ], # #ifdef-dependent immediate types, which need Primitive.cexpr! for type detection -- cgit v1.2.1