Class: RLTK::CG::Builder
- Inherits:
-
Object
- Object
- RLTK::CG::Builder
- Includes:
- BindingClass
- Defined in:
- lib/rltk/cg/builder.rb
Overview
This class is responsible for adding Instructions to BasicBlocks.
Direct Known Subclasses
Constant Summary collapse
- CLASS_FINALIZER =
The Proc object called by the garbage collector to free resources used by LLVM.
Proc.new { |id| Bindings.dispose_builder(ptr) if ptr = ObjectSpace._id2ref(id).ptr }
Instance Attribute Summary
Attributes included from BindingClass
Class Method Summary collapse
-
.global ⇒ Builder
A global Builder object.
Instance Method Summary collapse
-
#add(lhs, rhs, name = '') ⇒ AddInst
The integer sum of the two operands.
-
#addr_space_cast(val, type, name = '') ⇒ AddrSpaceCastInst
Cast a value to a given address space.
-
#alloca(type, name = '') ⇒ AllocaInst
Stack allocation.
-
#and(lhs, rhs, name = '') ⇒ AndInst
An integer instruction.
-
#array_alloca(type, size, name = '') ⇒ ArrayAllocaInst
Stack array allocation.
-
#array_malloc(type, size, name = '') ⇒ ArrayMallocInst
Heap array allocation.
-
#ashr(lhs, rhs, name = '') ⇒ ARightShiftInst
Arithmetic (sign extended) shift right.
-
#atomic_rmw(op, addr, val, ordering, single_thread) ⇒ AtomicRMWInst
Create an atomic read/modify/write instruction.
-
#bitcast(val, type, name = '') ⇒ BitCastInst
Cast a value to the given type without changing any bits.
-
#branch(block) ⇒ BranchInst
(also: #br)
Unconditional branching.
-
#build(bb = nil, *block_args, &block) ⇒ Object
Executes a given block inside the context of this builder.
-
#build_inst(inst, *args) ⇒ Instruction
(also: #<<)
Build an instruction.
-
#call(fun, *args) ⇒ CallInst
Build an instruction that performs a function call.
-
#cond_branch(val, iftrue, iffalse) ⇒ CondBranchInst
(also: #cond)
Conditional branching.
-
#current_block ⇒ BasicBlock
(also: #insertion_block)
BasicBlock the Builder is currently positioned on.
-
#exact_sdiv(lhs, rhs, name = '') ⇒ SDivInst
Signed exact integer division.
-
#extract_element(vector, index, name = '') ⇒ ExtractElementInst
Extract an element from a vector.
-
#extract_value(aggregate, index, name = '') ⇒ ExtractValueInst
Extract the value of a member field from an aggregate value.
-
#fadd(lhs, rhs, name = '') ⇒ FAddInst
The floating point sum of the two operands.
-
#fdiv(lhs, rhs, name = '') ⇒ FDivInst
The floating point quotient of the two operands.
-
#floating_point_cast(val, type, name = '') ⇒ FPCastInst
(also: #fp_cast)
A value of the target type.
-
#floating_point_extend(val, type, name = '') ⇒ FPExtendInst
(also: #fp_ext, #fp_extend)
Extend a floating point value.
-
#floating_point_to_signed_int(val, type, name = '') ⇒ FPToSIInst
(also: #fp2si)
Convert a floating point to a signed integer.
-
#floating_point_to_unsigned_int(val, type, name = '') ⇒ FPToSIInst
(also: #fp2ui)
Convert a floating point to an unsigned integer.
-
#floating_point_truncate(val, type, name = '') ⇒ LLVM::Instruction
(also: #fp_trunc, #fp_truncate)
Truncate a floating point value.
-
#fmul(lhs, rhs, name = '') ⇒ FMulInst
The floating point product of the two operands.
-
#fneg(val, name = '') ⇒ NegInst
Floating point negation.
-
#fp_comparison(pred, lhs, rhs, name = '') ⇒ FCmpInst
(also: #fcmp)
Builds an fcmp instruction.
-
#free(ptr) ⇒ FreeInst
The result of the free instruction.
-
#frem(lhs, rhs, name = '') ⇒ FRemInst
The floating point remainder.
-
#fsub(lhs, rhs, name = '') ⇒ FSubInst
The floating point difference of the two operands.
-
#get_element_ptr(ptr, indices, name = '') ⇒ GetElementPtrInst
(also: #gep)
Obtain a pointer to the element at the given indices.
-
#get_element_ptr_in_bounds(ptr, indices, name = '') ⇒ InBoundsGEPInst
(also: #inbounds_gep)
Builds a in-bounds getelementptr instruction.
-
#gloabl_string_pointer(string, name = '') ⇒ GlobalStringPtrInst
Creates a pointer to a global string initialized to a given value.
-
#global_string(string, name = '') ⇒ GlobalStringInst
Creates a global string initialized to a given value.
-
#initialize(bb = nil, *block_args, &block) ⇒ Builder
constructor
Creates a new Builder object, optionally positioning it at the end of block.
-
#insert_element(vector, element, index, name = '') ⇒ InsertElementInst
Insert an element into a vector.
-
#insert_value(aggregate, val, index, name = '') ⇒ InsertValueInst
Insert a value into an aggregate value’s member field.
-
#int_comparison(pred, lhs, rhs, name = '') ⇒ IntCmpInst
(also: #icmp)
Builds an icmp instruction.
-
#int_to_ptr(val, type, name = '') ⇒ IntToPtrInst
(also: #int2ptr)
Cast an int to a pointer.
- #integer_cast(val, type, name = '') ⇒ IntCastInst (also: #int_cast)
-
#invoke(fun, args, normal, exception, name = '') ⇒ InvokeInst
Invoke a function which may potentially unwind.
-
#is_not_null(val, name = '') ⇒ LLVM::Instruction
Check if a value is not null.
-
#is_null(val, name = '') ⇒ LLVM::Instruction
Check if a value is null.
-
#load(ptr, name = '') ⇒ LoadInst
Load the value of a given pointer.
-
#lshr(lhs, rhs, name = '') ⇒ ARightShiftInst
Logical (zero fill) shift right.
-
#malloc(type, name = '') ⇒ MallocInst
Heap allocation.
-
#mul(lhs, rhs, name = '') ⇒ MulInst
The integer product of the two operands.
-
#neg(val, name = '') ⇒ NegInst
Integer negation.
-
#not(val, name = '') ⇒ NotInst
Boolean negation.
-
#nsw_add(lhs, rhs, name = '') ⇒ NSWAddInst
No signed wrap addition.
-
#nsw_mul(lhs, rhs, name = '') ⇒ MulInst
No signed wrap multiplication.
-
#nsw_neg(val, name = '') ⇒ NegInst
No signed wrap integer negation.
-
#nsw_sub(lhs, rhs, name = '') ⇒ SubInst
No signed wrap subtraction.
-
#nuw_add(lhs, rhs, name = '') ⇒ NSWAddInst
No unsigned wrap addition.
-
#nuw_mul(lhs, rhs, name = '') ⇒ MulInst
No unsigned wrap multiplication.
-
#nuw_neg(val, name = '') ⇒ NegInst
No unsigned wrap integer negation.
-
#nuw_sub(lhs, rhs, name = '') ⇒ SubInst
No unsigned wrap subtraction.
-
#or(lhs, rhs, name = '') ⇒ OrInst
An integer instruction.
-
#phi(type, incoming, name = '') ⇒ PhiInst
Build a Phi node of the given type with the given incoming branches.
-
#position(bb, instruction) ⇒ Builder
Position the Builder after the given instruction.
-
#position_at_end(bb) ⇒ Bulder
(also: #pae, #target)
Position the Builder at the end of the given BasicBlock.
-
#position_before(instruction) ⇒ Builder
Position the Builder before the given Instruction.
- #ptr_cast(val, type, name = '') ⇒ PtrCastInst
-
#ptr_diff(lhs, rhs, name = '') ⇒ PtrDiffInst
Calculate the difference between two pointers.
-
#ptr_to_int(val, type, name = '') ⇒ PtrToIntInst
(also: #ptr2int)
Cast a pointer to an int.
- #ret(val) ⇒ ReturnInst
- #ret_aggregate(*vals) ⇒ RetAggregateInst
- #ret_void ⇒ RetVoidInst
-
#sdiv(lhs, rhs, name = '') ⇒ SDivInst
Signed integer division.
-
#select(if_val, then_val, else_val, name = '') ⇒ SelectInst
Return a value based on a condition.
-
#shift(dir, lhs, rhs, mode = :arithmetic, name = '') ⇒ LeftShiftInst, ...
A wrapper method around the #shift_left and #shift_right methods.
-
#shift_left(lhs, rhs, name = '') ⇒ LeftShiftInst
(also: #shl)
An integer instruction.
- #shift_right(lhs, rhs, mode = :arithmetic, name = '') ⇒ LeftShiftInst
-
#shuffle_vector(vec1, vec2, mask, name = '') ⇒ ShuffleVectorInst
Shuffle two vectors according to a given mask.
-
#sign_extend(val, type, name = '') ⇒ SignExtendInst
(also: #sext)
Sign extension by copying the sign bit (highest order bit) of the value until it reaches the bit size of the given type.
-
#sign_extend_or_bitcast(val, type, name = '') ⇒ SignExtendOrBitcastInst
(also: #sext_or_bitcast)
Sign extension or bitcast.
-
#signed_int_to_floating_point(val, type, name = '') ⇒ SIToFPInst
(also: #si2fp)
Convert a signed integer to a floating point.
-
#srem(lhs, rhs, name = '') ⇒ SRemInst
Signed remainder.
-
#store(val, ptr) ⇒ StoreInst
Store a value at a given pointer.
-
#struct_get_element_ptr(ptr, index, name = '') ⇒ StructGEPInst
(also: #struct_getp)
Builds a struct getelementptr instruction.
-
#sub(lhs, rhs, name = '') ⇒ SubInst
The integer difference of the two operands.
-
#switch(val, default, cases) ⇒ SwitchInst
Select a value based on an incoming value.
-
#truncate(val, type, name = '') ⇒ TruncateInst
(also: #trunc)
Truncates its operand to the given type.
-
#truncate_or_bitcast(val, type, name = '') ⇒ TruncateInst
Truncates or bitcast.
-
#udiv(lhs, rhs, name = '') ⇒ SDivInst
Unsigned integer division.
-
#unreachable ⇒ UnreachableInst
Generates an instruction with no defined semantics.
-
#unsigned_int_to_floating_point(val, type, name = '') ⇒ SIToFPInst
(also: #ui2fp)
Convert an unsigned integer to a floating point.
-
#urem(lhs, rhs, name = '') ⇒ SRemInst
Unsigned remainder.
-
#xor(lhs, rhs, name = '') ⇒ XOrInst
An integer instruction.
-
#zero_extend(val, type, name = '') ⇒ ZeroExtendInst
(also: #zext)
Zero extends its operand to the given type.
-
#zero_extend_or_bitcast(val, type, name = '') ⇒ ZeroExtendInst
(also: #zext_or_bitcast)
Zero extend or bitcast.
Methods included from BindingClass
Constructor Details
#initialize(bb = nil, *block_args, &block) ⇒ Builder
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.
39 40 41 42 43 44 45 46 47 |
# File 'lib/rltk/cg/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 |
Class Method Details
Instance Method Details
#add(lhs, rhs, name = '') ⇒ AddInst
Returns The integer sum of the two operands.
323 324 325 |
# File 'lib/rltk/cg/builder.rb', line 323 def add(lhs, rhs, name = '') AddInst.new(Bindings.build_add(@ptr, lhs, rhs, name)) end |
#addr_space_cast(val, type, name = '') ⇒ AddrSpaceCastInst
Cast a value to a given address space.
842 843 844 |
# File 'lib/rltk/cg/builder.rb', line 842 def addr_space_cast(val, type, name = '') AddrSpaceCast.new(Bindings.addr_space_cast(@ptr, val, check_cg_type(type), name)) end |
#alloca(type, name = '') ⇒ AllocaInst
Stack allocation.
701 702 703 |
# File 'lib/rltk/cg/builder.rb', line 701 def alloca(type, name = '') AllocaInst.new(Bindings.build_alloca(@ptr, check_cg_type(type), name)) end |
#and(lhs, rhs, name = '') ⇒ AndInst
Returns An integer instruction.
638 639 640 |
# File 'lib/rltk/cg/builder.rb', line 638 def and(lhs, rhs, name = '') AndInst.new(Bindings.build_and(@ptr, lhs, rhs, name)) end |
#array_alloca(type, size, name = '') ⇒ ArrayAllocaInst
Stack array allocation.
712 713 714 |
# File 'lib/rltk/cg/builder.rb', line 712 def array_alloca(type, size, name = '') ArrayAllocaInst.new(Bindings.build_array_alloca(@ptr, check_cg_type(type), size, name)) end |
#array_malloc(type, size, name = '') ⇒ ArrayMallocInst
Heap array allocation.
691 692 693 |
# File 'lib/rltk/cg/builder.rb', line 691 def array_malloc(type, size, name = '') ArrayMallocInst.new(Bindings.build_array_malloc(@ptr, check_cg_type(type), size, name)) end |
#ashr(lhs, rhs, name = '') ⇒ ARightShiftInst
Arithmetic (sign extended) shift right.
618 619 620 |
# File 'lib/rltk/cg/builder.rb', line 618 def ashr(lhs, rhs, name = '') ARightShiftInst.new(Bindings.build_a_shr(@ptr, lhs, rhs, name)) end |
#atomic_rmw(op, addr, val, ordering, single_thread) ⇒ AtomicRMWInst
Create an atomic read/modify/write instruction.
827 828 829 |
# File 'lib/rltk/cg/builder.rb', line 827 def atomic_rmw(op, addr, val, ordering, single_thread) AtomicRMWInst.new(Bindings.build_atomic_rmw(@ptr, op, addr, val, ordering, single_thread.to_i)) end |
#bitcast(val, type, name = '') ⇒ BitCastInst
Cast a value to the given type without changing any bits.
853 854 855 |
# File 'lib/rltk/cg/builder.rb', line 853 def bitcast(val, type, name = '') BitCastInst.new(Bindings.build_bit_cast(@ptr, val, check_cg_type(type), name)) end |
#branch(block) ⇒ BranchInst Also known as: br
Unconditional branching.
164 165 166 |
# File 'lib/rltk/cg/builder.rb', line 164 def branch(block) BranchInst.new(Bindings.build_br(@ptr, block)) end |
#build(bb = nil, *block_args, &block) ⇒ Object
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.
58 59 60 61 |
# File 'lib/rltk/cg/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_inst(inst, *args) ⇒ Instruction Also known as: <<
Build an instruction.
69 70 71 |
# File 'lib/rltk/cg/builder.rb', line 69 def build_inst(inst, *args) self.send(inst, *args) end |
#call(fun, *args) ⇒ CallInst
Build an instruction that performs a function call.
175 176 177 178 179 180 181 182 |
# File 'lib/rltk/cg/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 |
#cond_branch(val, iftrue, iffalse) ⇒ CondBranchInst Also known as: cond
Conditional branching.
191 192 193 |
# File 'lib/rltk/cg/builder.rb', line 191 def cond_branch(val, iftrue, iffalse) CondBranchInst.new(Bindings.build_cond_br(@ptr, val, iftrue, iffalse)) end |
#current_block ⇒ BasicBlock Also known as: insertion_block
Returns BasicBlock the Builder is currently positioned on.
116 117 118 |
# File 'lib/rltk/cg/builder.rb', line 116 def current_block BasicBlock.new(Bindings.get_insert_block(@ptr)) end |
#exact_sdiv(lhs, rhs, name = '') ⇒ SDivInst
Signed exact integer division.
471 472 473 |
# File 'lib/rltk/cg/builder.rb', line 471 def exact_sdiv(lhs, rhs, name = '') ExactSDivInst.new(Bindings.build_exact_s_div(@ptr, lhs, rhs, name)) end |
#extract_element(vector, index, name = '') ⇒ ExtractElementInst
Extract an element from a vector.
203 204 205 |
# File 'lib/rltk/cg/builder.rb', line 203 def extract_element(vector, index, name = '') ExtractElementInst.new(Bindings.build_extract_element(@ptr, vector, index, name)) end |
#extract_value(aggregate, index, name = '') ⇒ ExtractValueInst
Extract the value of a member field from an aggregate value.
214 215 216 |
# File 'lib/rltk/cg/builder.rb', line 214 def extract_value(aggregate, index, name = '') ExtractValueInst.new(Bindings.build_extract_value(@ptr, aggregate, index, name)) end |
#fadd(lhs, rhs, name = '') ⇒ FAddInst
Returns The floating point sum of the two operands.
332 333 334 |
# File 'lib/rltk/cg/builder.rb', line 332 def fadd(lhs, rhs, name = '') FAddInst.new(Bindings.build_f_add(@ptr, lhs, rhs, name)) end |
#fdiv(lhs, rhs, name = '') ⇒ FDivInst
Returns The floating point quotient of the two operands.
449 450 451 |
# File 'lib/rltk/cg/builder.rb', line 449 def fdiv(lhs, rhs, name = '') FDivInst.new(Bindings.build_f_div(@ptr, lhs, rhs, name)) end |
#floating_point_cast(val, type, name = '') ⇒ FPCastInst Also known as: fp_cast
Returns A value of the target type.
862 863 864 |
# File 'lib/rltk/cg/builder.rb', line 862 def floating_point_cast(val, type, name = '') FPCastInst.new(Bindings.build_fp_cast(@ptr, val, check_cg_type(type), name)) end |
#floating_point_extend(val, type, name = '') ⇒ FPExtendInst Also known as: fp_ext, fp_extend
Extend a floating point value.
874 875 876 |
# File 'lib/rltk/cg/builder.rb', line 874 def floating_point_extend(val, type, name = '') FPExtendInst.new(Bindings.build_fp_ext(@ptr, val, check_cg_type(type), name)) end |
#floating_point_to_signed_int(val, type, name = '') ⇒ FPToSIInst Also known as: fp2si
Convert a floating point to a signed integer.
887 888 889 |
# File 'lib/rltk/cg/builder.rb', line 887 def floating_point_to_signed_int(val, type, name = '') FPToSIInst.new(Bindings.build_fp_to_si(@ptr, val, check_cg_type(type), name)) end |
#floating_point_to_unsigned_int(val, type, name = '') ⇒ FPToSIInst Also known as: fp2ui
Convert a floating point to an unsigned integer.
899 900 901 |
# File 'lib/rltk/cg/builder.rb', line 899 def floating_point_to_unsigned_int(val, type, name = '') FPToUIInst.new(Bindings.build_fp_to_ui(@ptr, val, check_cg_type(type), name)) end |
#floating_point_truncate(val, type, name = '') ⇒ LLVM::Instruction Also known as: fp_trunc, fp_truncate
Truncate a floating point value.
911 912 913 |
# File 'lib/rltk/cg/builder.rb', line 911 def floating_point_truncate(val, type, name = '') FPTruncInst.new(Bindings.build_fp_trunc(@ptr, val, check_cg_type(type), name)) end |
#fmul(lhs, rhs, name = '') ⇒ FMulInst
Returns The floating point product of the two operands.
416 417 418 |
# File 'lib/rltk/cg/builder.rb', line 416 def fmul(lhs, rhs, name = '') FMulInst.new(Bindings.build_f_mul(@ptr, lhs, rhs, name)) end |
#fneg(val, name = '') ⇒ NegInst
Floating point negation. Implemented as a shortcut to the equivalent sub instruction.
539 540 541 |
# File 'lib/rltk/cg/builder.rb', line 539 def fneg(val, name = '') FNegInst.new(Bindings.build_f_neg(@ptr, val, name)) end |
#fp_comparison(pred, lhs, rhs, name = '') ⇒ FCmpInst Also known as: fcmp
Builds an fcmp instruction. Compares lhs to rhs as reals using the given symbol predicate.
1091 1092 1093 |
# File 'lib/rltk/cg/builder.rb', line 1091 def fp_comparison(pred, lhs, rhs, name = '') FCmpInst.new(Bindings.build_f_cmp(@ptr, pred, lhs, rhs, name)) end |
#free(ptr) ⇒ FreeInst
Returns The result of the free instruction.
719 720 721 |
# File 'lib/rltk/cg/builder.rb', line 719 def free(ptr) FreeInst.new(Bindings.build_free(@ptr, ptr)) end |
#frem(lhs, rhs, name = '') ⇒ FRemInst
Returns The floating point remainder.
493 494 495 |
# File 'lib/rltk/cg/builder.rb', line 493 def frem(lhs, rhs, name = '') FRemInst.new(Bindings.build_f_rem(@ptr, lhs, rhs, name)) end |
#fsub(lhs, rhs, name = '') ⇒ FSubInst
Returns The floating point difference of the two operands.
374 375 376 |
# File 'lib/rltk/cg/builder.rb', line 374 def fsub(lhs, rhs, name = '') FSubInst.new(Bindings.build_f_sub(@ptr, lhs, rhs, name)) end |
#get_element_ptr(ptr, indices, name = '') ⇒ GetElementPtrInst Also known as: gep
Obtain a pointer to the element at the given indices.
751 752 753 754 755 756 757 758 |
# File 'lib/rltk/cg/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 |
#get_element_ptr_in_bounds(ptr, indices, name = '') ⇒ InBoundsGEPInst Also known as: inbounds_gep
Builds a in-bounds getelementptr instruction. If the indices are outside the allocated pointer the value is undefined.
770 771 772 773 774 775 776 777 |
# File 'lib/rltk/cg/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 |
#gloabl_string_pointer(string, name = '') ⇒ GlobalStringPtrInst
Creates a pointer to a global string initialized to a given value.
808 809 810 |
# File 'lib/rltk/cg/builder.rb', line 808 def gloabl_string_pointer(string, name = '') GlobalStringPtrInst.new(Bindings.build_global_string_ptr(@ptr, string, name)) end |
#global_string(string, name = '') ⇒ GlobalStringInst
Creates a global string initialized to a given value.
798 799 800 |
# File 'lib/rltk/cg/builder.rb', line 798 def global_string(string, name = '') GlobalStringInst.new(Bindings.build_global_string(@ptr, string, name)) end |
#insert_element(vector, element, index, name = '') ⇒ InsertElementInst
Insert an element into a vector.
226 227 228 |
# File 'lib/rltk/cg/builder.rb', line 226 def insert_element(vector, element, index, name = '') InsertElementInst.new(Bindings.build_insert_element(@ptr, vector, element, index, name)) end |
#insert_value(aggregate, val, index, name = '') ⇒ InsertValueInst
Insert a value into an aggregate value’s member field.
238 239 240 |
# File 'lib/rltk/cg/builder.rb', line 238 def insert_value(aggregate, val, index, name = '') InsertValueInst.new(Bindings.build_insert_value(@ptr, aggregate, val, index, name)) end |
#int_comparison(pred, lhs, rhs, name = '') ⇒ IntCmpInst Also known as: icmp
Builds an icmp instruction. Compares lhs to rhs using the given symbol predicate.
1074 1075 1076 |
# File 'lib/rltk/cg/builder.rb', line 1074 def int_comparison(pred, lhs, rhs, name = '') IntCmpInst.new(Bindings.build_i_cmp(@ptr, pred, lhs, rhs, name)) end |
#int_to_ptr(val, type, name = '') ⇒ IntToPtrInst Also known as: int2ptr
Cast an int to a pointer.
924 925 926 |
# File 'lib/rltk/cg/builder.rb', line 924 def int_to_ptr(val, type, name = '') IntToPtrInst.new(Bindings.build_int_to_ptr(@ptr, val, check_cg_type(type), name)) end |
#integer_cast(val, type, name = '') ⇒ IntCastInst Also known as: int_cast
934 935 936 |
# File 'lib/rltk/cg/builder.rb', line 934 def integer_cast(val, type, name = '') IntCastInst.new(Bindings.build_int_cast(@ptr, val, check_cg_type(type), name)) end |
#invoke(fun, args, normal, exception, name = '') ⇒ InvokeInst
Invoke a function which may potentially unwind.
251 252 253 |
# File 'lib/rltk/cg/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 |
#is_not_null(val, name = '') ⇒ LLVM::Instruction
Check if a value is not null.
1113 1114 1115 |
# File 'lib/rltk/cg/builder.rb', line 1113 def is_not_null(val, name = '') IsNotNullInst.new(Builder.build_is_not_null(@ptr, val, name)) end |
#is_null(val, name = '') ⇒ LLVM::Instruction
Check if a value is null.
1123 1124 1125 |
# File 'lib/rltk/cg/builder.rb', line 1123 def is_null(val, name = '') IsNullInst.new(Bindings.build_is_null(@ptr, val, name)) end |
#load(ptr, name = '') ⇒ LoadInst
Load the value of a given pointer.
729 730 731 |
# File 'lib/rltk/cg/builder.rb', line 729 def load(ptr, name = '') LoadInst.new(Bindings.build_load(@ptr, ptr, name)) end |
#lshr(lhs, rhs, name = '') ⇒ ARightShiftInst
Logical (zero fill) shift right.
629 630 631 |
# File 'lib/rltk/cg/builder.rb', line 629 def lshr(lhs, rhs, name = '') LRightShiftInst.new(Bindings.build_l_shr(@ptr, lhs, rhs, name)) end |
#malloc(type, name = '') ⇒ MallocInst
Heap allocation.
680 681 682 |
# File 'lib/rltk/cg/builder.rb', line 680 def malloc(type, name = '') MallocInst.new(Bindings.build_malloc(@ptr, check_type(type), name)) end |
#mul(lhs, rhs, name = '') ⇒ MulInst
Returns The integer product of the two operands.
407 408 409 |
# File 'lib/rltk/cg/builder.rb', line 407 def mul(lhs, rhs, name = '') MulInst.new(Bindings.build_mul(@ptr, lhs, rhs, name)) end |
#neg(val, name = '') ⇒ NegInst
Integer negation. Implemented as a shortcut to the equivalent sub instruction.
528 529 530 |
# File 'lib/rltk/cg/builder.rb', line 528 def neg(val, name = '') NegInst.new(Bindings.build_neg(@ptr, val, name)) end |
#not(val, name = '') ⇒ NotInst
Boolean negation.
666 667 668 |
# File 'lib/rltk/cg/builder.rb', line 666 def not(val, name = '') NotInst.new(Bindings.build_not(@ptr, val, name)) end |
#nsw_add(lhs, rhs, name = '') ⇒ NSWAddInst
No signed wrap addition.
343 344 345 |
# File 'lib/rltk/cg/builder.rb', line 343 def nsw_add(lhs, rhs, name = '') NSWAddInst.new(Bindings.build_nsw_add(@ptr, lhs, rhs, name)) end |
#nsw_mul(lhs, rhs, name = '') ⇒ MulInst
No signed wrap multiplication.
427 428 429 |
# File 'lib/rltk/cg/builder.rb', line 427 def nsw_mul(lhs, rhs, name = '') NSWMulInst.new(Bindings.build_nsw_mul(@ptr, lhs, rhs, name)) end |
#nsw_neg(val, name = '') ⇒ NegInst
No signed wrap integer negation. Implemented as a shortcut to the equivalent sub instruction.
550 551 552 |
# File 'lib/rltk/cg/builder.rb', line 550 def nsw_neg(val, name = '') NSWNegInst.new(Bindings.build_nsw_neg(@ptr, val, name)) end |
#nsw_sub(lhs, rhs, name = '') ⇒ SubInst
No signed wrap subtraction.
385 386 387 |
# File 'lib/rltk/cg/builder.rb', line 385 def nsw_sub(lhs, rhs, name = '') NSWSubInst.new(Bindings.build_nsw_sub(@ptr, lhs, rhs, name)) end |
#nuw_add(lhs, rhs, name = '') ⇒ NSWAddInst
No unsigned wrap addition.
354 355 356 |
# File 'lib/rltk/cg/builder.rb', line 354 def nuw_add(lhs, rhs, name = '') NUWAddInst.new(Bindings.build_nuw_add(@ptr, lhs, rhs, name)) end |
#nuw_mul(lhs, rhs, name = '') ⇒ MulInst
No unsigned wrap multiplication.
438 439 440 |
# File 'lib/rltk/cg/builder.rb', line 438 def nuw_mul(lhs, rhs, name = '') NUWMulInst.new(Bindings.build_nuw_mul(@ptr, lhs, rhs, name)) end |
#nuw_neg(val, name = '') ⇒ NegInst
No unsigned wrap integer negation. Implemented as a shortcut to the equivalent sub instruction.
561 562 563 |
# File 'lib/rltk/cg/builder.rb', line 561 def nuw_neg(val, name = '') NUWNegInst.new(Bindings.build_nuw_neg(@ptr, val, name)) end |
#nuw_sub(lhs, rhs, name = '') ⇒ SubInst
No unsigned wrap subtraction.
396 397 398 |
# File 'lib/rltk/cg/builder.rb', line 396 def nuw_sub(lhs, rhs, name = '') NUWSubInst.new(Bindings.build_nuw_sub(@ptr, lhs, rhs, name)) end |
#or(lhs, rhs, name = '') ⇒ OrInst
Returns An integer instruction.
647 648 649 |
# File 'lib/rltk/cg/builder.rb', line 647 def or(lhs, rhs, name = '') OrInst.new(Bindings.build_or(@ptr, lhs, rhs, name)) end |
#phi(type, incoming, name = '') ⇒ PhiInst
Build a Phi node of the given type with the given incoming branches.
265 266 267 268 269 |
# File 'lib/rltk/cg/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(bb, instruction) ⇒ Builder
Position the Builder after the given instruction.
80 81 82 83 |
# File 'lib/rltk/cg/builder.rb', line 80 def position(bb, instruction) Bindings.position_builder(@ptr, bb, instruction) if check_type(bb, BasicBlock, 'bb') self end |
#position_at_end(bb) ⇒ Bulder Also known as: pae, target
Position the Builder at the end of the given BasicBlock.
90 91 92 93 |
# File 'lib/rltk/cg/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_before(instruction) ⇒ Builder
Position the Builder before the given Instruction.
102 103 104 105 |
# File 'lib/rltk/cg/builder.rb', line 102 def position_before(instruction) Bindings.position_builder_before(@ptr, instruction) self end |
#ptr_cast(val, type, name = '') ⇒ PtrCastInst
944 945 946 |
# File 'lib/rltk/cg/builder.rb', line 944 def ptr_cast(val, type, name = '') PtrCastInst.new(Bindings.build_pointer_cast(@ptr, val, check_cg_type(type), name)) end |
#ptr_diff(lhs, rhs, name = '') ⇒ PtrDiffInst
Calculate the difference between two pointers.
1103 1104 1105 |
# File 'lib/rltk/cg/builder.rb', line 1103 def ptr_diff(lhs, rhs, name = '') PtrDiffInst.new(Bindings.build_ptr_diff(lhs, rhs, name)) end |
#ptr_to_int(val, type, name = '') ⇒ PtrToIntInst Also known as: ptr2int
Cast a pointer to an int. Useful for pointer arithmetic.
955 956 957 |
# File 'lib/rltk/cg/builder.rb', line 955 def ptr_to_int(val, type, name = '') PtrToIntInst.new(Bindings.build_ptr_to_int(@ptr, val, check_cg_type(type), name)) end |
#ret(val) ⇒ ReturnInst
136 137 138 |
# File 'lib/rltk/cg/builder.rb', line 136 def ret(val) ReturnInst.new(Bindings.build_ret(@ptr, val)) end |
#ret_aggregate(*vals) ⇒ RetAggregateInst
146 147 148 149 150 151 152 153 |
# File 'lib/rltk/cg/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 |
#ret_void ⇒ RetVoidInst
141 142 143 |
# File 'lib/rltk/cg/builder.rb', line 141 def ret_void ReturnVoidInst.new(Bindings.build_ret_void(@ptr)) end |
#sdiv(lhs, rhs, name = '') ⇒ SDivInst
Signed integer division.
460 461 462 |
# File 'lib/rltk/cg/builder.rb', line 460 def sdiv(lhs, rhs, name = '') SDivInst.new(Bindings.build_s_div(@ptr, lhs, rhs, name)) end |
#select(if_val, then_val, else_val, name = '') ⇒ SelectInst
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.
282 283 284 |
# File 'lib/rltk/cg/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 |
#shift(dir, lhs, rhs, mode = :arithmetic, name = '') ⇒ LeftShiftInst, ...
A wrapper method around the #shift_left and #shift_right methods.
579 580 581 582 583 584 |
# File 'lib/rltk/cg/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 |
#shift_left(lhs, rhs, name = '') ⇒ LeftShiftInst Also known as: shl
Returns An integer instruction.
591 592 593 |
# File 'lib/rltk/cg/builder.rb', line 591 def shift_left(lhs, rhs, name = '') LeftShiftInst.new(Bindings.build_shl(@ptr, lhs, rhs, name)) end |
#shift_right(lhs, rhs, mode = :arithmetic, name = '') ⇒ LeftShiftInst
604 605 606 607 608 609 |
# File 'lib/rltk/cg/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_vector(vec1, vec2, mask, name = '') ⇒ ShuffleVectorInst
Shuffle two vectors according to a given mask.
294 295 296 |
# File 'lib/rltk/cg/builder.rb', line 294 def shuffle_vector(vec1, vec2, mask, name = '') ShuffleVectorInst.new(Bindings.build_shuffle_vector(@ptr, vec1, vec2, mask, name)) end |
#sign_extend(val, type, name = '') ⇒ SignExtendInst Also known as: sext
Sign extension by copying the sign bit (highest order bit) of the value until it reaches the bit size of the given type.
968 969 970 |
# File 'lib/rltk/cg/builder.rb', line 968 def sign_extend(val, type, name = '') SignExtendInst.new(Bindings.build_s_ext(@ptr, val, check_cg_type(type), name)) end |
#sign_extend_or_bitcast(val, type, name = '') ⇒ SignExtendOrBitcastInst Also known as: sext_or_bitcast
Sign extension or bitcast.
980 981 982 |
# File 'lib/rltk/cg/builder.rb', line 980 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 |
#signed_int_to_floating_point(val, type, name = '') ⇒ SIToFPInst Also known as: si2fp
Convert a signed integer to a floating point.
992 993 994 |
# File 'lib/rltk/cg/builder.rb', line 992 def signed_int_to_floating_point(val, type, name = '') SIToFPInst.new(Bindings.build_si_to_fp(@ptr, val, check_cg_type(type), name)) end |
#srem(lhs, rhs, name = '') ⇒ SRemInst
Signed remainder.
504 505 506 |
# File 'lib/rltk/cg/builder.rb', line 504 def srem(lhs, rhs, name = '') SRemInst.new(Bindings.build_s_rem(@ptr, lhs, rhs, name)) end |
#store(val, ptr) ⇒ StoreInst
Store a value at a given pointer.
739 740 741 |
# File 'lib/rltk/cg/builder.rb', line 739 def store(val, ptr) StoreInst.new(Bindings.build_store(@ptr, val, ptr)) end |
#struct_get_element_ptr(ptr, index, name = '') ⇒ StructGEPInst Also known as: struct_getp
Builds a struct getelementptr instruction.
787 788 789 |
# File 'lib/rltk/cg/builder.rb', line 787 def struct_get_element_ptr(ptr, index, name = '') StructGEPInst.new(Bindings.build_struct_gep(@ptr, ptr, index, name)) end |
#sub(lhs, rhs, name = '') ⇒ SubInst
Returns The integer difference of the two operands.
365 366 367 |
# File 'lib/rltk/cg/builder.rb', line 365 def sub(lhs, rhs, name = '') SubInst.new(Bindings.build_sub(@ptr, lhs, rhs, name)) end |
#switch(val, default, cases) ⇒ SwitchInst
Select a value based on an incoming value.
306 307 308 309 310 |
# File 'lib/rltk/cg/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 |
#truncate(val, type, name = '') ⇒ TruncateInst Also known as: trunc
Truncates its operand to the given type. The size of the value type must be greater than the size of the target type.
1005 1006 1007 |
# File 'lib/rltk/cg/builder.rb', line 1005 def truncate(val, type, name = '') TruncateInst.new(Bindings.build_trunc(@ptr, val, check_cg_type(type), name)) end |
#truncate_or_bitcast(val, type, name = '') ⇒ TruncateInst
Truncates or bitcast.
1017 1018 1019 |
# File 'lib/rltk/cg/builder.rb', line 1017 def truncate_or_bitcast(val, type, name = '') TruncateOrBitCastInst.new(Bindings.build_trunc_or_bit_cast(@ptr, val, check_cg_type(type), name)) end |
#udiv(lhs, rhs, name = '') ⇒ SDivInst
Unsigned integer division.
482 483 484 |
# File 'lib/rltk/cg/builder.rb', line 482 def udiv(lhs, rhs, name = '') UDivInst.new(Bindings.build_u_div(@ptr, lhs, rhs, name)) end |
#unreachable ⇒ UnreachableInst
Generates an instruction with no defined semantics. Can be used to provide hints to the optimizer.
125 126 127 |
# File 'lib/rltk/cg/builder.rb', line 125 def unreachable UnreachableInst.new(Bindings.build_unreachable(@ptr)) end |
#unsigned_int_to_floating_point(val, type, name = '') ⇒ SIToFPInst Also known as: ui2fp
Convert an unsigned integer to a floating point.
1028 1029 1030 |
# File 'lib/rltk/cg/builder.rb', line 1028 def unsigned_int_to_floating_point(val, type, name = '') UIToFPInst.new(Bindings.build_ui_to_fp(@ptr, val, check_cg_type(type), name)) end |
#urem(lhs, rhs, name = '') ⇒ SRemInst
Unsigned remainder.
515 516 517 |
# File 'lib/rltk/cg/builder.rb', line 515 def urem(lhs, rhs, name = '') URemInst.new(Bindings.build_u_rem(@ptr, lhs, rhs, name)) end |
#xor(lhs, rhs, name = '') ⇒ XOrInst
Returns An integer instruction.
656 657 658 |
# File 'lib/rltk/cg/builder.rb', line 656 def xor(lhs, rhs, name = '') XOrInst.new(Bindings.build_xor(@ptr, lhs, rhs, name)) end |
#zero_extend(val, type, name = '') ⇒ ZeroExtendInst Also known as: zext
Zero extends its operand to the given type. The size of the value type must be greater than the size of the target type.
1041 1042 1043 |
# File 'lib/rltk/cg/builder.rb', line 1041 def zero_extend(val, type, name = '') ZeroExtendInst.new(Bindings.build_z_ext(@ptr, val, check_cg_type(type), name)) end |
#zero_extend_or_bitcast(val, type, name = '') ⇒ ZeroExtendInst Also known as: zext_or_bitcast
Zero extend or bitcast.
1053 1054 1055 |
# File 'lib/rltk/cg/builder.rb', line 1053 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 |