class Carbon::Tacky::Builder
A “builder.” This is used in order to create an instruction set for a block. The builder defines a set of methods that create and append an instruction to the parent block. Each instruction gets its own instruction ID relative to the parent block.
@see llvm.org/releases/3.5.2/docs/LangRef.html The LLVM Language
Reference Manual.
@api semiprivate
Public Class Methods
Initialize the builder with the given block.
@param block [Tacky::Block] The block to build onto.
# File lib/carbon/tacky/builder.rb, line 18 def initialize(block) @block = block end
Public Instance Methods
Creates an instruction, and returns a reference to that instruction. The reference points to the instruction using the “instruction id,” which is essentially the instruction's place in the block.
@api private @param inst [::Symbol, ::String] The instruction name. @param parameters [<Reference, Parameter
, Value
, Object>] The
parameters that are being passed to the instruction.
@param name [::String] The return value name of the instruction. @return [Tacky::Reference] The reference to the new instruction.
# File lib/carbon/tacky/builder.rb, line 306 def _call(inst, *parameters, name: "") # cut it off at the pass and force all parameters to instructions to # have a type. id = @block.next typed = parameters.map { |p| Tacky::Typed.from(p) } reference = Tacky::Reference.new(id) instruction = Tacky::Instruction.new(id, inst, parameters, reference) instruction.name = name @block.instructions << instruction reference end
# File lib/carbon/tacky/builder.rb, line 291 def deref(type) fail _call(:_deref, type) end
Returns a null value of a given type. This may be a constant value or a generated value.
@param type [Concrete::Type] The type to null. @return [Tacky::Reference] A value representing the return value of
the instruction.
# File lib/carbon/tacky/builder.rb, line 287 def null(type) _call(:_null, type) end
Returns the size of a type. This may be a constant value or a generated value.
@param type [Concrete::Type] The type to find the size of. @return [Tacky::Reference] A value representing the return value of
the instruction.
# File lib/carbon/tacky/builder.rb, line 277 def sizeof(type) _call(:_sizeof, type) end