class RCGTK::Builder
This class is responsible for adding {Instruction Instructions} to {BasicBlock BasicBlocks}.
Constants
- CLASS_FINALIZER
The Proc object called by the garbage collector to free resources used by
LLVM
.
Public Class Methods
@return [Builder] A global Builder
object.
# File lib/rcgtk/builder.rb, line 28 def self.global @@global_builder ||= Builder.new end
Creates a new Builder
object, optionally positioning it at the end of block. If a block is given it will be executed as if it was passed to the build
method.
@param [BasicBlock, nil] bb BasicBlock
used to position the Builder
. @param [Array<Object>] block_args Arguments to be passed to block. @param [Proc, nil] block Block to execute in the context of this Builder
.
# File lib/rcgtk/builder.rb, line 39 def initialize(bb = nil, *block_args, &block) @ptr = Bindings.create_builder # Define a finalizer to free the memory used by LLVM for this # builder. ObjectSpace.define_finalizer(self, CLASS_FINALIZER) if block then self.build(bb, *block_args, &block) elsif bb then position_at_end(bb) end end
Public Instance Methods
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [AddInst] The integer sum of the two operands.
# File lib/rcgtk/builder.rb, line 323 def add(lhs, rhs, name = '') AddInst.new(Bindings.build_add(@ptr, lhs, rhs, name)) end
Cast a value to a given address space.
@param [Value] val Value
to cast @param [Type] type Target
type @param [String] name Name of the result in LLVM
IR
@return [AddrSpaceCastInst]
# File lib/rcgtk/builder.rb, line 855 def addr_space_cast(val, type, name = '') AddrSpaceCast.new(Bindings.addr_space_cast(@ptr, val, check_cg_type(type), name)) end
Stack allocation.
@param [Type] type Type
or value whose type should be allocad. @param [String] name Name of the result in LLVM
IR.
@return [AllocaInst] A pointer to the allocad bytes.
# File lib/rcgtk/builder.rb, line 701 def alloca(type, name = '') AllocaInst.new(Bindings.build_alloca(@ptr, check_cg_type(type), name)) end
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [AndInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 638 def and(lhs, rhs, name = '') AndInst.new(Bindings.build_and(@ptr, lhs, rhs, name)) end
Stack array allocation.
@param [Type] type Type
or value whose type should be allocad. @param [Value] size Unsigned integer representing size of the array. @param [String] name Name of the result in LLVM
IR.
@return [ArrayAllocaInst] A pointer to the allocad bytes.
# File lib/rcgtk/builder.rb, line 712 def array_alloca(type, size, name = '') ArrayAllocaInst.new(Bindings.build_array_alloca(@ptr, check_cg_type(type), size, name)) end
Heap array allocation.
@param [Type] type Type
or value whose type will be the element type of the malloced array. @param [Value] size Unsigned integer representing size of the array. @param [String] name Name of the result in LLVM
IR.
@return [ArrayMallocInst] A pointer to the malloced array
# File lib/rcgtk/builder.rb, line 691 def array_malloc(type, size, name = '') ArrayMallocInst.new(Bindings.build_array_malloc(@ptr, check_cg_type(type), size, name)) end
Arithmetic (sign extended) shift right.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [ARightShiftInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 618 def ashr(lhs, rhs, name = '') ARightShiftInst.new(Bindings.build_a_shr(@ptr, lhs, rhs, name)) end
Create an atomic read/modify/write instruction.
@see llvm.org/docs/LangRef.html#atomic-memory-ordering-constraints
@param [Symbol from enum_atomic_rmw_bin_op] op Operation to perform @param [OpaqueValue] addr Address to modify @param [OpaqueValue] val Value
to test @param [Symbol from enum_atomic_ordering] ordering Memory ordering constraints @param [Boolean] is_single_thread Synchronize with single thread or all threads
@return [AtomicRMWInst]
# File lib/rcgtk/builder.rb, line 827 def atomic_rmw(op, addr, val, ordering, single_thread) AtomicRMWInst.new(Bindings.build_atomic_rmw(@ptr, op, addr, val, ordering, is_single_thread.to_i)) end
Cast a value to the given type without changing any bits.
@param [Value] val Value
to cast @param [Type] type Target
type @param [String] name Name of the result in LLVM
IR
@return [BitCastInst] A value of the target type.
# File lib/rcgtk/builder.rb, line 866 def bitcast(val, type, name = '') BitCastInst.new(Bindings.build_bit_cast(@ptr, val, check_cg_type(type), name)) end
Unconditional branching.
@param [BasicBlock] block Where to jump.
@return [BranchInst]
# File lib/rcgtk/builder.rb, line 164 def branch(block) BranchInst.new(Bindings.build_br(@ptr, block)) end
Executes a given block inside the context of this builder. If the bb parameter isn’t nill, the Builder
will be positioned at the end of the specified BasicBlock
.
@param [BasicBlock] bb Optional BasicBlock
used to position the Builder
. @param [Array<Object>] block_args Arguments to be passed to block. @param [Proc] block Block to execute in the context of this Builder
.
@return [Object] The result of evaluating block in the context of this Builder
.
# File lib/rcgtk/builder.rb, line 58 def build(bb = nil, *block_args, &block) self.position_at_end(bb) if bb self.instance_exec(*block_args, &block) end
Build an instruction.
@param [Symbol] inst Name of instruction building method. @param [Array<Object>] args Arguments to be passed to building method.
@return [Instruction] Build instruction.
# File lib/rcgtk/builder.rb, line 69 def build_inst(inst, *args) self.send(inst, *args) end
Build an instruction that performs a function call.
@param [Function] fun Function
to call. @param [Array<Value>] args Arguments to pass to function.
@return [CallInst]
# File lib/rcgtk/builder.rb, line 175 def call(fun, *args) name = if args.last.is_a?(String) then args.pop else '' end args_ptr = FFI::MemoryPointer.new(:pointer, args.length) args_ptr.write_array_of_pointer(args) CallInst.new(Bindings.build_call(@ptr, fun, args_ptr, args.length, name)) end
Conditional branching.
@param [Value] val Condition value. @param [BasicBlock] iffalse Where to jump if condition is true. @param [BasicBlock] iftrue Where to jump if condition is false.
@return [CondBranchInst]
# File lib/rcgtk/builder.rb, line 191 def cond_branch(val, iftrue, iffalse) CondBranchInst.new(Bindings.build_cond_br(@ptr, val, iftrue, iffalse)) end
@return [BasicBlock] BasicBlock
the Builder
is currently positioned on.
# File lib/rcgtk/builder.rb, line 116 def current_block BasicBlock.new(Bindings.get_insert_block(@ptr)) end
Signed exact integer division.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SDivInst] The integer quotient of the two operands.
# File lib/rcgtk/builder.rb, line 471 def exact_sdiv(lhs, rhs, name = '') ExactSDivInst.new(Bindings.build_exact_s_div(@ptr, lhs, rhs, name)) end
Extract an element from a vector.
@param [Value] vector Vector from which to extract a value. @param [Value] index Index of the element to extract, an unsigned integer. @param [String] name Value
of the result in LLVM
IR.
@return [ExtractElementInst] The extracted element.
# File lib/rcgtk/builder.rb, line 203 def extract_element(vector, index, name = '') ExtractElementInst.new(Bindings.build_extract_element(@ptr, vector, index, name)) end
Extract the value of a member field from an aggregate value.
@param [Value] aggregate An aggregate value. @param [Value] index Index of the member to extract. @param [String] name Name of the result in LLVM
IR.
@return [ExtractValueInst] The extracted value.
# File lib/rcgtk/builder.rb, line 214 def extract_value(aggregate, index, name = '') ExtractValueInst.new(Bindings.build_extract_value(@ptr, aggregate, index, name)) end
@param [Value] lhs Floating point or vector of floating points. @param [Value] rhs Floating point or vector of floating points. @param [String] name Name of the result in LLVM
IR.
@return [FAddInst] The floating point sum of the two operands.
# File lib/rcgtk/builder.rb, line 332 def fadd(lhs, rhs, name = '') FAddInst.new(Bindings.build_f_add(@ptr, lhs, rhs, name)) end
@param [Value] lhs Floating point or vector of floating points. @param [Value] rhs Floating point or vector of floating points. @param [String] name Name of the result in LLVM
IR.
@return [FDivInst] The floating point quotient of the two operands.
# File lib/rcgtk/builder.rb, line 449 def fdiv(lhs, rhs, name = '') FDivInst.new(Bindings.build_f_div(@ptr, lhs, rhs, name)) end
Create a fence instruction
@see llvm.org/docs/LangRef.html#atomic-memory-ordering-constraints
@param [Symbol from enum_atomic_ordering] ordering Memory ordering constraints @param [Boolean] is_single_thread If this instruction is for a single thread @param [String] name Name of the result in LLVM
IR
@return [FenceInst]
# File lib/rcgtk/builder.rb, line 840 def fence(ordering, is_single_thread, name = '') FenceInst.new(Bindings.build_fence(@ptr, ordering, is_single_thread.to_i, name)) end
@param [Value] val Value
to cast. @param [Type] type Target
type. @param [String] name Name of the result in LLVM
IR.
@return [FPCastInst] A value of the target type.
# File lib/rcgtk/builder.rb, line 875 def floating_point_cast(val, type, name = '') FPCastInst.new(Bindings.build_fp_cast(@ptr, val, check_cg_type(type), name)) end
Extend a floating point value.
@param [Value] val Floating point or vector of floating point. @param [Type] type Floating point or vector of floating point type of greater size than val’s type. @param [String] name Name of the result in LLVM
IR.
@return [FPExtendInst] The extended value.
# File lib/rcgtk/builder.rb, line 887 def floating_point_extend(val, type, name = '') FPExtendInst.new(Bindings.build_fp_ext(@ptr, val, check_cg_type(type), name)) end
Convert a floating point to a signed integer.
@param [Value] val Floating point or vector of floating points to convert. @param [Type] type Integer or vector of integer target type. @param [String] name Name of the result in LLVM
IR.
@return [FPToSIInst] The converted value.
# File lib/rcgtk/builder.rb, line 900 def floating_point_to_signed_int(val, type, name = '') FPToSIInst.new(Bindings.build_fp_to_si(@ptr, val, check_cg_type(type), name)) end
Convert a floating point to an unsigned integer.
@param [Value] val Floating point or vector of floating points to convert. @param [Type] type Integer or vector of integer target type. @param [String] name Name of the result in LLVM
IR.
@return [FPToSIInst] The converted value.
# File lib/rcgtk/builder.rb, line 912 def floating_point_to_unsigned_int(val, type, name = '') FPToUIInst.new(Bindings.build_fp_to_ui(@ptr, val, check_cg_type(type), name)) end
Truncate a floating point value.
@param [Value] val Floating point or vector of floating point. @param [Type] type Floating point or vector of floating point type of lesser size than val’s type. @param [String] name Name of the result in LLVM
IR.
@return [LLVM::Instruction] The truncated value
# File lib/rcgtk/builder.rb, line 924 def floating_point_truncate(val, type, name = '') FPTruncInst.new(Bindings.build_fp_trunc(@ptr, val, check_cg_type(type), name)) end
@param [Value] lhs Floating point or vector of floating points. @param [Value] rhs Floating point or vector of floating points. @param [String] name Name of the result in LLVM
IR.
@return [FMulInst] The floating point product of the two operands.
# File lib/rcgtk/builder.rb, line 416 def fmul(lhs, rhs, name = '') FMulInst.new(Bindings.build_f_mul(@ptr, lhs, rhs, name)) end
Floating point negation. Implemented as a shortcut to the equivalent sub instruction.
@param [Value] val Floating point or vector of floating points. @param [String] name Name of the result in LLVM
IR.
@return [NegInst] The negated operand.
# File lib/rcgtk/builder.rb, line 539 def fneg(val, name = '') FNegInst.new(Bindings.build_f_neg(@ptr, val, name)) end
Builds an fcmp instruction. Compares lhs to rhs as reals using the given symbol predicate.
@see Bindings
.enum_real_predicate @LLVMInst fcmp
@param [Symbol] pred A real predicate. @param [Value] lhs Left hand side of the comparison, of floating point type. @param [Value] rhs Right hand side of the comparison, of the same type as lhs. @param [String] name Name of the result in LLVM
IR.
@return [FCmpInst] A Boolean represented as an Int1
.
# File lib/rcgtk/builder.rb, line 1104 def fp_comparison(pred, lhs, rhs, name = '') FCmpInst.new(Bindings.build_f_cmp(@ptr, pred, lhs, rhs, name)) end
@param [LLVM::Value] ptr The pointer to be freed.
@return [FreeInst] The result of the free instruction.
# File lib/rcgtk/builder.rb, line 719 def free(ptr) FreeInst.new(Bindings.build_free(@ptr, ptr)) end
@param [Value] lhs Floating point or vector of floating points. @param [Value] rhs Floating point or vector of floating points. @param [String] name Name of the result in LLVM
IR.
@return [FRemInst] The floating point remainder.
# File lib/rcgtk/builder.rb, line 493 def frem(lhs, rhs, name = '') FRemInst.new(Bindings.build_f_rem(@ptr, lhs, rhs, name)) end
@param [Value] lhs Floating point or vector of floating points. @param [Value] rhs Floating point or vector of floating points. @param [String] name Name of the result in LLVM
IR.
@return [FSubInst] The floating point difference of the two operands.
# File lib/rcgtk/builder.rb, line 374 def fsub(lhs, rhs, name = '') FSubInst.new(Bindings.build_f_sub(@ptr, lhs, rhs, name)) end
Obtain a pointer to the element at the given indices.
@param [Value] ptr Pointer to an aggregate value @param [Array<Value>] indices Ruby array of Value
representing
indices into the aggregate.
@param [String] name The name of the result in LLVM
IR.
@return [GetElementPtrInst] The resulting pointer.
# File lib/rcgtk/builder.rb, line 751 def get_element_ptr(ptr, indices, name = '') check_array_type(indices, Value, 'indices') indices_ptr = FFI::MemoryPointer.new(:pointer, indices.length) indices_ptr.write_array_of_pointer(indices) GetElementPtrInst.new(Bindings.build_gep(@ptr, ptr, indices_ptr, indices.length, name)) end
Builds a in-bounds getelementptr instruction. If the indices are outside the allocated pointer the value is undefined.
@param [Value] ptr Pointer to an aggregate value @param [Array<Value>] indices Ruby array of Value
representing
indices into the aggregate.
@param [String] name The name of the result in LLVM
IR.
@return [InBoundsGEPInst] The resulting pointer.
# File lib/rcgtk/builder.rb, line 770 def get_element_ptr_in_bounds(ptr, indices, name = '') check_array_type(indices, Value, 'indices') indices_ptr = FFI::MemoryPointer.new(:pointer, indices.length) indices_ptr.write_array_of_pointer(indices) InBoundsGEPInst.new(Bindings.build_in_bounds_gep(@ptr, ptr, indices_ptr, indices.length, name)) end
Creates a pointer to a global string initialized to a given value.
@param [String] string String used by the initializer @param [String] name Name of the result in LLVM
IR
@return [GlobalStringPtrInst] Reference to the global string pointer.
# File lib/rcgtk/builder.rb, line 808 def gloabl_string_pointer(string, name = '') GlobalStringPtrInst.new(Bindings.build_global_string_ptr(@ptr, string, name)) end
Creates a global string initialized to a given value.
@param [String] string String used by the initialize. @param [String] name Name of the result in LLVM
IR.
@return [GlobalStringInst] Reference to the global string.
# File lib/rcgtk/builder.rb, line 798 def global_string(string, name = '') GlobalStringInst.new(Bindings.build_global_string(@ptr, string, name)) end
Insert an element into a vector.
@param [Value] vector Vector into which to insert the element. @param [Value] element Element to be inserted into the vector. @param [Value] index Index at which to insert the element. @param [String] name Name of the result in LLVM
IR.
@return [InsertElementInst] A vector the same type as vector.
# File lib/rcgtk/builder.rb, line 226 def insert_element(vector, element, index, name = '') InsertElementInst.new(Bindings.build_insert_element(@ptr, vector, element, index, name)) end
Insert a value into an aggregate value’s member field.
@param [Value] aggregate An aggregate value. @param [Value] val Value
to insert into aggregate. @param [Value] index Index at which to insert the value. @param [String] name Name of the result in LLVM
IR.
@return [InsertValueInst] An aggregate value of the same type as aggregate.
# File lib/rcgtk/builder.rb, line 238 def insert_value(aggregate, val, index, name = '') InsertValueInst.new(Bindings.build_insert_value(@ptr, aggregate, val, index, name)) end
Builds an icmp instruction. Compares lhs to rhs using the given symbol predicate.
@see Bindings
.enum_int_predicate @LLVMInst icmp
@param [Symbol] pred An integer predicate. @param [Value] lhs Left hand side of the comparison, of integer or pointer type. @param [Value] rhs Right hand side of the comparison, of the same type as lhs. @param [String] name Name of the result in LLVM
IR.
@return [IntCmpInst] A Boolean represented as Int1
.
# File lib/rcgtk/builder.rb, line 1087 def int_comparison(pred, lhs, rhs, name = '') IntCmpInst.new(Bindings.build_i_cmp(@ptr, pred, lhs, rhs, name)) end
Cast an int to a pointer.
@param [Value] val An integer value. @param [Type] type A pointer type. @param [String] name Name of the result in LLVM
IR.
@return [IntToPtrInst] A pointer of the given type and the address held in val.
# File lib/rcgtk/builder.rb, line 937 def int_to_ptr(val, type, name = '') IntToPtrInst.new(Bindings.build_int_to_ptr(@ptr, val, check_cg_type(type), name)) end
@param [Value] val An integer value. @param [Type] type Integer or vector of integer target type. @param [String] name Name of the result in LLVM
IR.
@return [IntCastInst]
# File lib/rcgtk/builder.rb, line 947 def integer_cast(val, type, name = '') IntCastInst.new(Bindings.build_int_cast(@ptr, val, check_cg_type(type), name)) end
Invoke a function which may potentially unwind.
@param [Function] fun Function
to invoke. @param [Array<Value>] args Arguments passed to fun. @param [BasicBlock] normal Where to jump if fun does not unwind. @param [BasicBlock] exception Where to jump if fun unwinds. @param [String] name Name of the result in LLVM
IR.
@return [InvokeInst] The value returned by fun, unless an unwind instruction occurs.
# File lib/rcgtk/builder.rb, line 251 def invoke(fun, args, normal, exception, name = '') InvokeInst.new(Bindings.build_invoke(@ptr, fun, args, args.length, normal, exception, name)) end
Check if a value is not null.
@param [Value] val Value
to check. @param [String] name Name of the result in LLVM
IR.
@return [LLVM::Instruction] A Boolean represented as an Int1
.
# File lib/rcgtk/builder.rb, line 1126 def is_not_null(val, name = '') IsNotNullInst.new(Builder.build_is_not_null(@ptr, val, name)) end
Check if a value is null.
@param [Value] val Value
to check. @param [String] name Name of the result in LLVM
IR.
@return [LLVM::Instruction] A Boolean represented as an Int1
.
# File lib/rcgtk/builder.rb, line 1136 def is_null(val, name = '') IsNullInst.new(Bindings.build_is_null(@ptr, val, name)) end
Load the value of a given pointer.
@param [Value] ptr Pointer to be loaded. @param [String] name Name of the result in LLVM
IR.
@return [LoadInst] The result of the load operation. Represents a value of the pointer’s type.
# File lib/rcgtk/builder.rb, line 729 def load(ptr, name = '') LoadInst.new(Bindings.build_load(@ptr, ptr, name)) end
Logical (zero fill) shift right.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [ARightShiftInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 629 def lshr(lhs, rhs, name = '') LRightShiftInst.new(Bindings.build_l_shr(@ptr, lhs, rhs, name)) end
Heap allocation.
@param [Type] type Type
or value whose type should be malloced. @param [String] name Name of the result in LLVM
IR.
@return [MallocInst] A pointer to the malloced bytes.
# File lib/rcgtk/builder.rb, line 680 def malloc(type, name = '') MallocInst.new(Bindings.build_malloc(@ptr, check_type(type), name)) end
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [MulInst] The integer product of the two operands.
# File lib/rcgtk/builder.rb, line 407 def mul(lhs, rhs, name = '') MulInst.new(Bindings.build_mul(@ptr, lhs, rhs, name)) end
Integer negation. Implemented as a shortcut to the equivalent sub instruction.
@param [Value] val Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [NegInst] The negated operand.
# File lib/rcgtk/builder.rb, line 528 def neg(val, name = '') NegInst.new(Bindings.build_neg(@ptr, val, name)) end
Boolean negation.
@param [Value] val Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [NotInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 666 def not(val, name = '') NotInst.new(Bindings.build_not(@ptr, val, name)) end
No signed wrap addition.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [NSWAddInst] The integer sum of the two operands.
# File lib/rcgtk/builder.rb, line 343 def nsw_add(lhs, rhs, name = '') NSWAddInst.new(Bindings.build_nsw_add(@ptr, lhs, rhs, name)) end
No signed wrap multiplication.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [MulInst] The integer product of the two operands.
# File lib/rcgtk/builder.rb, line 427 def nsw_mul(lhs, rhs, name = '') NSWMulInst.new(Bindings.build_nsw_mul(@ptr, lhs, rhs, name)) end
No signed wrap integer negation. Implemented as a shortcut to the equivalent sub instruction.
@param [Value] val Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [NegInst] The negated operand.
# File lib/rcgtk/builder.rb, line 550 def nsw_neg(val, name = '') NSWNegInst.new(Bindings.build_nsw_neg(@ptr, val, name)) end
No signed wrap subtraction.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SubInst] The integer difference of the two operands.
# File lib/rcgtk/builder.rb, line 385 def nsw_sub(lhs, rhs, name = '') NSWSubInst.new(Bindings.build_nsw_sub(@ptr, lhs, rhs, name)) end
No unsigned wrap addition.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [NSWAddInst] The integer sum of the two operands.
# File lib/rcgtk/builder.rb, line 354 def nuw_add(lhs, rhs, name = '') NUWAddInst.new(Bindings.build_nuw_add(@ptr, lhs, rhs, name)) end
No unsigned wrap multiplication.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [MulInst] The integer product of the two operands.
# File lib/rcgtk/builder.rb, line 438 def nuw_mul(lhs, rhs, name = '') NUWMulInst.new(Bindings.build_nuw_mul(@ptr, lhs, rhs, name)) end
No unsigned wrap integer negation. Implemented as a shortcut to the equivalent sub instruction.
@param [Value] val Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [NegInst] The negated operand.
# File lib/rcgtk/builder.rb, line 561 def nuw_neg(val, name = '') NUWNegInst.new(Bindings.build_nuw_neg(@ptr, val, name)) end
No unsigned wrap subtraction.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SubInst] The integer difference of the two operands.
# File lib/rcgtk/builder.rb, line 396 def nuw_sub(lhs, rhs, name = '') NUWSubInst.new(Bindings.build_nuw_sub(@ptr, lhs, rhs, name)) end
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [OrInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 647 def or(lhs, rhs, name = '') OrInst.new(Bindings.build_or(@ptr, lhs, rhs, name)) end
Build a Phi node of the given type with the given incoming branches.
@param [Type] type Specifies the result type. @param [Hash{BasicBlock => Value}] incoming A hash mapping basic blocks to a
corresponding value. If the phi node is jumped to from a given basic block, the phi instruction takes on its corresponding value.
@param [String] name Name of the result in LLVM
IR.
@return [PhiInst] The phi node.
# File lib/rcgtk/builder.rb, line 265 def phi(type, incoming, name = '') PhiInst.new(Bindings.build_phi(@ptr, check_cg_type(type), name)).tap do |phi| phi.incoming.add(incoming) end end
Position the Builder
after the given instruction.
@param [BasicBlock] bb @param [Instruction] instruction
@return [Builder] self
# File lib/rcgtk/builder.rb, line 80 def position(bb, instruction) Bindings.position_builder(@ptr, bb, instruction) if check_type(bb, BasicBlock, 'bb') self end
Position the Builder
at the end of the given BasicBlock
.
@param [BasicBlock] bb
@return [Bulder] self
# File lib/rcgtk/builder.rb, line 90 def position_at_end(bb) Bindings.position_builder_at_end(@ptr, bb) if check_type(bb, BasicBlock, 'bb') self end
Position the Builder
before the given Instruction
.
@param [Instruction] instruction
@return [Builder] self
# File lib/rcgtk/builder.rb, line 102 def position_before(instruction) Bindings.position_builder_before(@ptr, instruction) self end
@param [Value] val A pointer value. @param [Type] type A pointer target type. @param [String] name Name of the result in LLVM
IR.
@return [PtrCastInst]
# File lib/rcgtk/builder.rb, line 957 def ptr_cast(val, type, name = '') PtrCastInst.new(Bindings.build_pointer_cast(@ptr, val, check_cg_type(type), name)) end
Calculate the difference between two pointers.
@param [Value] lhs A pointer. @param [Value] rhs A pointer. @param [String] name Name of the result in LLVM
IR.
@return [PtrDiffInst] The integer difference between the two pointers.
# File lib/rcgtk/builder.rb, line 1116 def ptr_diff(lhs, rhs, name = '') PtrDiffInst.new(Bindings.build_ptr_diff(lhs, rhs, name)) end
Cast a pointer to an int. Useful for pointer arithmetic.
@param [Value] val A pointer value. @param [Type] type An integer type. @param [String] name Name of the result in LLVM
IR.
@return [PtrToIntInst] An integer of the given type representing the pointer’s address.
# File lib/rcgtk/builder.rb, line 968 def ptr_to_int(val, type, name = '') PtrToIntInst.new(Bindings.build_ptr_to_int(@ptr, val, check_cg_type(type), name)) end
@param [Value] val The Value
to return.
@return [ReturnInst]
# File lib/rcgtk/builder.rb, line 136 def ret(val) ReturnInst.new(Bindings.build_ret(@ptr, val)) end
@return [RetAggregateInst]
# File lib/rcgtk/builder.rb, line 146 def ret_aggregate(*vals) vals = vals.first if vals.length == 1 and vals.first.instance_of?(::Array) vals_ptr = FFI::MemoryPointer.new(:pointer, vals.length) vals_ptr.write_array_of_pointer(vals) ReturnAggregateInst.new(Bindings.build_aggregate_ret(@ptr, vals_ptr, vals.length)) end
@return [RetVoidInst]
# File lib/rcgtk/builder.rb, line 141 def ret_void ReturnVoidInst.new(Bindings.build_ret_void(@ptr)) end
Signed integer division.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SDivInst] The integer quotient of the two operands.
# File lib/rcgtk/builder.rb, line 460 def sdiv(lhs, rhs, name = '') SDivInst.new(Bindings.build_s_div(@ptr, lhs, rhs, name)) end
Return a value based on a condition. This differs from cond in that its operands are values rather than basic blocks. As a consequence, both arguments must be evaluated.
@param [Value] if_val An Int1
or a vector of Int1
. @param [Value] then_val Value
or vector of the same arity as if_val. @param [Value] else_val Value
or vector of values of the same arity
as *if_val*, and of the same type as *then_val*.
@param [String] name Name of the result in LLVM
IR.
@return [SelectInst] An instruction representing either then_val or else_val.
# File lib/rcgtk/builder.rb, line 282 def select(if_val, then_val, else_val, name = '') SelectInst.new(Bindings.build_select(@ptr, if_val, then_val, else_val, name)) end
A wrapper method around the {#shift_left} and {#shift_right} methods.
@param [:left, :right] dir The direction to shift. @param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [:arithmetic, :logical] mode Shift mode for right shifts. @param [String] name Name of the result in LLVM
IR.
@return [LeftShiftInst, ARightShiftInst
, LRightShiftInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 579 def shift(dir, lhs, rhs, mode = :arithmetic, name = '') case dir when :left then shift_left(lhs, rhs, name) when :right then shift_right(lhs, rhs, mode, name) end end
@param [Value] lhs Integer or vector of integers @param [Value] rhs Integer or vector of integers @param [String] name Name of the result in LLVM
IR
@return [LeftShiftInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 591 def shift_left(lhs, rhs, name = '') LeftShiftInst.new(Bindings.build_shl(@ptr, lhs, rhs, name)) end
A wrapper function around {#ashr} and {#lshr}.
@param [Value] lhs Integer or vector of integers @param [Value] rhs Integer or vector of integers @param [:arithmetic, :logical] mode The filling mode. @param [String] name Name of the result in LLVM
IR
@return [LeftShiftInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 604 def shift_right(lhs, rhs, mode = :arithmetic, name = '') case mode when :arithmetic then ashr(lhs, rhs, name) when :logical then lshr(lhs, rhs, name) end end
Shuffle two vectors according to a given mask.
@param [Value] vec1 Vector @param [Value] vec2 Vector of the same type and arity as vec1. @param [Value] mask Vector of Int1
of the same arity as vec1 and vec2. @param [String] name Name of the result in LLVM
IR.
@return [ShuffleVectorInst] The shuffled vector.
# File lib/rcgtk/builder.rb, line 294 def shuffle_vector(vec1, vec2, mask, name = '') ShuffleVectorInst.new(Bindings.build_shuffle_vector(@ptr, vec1, vec2, mask, name)) end
Sign extension by copying the sign bit (highest order bit) of the value until it reaches the bit size of the given type.
@param [Value] val Integer or vector of integers to be extended. @param [Type] type Integer or vector of integer type of greater size than the size of val. @param [String] name Name of the result in LLVM
IR.
@return [SignExtendInst] The extended value.
# File lib/rcgtk/builder.rb, line 981 def sign_extend(val, type, name = '') SignExtendInst.new(Bindings.build_s_ext(@ptr, val, check_cg_type(type), name)) end
Sign extension or bitcast.
@param [Value] val Integer or vector of integers to be extended. @param [Type] type Integer or vector of integer type of greater size than the size of val. @param [String] name Name of the result in LLVM
IR.
@return [SignExtendOrBitcastInst] The extended or cast value.
# File lib/rcgtk/builder.rb, line 993 def sign_extend_or_bitcast(val, type, name = '') SignExtendOrBitCastInst.new(Bindings.build_s_ext_or_bit_cast(@ptr, val, check_cg_type(type), name)) end
Convert a signed integer to a floating point.
@param [Value] val Signed integer or vector of signed integer to convert. @param [Type] type Floating point or vector of floating point target type. @param [String] name Name of the result in LLVM
IR.
@return [SIToFPInst] The converted value.
# File lib/rcgtk/builder.rb, line 1005 def signed_int_to_floating_point(val, type, name = '') SIToFPInst.new(Bindings.build_si_to_fp(@ptr, val, check_cg_type(type), name)) end
Signed remainder.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SRemInst] The integer remainder.
# File lib/rcgtk/builder.rb, line 504 def srem(lhs, rhs, name = '') SRemInst.new(Bindings.build_s_rem(@ptr, lhs, rhs, name)) end
Store a value at a given pointer.
@param [Value] val The value to be stored. @param [Value] ptr Pointer to the same type as val.
@return [StoreInst] The result of the store operation.
# File lib/rcgtk/builder.rb, line 739 def store(val, ptr) StoreInst.new(Bindings.build_store(@ptr, val, ptr)) end
Builds a struct getelementptr instruction.
@param [Value] ptr Pointer to a structure. @param [Value] index Unsigned integer representing the index of a structure member. @param [String] name Name of the result in LLVM
IR.
@return [StructGEPInst] The resulting pointer.
# File lib/rcgtk/builder.rb, line 787 def struct_get_element_ptr(ptr, index, name = '') StructGEPInst.new(Bindings.build_struct_gep(@ptr, ptr, index, name)) end
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SubInst] The integer difference of the two operands.
# File lib/rcgtk/builder.rb, line 365 def sub(lhs, rhs, name = '') SubInst.new(Bindings.build_sub(@ptr, lhs, rhs, name)) end
Select a value based on an incoming value. @param [Value] val Value
to switch on. @param [BasicBlock] default Default case. @param [Hash{Value => BasicBlock}] cases Hash mapping values
to basic blocks. When a value is matched, control will jump to the corresponding basic block.
@return [SwitchInst]
# File lib/rcgtk/builder.rb, line 306 def switch(val, default, cases) SwitchInst.new(Bindings.build_switch(@ptr, val, default, cases.size)).tap do |inst| cases.each { |val, block| inst.add_case(val, block) } end end
Truncates its operand to the given type. The size of the value type must be greater than the size of the target type.
@param [Value] val Integer or vector of integers to be truncated. @param [Type] type Integer or vector of integers of equal size to val. @param [String] name Name of the result in LLVM
IR.
@return [TruncateInst] The truncated value.
# File lib/rcgtk/builder.rb, line 1018 def truncate(val, type, name = '') TruncateInst.new(Bindings.build_trunc(@ptr, val, check_cg_type(type), name)) end
Truncates or bitcast.
@param [Value] val Integer or vector of integers to be truncated. @param [Type] type Integer or vector of integers of equal size to val. @param [String] name Name of the result in LLVM
IR.
@return [TruncateInst] The truncated or cast value.
# File lib/rcgtk/builder.rb, line 1030 def truncate_or_bitcast(val, type, name = '') TruncateOrBitCastInst.new(Bindings.build_trunc_or_bit_cast(@ptr, val, check_cg_type(type), name)) end
Unsigned integer division.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SDivInst] The integer quotient of the two operands.
# File lib/rcgtk/builder.rb, line 482 def udiv(lhs, rhs, name = '') UDivInst.new(Bindings.build_u_div(@ptr, lhs, rhs, name)) end
Generates an instruction with no defined semantics. Can be used to provide hints to the optimizer.
@return [UnreachableInst]
# File lib/rcgtk/builder.rb, line 125 def unreachable UnreachableInst.new(Bindings.build_unreachable(@ptr)) end
Convert an unsigned integer to a floating point.
@param [Value] val Signed integer or vector of signed integer to convert. @param [Type] type Floating point or vector of floating point target type. @param [String] name Name of the result in LLVM
IR.
@return [SIToFPInst] The converted value.
# File lib/rcgtk/builder.rb, line 1041 def unsigned_int_to_floating_point(val, type, name = '') UIToFPInst.new(Bindings.build_ui_to_fp(@ptr, val, check_cg_type(type), name)) end
Unsigned remainder.
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [SRemInst] The integer remainder.
# File lib/rcgtk/builder.rb, line 515 def urem(lhs, rhs, name = '') URemInst.new(Bindings.build_u_rem(@ptr, lhs, rhs, name)) end
@param [Value] lhs Integer or vector of integers. @param [Value] rhs Integer or vector of integers. @param [String] name Name of the result in LLVM
IR.
@return [XOrInst] An integer instruction.
# File lib/rcgtk/builder.rb, line 656 def xor(lhs, rhs, name = '') XOrInst.new(Bindings.build_xor(@ptr, lhs, rhs, name)) end
Zero extends its operand to the given type. The size of the value type must be greater than the size of the target type.
@param [Value] val Integer or vector of integers to be extended. @param [Type] type Integer or vector of integer type of greater size than val. @param [String] name Name of the result in LLVM
IR.
@return [ZeroExtendInst] The extended value.
# File lib/rcgtk/builder.rb, line 1054 def zero_extend(val, type, name = '') ZeroExtendInst.new(Bindings.build_z_ext(@ptr, val, check_cg_type(type), name)) end
Zero extend or bitcast.
@param [Value] val Integer or vector of integers to be extended. @param [Type] type Integer or vector of integer type of greater size than val. @param [String] name Name of the result in LLVM
IR.
@return [ZeroExtendInst] The extended or cast value.
# File lib/rcgtk/builder.rb, line 1066 def zero_extend_or_bitcast(val, type, name = '') ZeroExtendOrBitCastInst.new(Bindings.build_z_ext_or_bit_cast(@ptr, val, check_cg_type(type), name)) end