Class: Stone::AST::PropertyAccess::TypeDispatchBuilder
- Inherits:
-
Object
- Object
- Stone::AST::PropertyAccess::TypeDispatchBuilder
- Defined in:
- lib/stone/ast/property_access.rb
Overview
Builds LLVM switch/phi dispatch for union type extraction
Instance Method Summary collapse
- #build_extraction_blocks(_payload_ptr) ⇒ Object
- #build_merge_phi(phi_incoming) ⇒ Object
- #build_switch(type_tag) ⇒ Object
-
#initialize(builder, mod, union_type) ⇒ TypeDispatchBuilder
constructor
A new instance of TypeDispatchBuilder.
Constructor Details
#initialize(builder, mod, union_type) ⇒ TypeDispatchBuilder
Returns a new instance of TypeDispatchBuilder.
418 419 420 421 422 423 424 425 |
# File 'lib/stone/ast/property_access.rb', line 418 def initialize(builder, mod, union_type) @builder = builder @mod = mod @union_type = union_type @alternatives = union_type.alternatives @result_type = union_type.common_llvm_result_type create_basic_blocks end |
Instance Method Details
#build_extraction_blocks(_payload_ptr) ⇒ Object
432 433 434 435 436 437 438 439 440 |
# File 'lib/stone/ast/property_access.rb', line 432 def build_extraction_blocks(_payload_ptr) @alternatives.each_with_index.to_h do |alt, index| @builder.position_at_end(@alt_blocks[index]) raw_value = yield(alt) converted = convert_to_result_type(raw_value) @builder.br(@merge_block) [@alt_blocks[index], converted] end end |
#build_merge_phi(phi_incoming) ⇒ Object
442 443 444 445 |
# File 'lib/stone/ast/property_access.rb', line 442 def build_merge_phi(phi_incoming) @builder.position_at_end(@merge_block) @builder.phi(@result_type, phi_incoming, "extracted_payload") end |
#build_switch(type_tag) ⇒ Object
427 428 429 430 |
# File 'lib/stone/ast/property_access.rb', line 427 def build_switch(type_tag) cases = @alternatives.each_with_index.to_h { |alt, i| [Stone::RTTI.type_constant_for(@mod, alt), @alt_blocks[i]] } @builder.switch(type_tag, default_block, cases) end |