module Carbon::Tacky::Instruction::Generation
Generation
logic for instructions.
Private Instance Methods
generate_deref(context, _block)
click to toggle source
# File lib/carbon/tacky/instruction/generation.rb, line 36 def generate_deref(context, _block) mapped_parameter(@parameters.first, context).element_type end
generate_normal(context, block)
click to toggle source
Generates a “normal” instruction. It maps the parameters, then sends the instruction over to a builder for LLVM, before returning the result of the instruction.
@param context [Tacky::Context] The context. @param block [::LLVM::BasicBlock] The block. @return [::LLVM::Value] The result of the llvm instruction.
# File lib/carbon/tacky/instruction/generation.rb, line 18 def generate_normal(context, block) params = mapped_parameters(context) value = :_ block.build { |b| value = b.public_send(@instruction, *params) } value end
generate_null(context, _block)
click to toggle source
# File lib/carbon/tacky/instruction/generation.rb, line 26 def generate_null(context, _block) params = mapped_parameters(context) params.first.null end
generate_sizeof(context, _block)
click to toggle source
# File lib/carbon/tacky/instruction/generation.rb, line 31 def generate_sizeof(context, _block) params = mapped_parameters(context) params.first.size end
mapped_parameter(param, context)
click to toggle source
# File lib/carbon/tacky/instruction/generation.rb, line 54 def mapped_parameter(param, context) case param when Concrete::Type context.fetch(param.sub(context.generics)).last when Tacky::Reference then context.instructions.fetch(param.id) when Tacky::Parameter then context.params.fetch(param.value) when Tacky::Typed then mapped_parameter(param.value, context) when ::Integer, ::Float, ::String, ::LLVM::Value then param else fail ArgumentError, "Unexpected parameter #{param.class}" end end
mapped_parameters(context)
click to toggle source
# File lib/carbon/tacky/instruction/generation.rb, line 40 def mapped_parameters(context) @parameters.map { |p| mapped_parameter(p, context) } end
typeof_value(value, context)
click to toggle source
# File lib/carbon/tacky/instruction/generation.rb, line 44 def typeof_value(value, context) case value when Concrete::Type value.sub(context.generics) when Tacky::Typed, Tacky::Parameter value.type.sub(context.generics) else fail ArgumentError, "Cannot typeof #{value.class}" end end