Class: RLTK::CG::Builder
- Includes:
- BindingClass
- Defined in:
- lib/rltk/cg/builder.rb
Overview
This class is responsible for adding Instructions to BasicBlocks.
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.
-
#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.
-
#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
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.
321 322 323 |
# File 'lib/rltk/cg/builder.rb', line 321 def add(lhs, rhs, name = '') AddInst.new(Bindings.build_add(@ptr, lhs, rhs, name)) end |
#alloca(type, name = '') ⇒ AllocaInst
Stack allocation.
699 700 701 |
# File 'lib/rltk/cg/builder.rb', line 699 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.
636 637 638 |
# File 'lib/rltk/cg/builder.rb', line 636 def and(lhs, rhs, name = '') AndInst.new(Bindings.build_and(@ptr, lhs, rhs, name)) end |
#array_alloca(type, size, name = '') ⇒ ArrayAllocaInst
Stack array allocation.
710 711 712 |
# File 'lib/rltk/cg/builder.rb', line 710 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.
689 690 691 |
# File 'lib/rltk/cg/builder.rb', line 689 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.
616 617 618 |
# File 'lib/rltk/cg/builder.rb', line 616 def ashr(lhs, rhs, name = '') ARightShiftInst.new(Bindings.build_a_shr(@ptr, lhs, rhs, name)) end |
#bitcast(val, type, name = '') ⇒ BitCastInst
Cast a value to the given type without changing any bits.
821 822 823 |
# File 'lib/rltk/cg/builder.rb', line 821 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.
162 163 164 |
# File 'lib/rltk/cg/builder.rb', line 162 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.to_sym, *args) end |
#call(fun, *args) ⇒ CallInst
Build an instruction that performs a function call.
173 174 175 176 177 178 179 180 |
# File 'lib/rltk/cg/builder.rb', line 173 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.
189 190 191 |
# File 'lib/rltk/cg/builder.rb', line 189 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.
114 115 116 |
# File 'lib/rltk/cg/builder.rb', line 114 def current_block BasicBlock.new(Bindings.get_insert_block(@ptr)) end |
#exact_sdiv(lhs, rhs, name = '') ⇒ SDivInst
Signed exact integer division.
469 470 471 |
# File 'lib/rltk/cg/builder.rb', line 469 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.
201 202 203 |
# File 'lib/rltk/cg/builder.rb', line 201 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.
212 213 214 |
# File 'lib/rltk/cg/builder.rb', line 212 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.
330 331 332 |
# File 'lib/rltk/cg/builder.rb', line 330 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.
447 448 449 |
# File 'lib/rltk/cg/builder.rb', line 447 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.
830 831 832 |
# File 'lib/rltk/cg/builder.rb', line 830 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.
842 843 844 |
# File 'lib/rltk/cg/builder.rb', line 842 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.
855 856 857 |
# File 'lib/rltk/cg/builder.rb', line 855 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.
867 868 869 |
# File 'lib/rltk/cg/builder.rb', line 867 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.
879 880 881 |
# File 'lib/rltk/cg/builder.rb', line 879 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.
414 415 416 |
# File 'lib/rltk/cg/builder.rb', line 414 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.
537 538 539 |
# File 'lib/rltk/cg/builder.rb', line 537 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.
1059 1060 1061 |
# File 'lib/rltk/cg/builder.rb', line 1059 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.
717 718 719 |
# File 'lib/rltk/cg/builder.rb', line 717 def free(ptr) FreeInst.new(Bindings.build_free(@ptr, ptr)) end |
#frem(lhs, rhs, name = '') ⇒ FRemInst
Returns The floating point remainder.
491 492 493 |
# File 'lib/rltk/cg/builder.rb', line 491 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.
372 373 374 |
# File 'lib/rltk/cg/builder.rb', line 372 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.
749 750 751 752 753 754 755 756 |
# File 'lib/rltk/cg/builder.rb', line 749 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.
768 769 770 771 772 773 774 775 |
# File 'lib/rltk/cg/builder.rb', line 768 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.
806 807 808 |
# File 'lib/rltk/cg/builder.rb', line 806 def gloabl_string_pointer(string, name = '') GlobalStringPtrInst(Bindings.build_global_string_ptr(@ptr, string, name)) end |
#global_string(string, name = '') ⇒ GlobalStringInst
Creates a global string initialized to a given value.
796 797 798 |
# File 'lib/rltk/cg/builder.rb', line 796 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.
224 225 226 |
# File 'lib/rltk/cg/builder.rb', line 224 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.
236 237 238 |
# File 'lib/rltk/cg/builder.rb', line 236 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.
1042 1043 1044 |
# File 'lib/rltk/cg/builder.rb', line 1042 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.
892 893 894 |
# File 'lib/rltk/cg/builder.rb', line 892 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
902 903 904 |
# File 'lib/rltk/cg/builder.rb', line 902 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.
249 250 251 |
# File 'lib/rltk/cg/builder.rb', line 249 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.
1081 1082 1083 |
# File 'lib/rltk/cg/builder.rb', line 1081 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.
1091 1092 1093 |
# File 'lib/rltk/cg/builder.rb', line 1091 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.
727 728 729 |
# File 'lib/rltk/cg/builder.rb', line 727 def load(ptr, name = '') LoadInst.new(Bindings.build_load(@ptr, ptr, name)) end |
#lshr(lhs, rhs, name = '') ⇒ ARightShiftInst
Logical (zero fill) shift right.
627 628 629 |
# File 'lib/rltk/cg/builder.rb', line 627 def lshr(lhs, rhs, name = '') LRightShiftInst.new(Bindings.build_l_shr(@ptr, lhs, rhs, name)) end |
#malloc(type, name = '') ⇒ MallocInst
Heap allocation.
678 679 680 |
# File 'lib/rltk/cg/builder.rb', line 678 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.
405 406 407 |
# File 'lib/rltk/cg/builder.rb', line 405 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.
526 527 528 |
# File 'lib/rltk/cg/builder.rb', line 526 def neg(val, name = '') NegInst.new(Bindings.build_neg(@ptr, val, name)) end |
#not(val, name = '') ⇒ NotInst
Boolean negation.
664 665 666 |
# File 'lib/rltk/cg/builder.rb', line 664 def not(val, name = '') NotInst.new(Bindings.build_not(@ptr, val, name)) end |
#nsw_add(lhs, rhs, name = '') ⇒ NSWAddInst
No signed wrap addition.
341 342 343 |
# File 'lib/rltk/cg/builder.rb', line 341 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.
425 426 427 |
# File 'lib/rltk/cg/builder.rb', line 425 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.
548 549 550 |
# File 'lib/rltk/cg/builder.rb', line 548 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.
383 384 385 |
# File 'lib/rltk/cg/builder.rb', line 383 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.
352 353 354 |
# File 'lib/rltk/cg/builder.rb', line 352 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.
436 437 438 |
# File 'lib/rltk/cg/builder.rb', line 436 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.
559 560 561 |
# File 'lib/rltk/cg/builder.rb', line 559 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.
394 395 396 |
# File 'lib/rltk/cg/builder.rb', line 394 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.
645 646 647 |
# File 'lib/rltk/cg/builder.rb', line 645 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.
263 264 265 266 267 |
# File 'lib/rltk/cg/builder.rb', line 263 def phi(type, incoming, name = '') returning PhiInst.new(Bindings.build_phi(@ptr, check_cg_type(type), name)) 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
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.
100 101 102 103 |
# File 'lib/rltk/cg/builder.rb', line 100 def position_before(instruction) Bindings.position_builder_before(@ptr, instruction) self end |
#ptr_cast(val, type, name = '') ⇒ PtrCastInst
912 913 914 |
# File 'lib/rltk/cg/builder.rb', line 912 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.
1071 1072 1073 |
# File 'lib/rltk/cg/builder.rb', line 1071 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.
923 924 925 |
# File 'lib/rltk/cg/builder.rb', line 923 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
134 135 136 |
# File 'lib/rltk/cg/builder.rb', line 134 def ret(val) ReturnInst.new(Bindings.build_ret(@ptr, val)) end |
#ret_aggregate(*vals) ⇒ RetAggregateInst
144 145 146 147 148 149 150 151 |
# File 'lib/rltk/cg/builder.rb', line 144 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
139 140 141 |
# File 'lib/rltk/cg/builder.rb', line 139 def ret_void ReturnVoidInst.new(Bindings.build_ret_void(@ptr)) end |
#sdiv(lhs, rhs, name = '') ⇒ SDivInst
Signed integer division.
458 459 460 |
# File 'lib/rltk/cg/builder.rb', line 458 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.
280 281 282 |
# File 'lib/rltk/cg/builder.rb', line 280 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.
577 578 579 580 581 582 |
# File 'lib/rltk/cg/builder.rb', line 577 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.
589 590 591 |
# File 'lib/rltk/cg/builder.rb', line 589 def shift_left(lhs, rhs, name = '') LeftShiftInst.new(Bindings.build_shl(@ptr, lhs, rhs, name)) end |
#shift_right(lhs, rhs, mode = :arithmetic, name = '') ⇒ LeftShiftInst
602 603 604 605 606 607 |
# File 'lib/rltk/cg/builder.rb', line 602 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.
292 293 294 |
# File 'lib/rltk/cg/builder.rb', line 292 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.
936 937 938 |
# File 'lib/rltk/cg/builder.rb', line 936 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.
948 949 950 |
# File 'lib/rltk/cg/builder.rb', line 948 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.
960 961 962 |
# File 'lib/rltk/cg/builder.rb', line 960 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.
502 503 504 |
# File 'lib/rltk/cg/builder.rb', line 502 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.
737 738 739 |
# File 'lib/rltk/cg/builder.rb', line 737 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.
785 786 787 |
# File 'lib/rltk/cg/builder.rb', line 785 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.
363 364 365 |
# File 'lib/rltk/cg/builder.rb', line 363 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.
304 305 306 307 308 |
# File 'lib/rltk/cg/builder.rb', line 304 def switch(val, default, cases) returning SwitchInst.new(Bindings.build_switch(@ptr, val, default, cases.size)) 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.
973 974 975 |
# File 'lib/rltk/cg/builder.rb', line 973 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.
985 986 987 |
# File 'lib/rltk/cg/builder.rb', line 985 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.
480 481 482 |
# File 'lib/rltk/cg/builder.rb', line 480 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.
123 124 125 |
# File 'lib/rltk/cg/builder.rb', line 123 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.
996 997 998 |
# File 'lib/rltk/cg/builder.rb', line 996 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.
513 514 515 |
# File 'lib/rltk/cg/builder.rb', line 513 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.
654 655 656 |
# File 'lib/rltk/cg/builder.rb', line 654 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.
1009 1010 1011 |
# File 'lib/rltk/cg/builder.rb', line 1009 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.
1021 1022 1023 |
# File 'lib/rltk/cg/builder.rb', line 1021 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 |