Class: LLVM::Builder
- Inherits:
-
Object
- Object
- LLVM::Builder
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/llvm/core/builder.rb
Instance Method Summary collapse
-
#add(lhs, rhs, name = "") ⇒ LLVM::Instruction
Integer addition.
-
#aggregate_ret(*vals) ⇒ LLVM::Instruction
Builds a ret instruction returning multiple values.
-
#alloca(ty, name = "") ⇒ LLVM::Instruction
Stack allocation.
-
#and(lhs, rhs, name = "") ⇒ LLVM::Instruction
An integer instruction.
-
#array_alloca(ty, sz, name = "") ⇒ LLVM::Instruction
Array stack allocation.
-
#array_malloc(ty, sz, name = "") ⇒ LLVM::Instruction
A pointer to the malloced array.
-
#ashr(lhs, rhs, name = "") ⇒ LLVM::Instruction
Arithmatic shift right.
-
#bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
Cast a value to the given type without changing any bits.
-
#br(block) ⇒ LLVM::Instruction
Unconditional branching (i.e. goto).
-
#call(fun, *args) ⇒ Object
Builds a call Instruction.
- #call2(type, fun, *args) ⇒ Object
-
#cond(cond, iftrue, iffalse) ⇒ LLVM::Instruction
Conditional branching (i.e. if).
- #dispose ⇒ Object
-
#exact_sdiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Signed exact division.
-
#extract_element(vector, idx, name = "") ⇒ LLVM::Instruction
Extract an element from a vector.
-
#extract_value(aggregate, idx, name = "") ⇒ LLVM::Instruction
Extract the value of a member field from an aggregate value.
-
#fadd(lhs, rhs, name = "") ⇒ LLVM::Instruction
The floating point sum of the two operands.
-
#fcmp(pred, lhs, rhs, name = "") ⇒ LLVM::Instruction
Builds an fcmp Instruction.
-
#fdiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
The floating point quotient of the two operands.
-
#fmul(lhs, rhs, name = "") ⇒ LLVM::Instruction
Floating point multiplication.
-
#fneg(lhs, name = "") ⇒ LLVM::Instruction
The ‘fneg’ instruction returns the negation of its operand.
-
#fp2si(val, ty, name = "") ⇒ LLVM::Instruction
Convert a floating point to a signed integer.
-
#fp2ui(val, ty, name = "") ⇒ LLVM::Instruction
Convert a floating point to an unsigned integer.
- #fp_cast(val, ty, name = "") ⇒ LLVM::Instruction
-
#fp_ext(val, ty, name = "") ⇒ LLVM::Instruction
Extend a floating point value.
-
#fp_trunc(val, ty, name = "") ⇒ LLVM::Instruction
Truncate a floating point value.
-
#free(ptr) ⇒ LLVM::Instruction
The result of the free instruction.
-
#frem(lhs, rhs, name = "") ⇒ LLVM::Instruction
The floating point remainder.
-
#fsub(lhs, rhs, name = "") ⇒ LLVM::Instruction
The floating point difference of the two operands.
-
#gep(ptr, indices, name = "") ⇒ LLVM::Instruction
Obtain a pointer to the element at the given indices may return Instruction or GlobalVariable.
-
#gep2(type, ptr, indices, name = '') ⇒ LLVM::Instruction
Obtain a pointer to the element at the given indices may return Instruction or GlobalVariable.
-
#global_string(string, name = "") ⇒ LLVM::Instruction
Creates a global string initialized to a given value.
-
#global_string_pointer(string, name = "") ⇒ LLVM::Instruction
Creates a pointer to a global string initialized to a given value.
-
#ibr(addr, num_dests) ⇒ LLVM::Instruction
Indirect branching (i.e. computed goto).
-
#icmp(pred, lhs, rhs, name = "") ⇒ LLVM::Instruction
Builds an icmp Instruction.
-
#inbounds_gep(ptr, indices, name = "") ⇒ LLVM::Instruction
Builds a inbounds getelementptr instruction.
- #inbounds_gep2(type, ptr, indices, name = "") ⇒ Object
-
#initialize ⇒ Builder
constructor
Important: Call #dispose to free backend memory after use.
-
#insert_block ⇒ LLVM::BasicBlock
The BasicBlock at which the Builder is currently positioned.
-
#insert_element(vector, elem, idx, name = "") ⇒ LLVM::Instruction
Insert an element into a vector.
-
#insert_value(aggregate, elem, idx, name = "") ⇒ LLVM::Instruction
Insert a value into an aggregate value’s member field.
-
#int2ptr(val, ty, name = "") ⇒ LLVM::Instruction
Cast an int to a pointer.
- #int_cast(val, ty, name = "") ⇒ LLVM::Instruction
- #int_cast2(val, ty, signed, name = "") ⇒ LLVM::Instruction
-
#invoke(fun, args, normal, exception, name = "") ⇒ LLVM::Instruction
Invoke a function which may potentially unwind.
- #invoke2(type, fun, args, normal, exception, name = "") ⇒ Object
-
#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.
-
#landing_pad(type, personality_function, num_clauses, name = '') ⇒ Object
LLVM::Value.
- #landing_pad_cleanup(type, personality_function, num_clauses, name = '') ⇒ Object
-
#load(ptr, name = "") ⇒ LLVM::Instruction
Load the value of a given pointer.
- #load2(type, ptr, name = "") ⇒ Object
-
#lshr(lhs, rhs, name = "") ⇒ LLVM::Instruction
Shifts right with zero fill.
-
#malloc(ty, name = "") ⇒ LLVM::Instruction
A pointer to the malloced bytes.
-
#mul(lhs, rhs, name = "") ⇒ LLVM::Instruction
Integer multiplication.
-
#neg(arg, name = "") ⇒ LLVM::Instruction
Integer negation.
-
#not(arg, name = "") ⇒ LLVM::Instruction
Boolean negation.
-
#nsw_add(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No signed wrap” integer addition.
-
#nsw_mul(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No signed wrap” integer multiplication.
-
#nsw_neg(arg, name = "") ⇒ LLVM::Instruction
“No signed wrap” integer negation.
-
#nsw_sub(lhs, rhs, name = "") ⇒ LLVM::Instruction
No signed wrap integer subtraction.
-
#nuw_add(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No unsigned wrap” integer addition.
-
#nuw_mul(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No unsigned wrap” integer multiplication.
- #nuw_neg(arg, name = "") ⇒ LLVM::Instruction deprecated Deprecated.
-
#nuw_sub(lhs, rhs, name = "") ⇒ LLVM::Instruction
No unsigned wrap integer subtraction.
-
#or(lhs, rhs, name = "") ⇒ LLVM::Instruction
An integer instruction.
-
#phi(ty, incoming, name = "") ⇒ LLVM::Instruction
Build a Phi node of the given type with the given incoming branches.
-
#pointer_cast(val, ty, name = "") ⇒ LLVM::Instruction
Cast pointer to other type.
-
#position(block, instruction) ⇒ LLVM::Builder
Position the builder at the given Instruction within the given BasicBlock.
-
#position_at_end(block) ⇒ LLVM::Builder
Positions the builder at the end of the given BasicBlock.
-
#position_before(instruction) ⇒ LLVM::Builder
Positions the builder before the given Instruction.
-
#ptr2int(val, ty, name = "") ⇒ LLVM::Instruction
Cast a pointer to an int.
-
#ptr_diff(lhs, rhs, name = "") ⇒ LLVM::Instruction
Calculate the difference between two pointers.
- #ptr_diff2(type, lhs, rhs, name = "") ⇒ Object
- #ret(val = nil) ⇒ LLVM::Instruction
- #ret_void ⇒ LLVM::Instruction
-
#sdiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Signed division.
-
#select(_if, _then, _else, name = "") ⇒ LLVM::Instruction
Return a value based on a condition.
-
#sext(val, ty, name = "") ⇒ LLVM::Instruction
Sign extension by copying the sign bit (highest order bit) of the value until it reaches the bit size of the given type.
- #sext_or_bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
-
#shl(lhs, rhs, name = "") ⇒ LLVM::Instruction
An integer instruction.
-
#shuffle_vector(vec1, vec2, mask, name = "") ⇒ LLVM::Instruction
Shuffle two vectors according to a given mask.
-
#si2fp(val, ty, name = "") ⇒ LLVM::Instruction
Convert a signed integer to a floating point.
-
#srem(lhs, rhs, name = "") ⇒ LLVM::Instruction
Signed remainder.
-
#store(val, ptr) ⇒ LLVM::Instruction
Store a value at a given pointer.
-
#struct_gep(ptr, idx, name = "") ⇒ LLVM::Instruction
Builds a struct getelementptr Instruction.
- #struct_gep2(type, ptr, idx, name = "") ⇒ Object
-
#sub(lhs, rhs, name = "") ⇒ LLVM::Instruction
Integer subtraction.
- #switch(val, default, cases) ⇒ LLVM::Instruction
- #to_ptr ⇒ Object
-
#trunc(val, ty, name = "") ⇒ LLVM::Instruction
Truncates its operand to the given type.
- #trunc_or_bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
-
#udiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Unsigned integer division.
-
#ui2fp(val, ty, name = "") ⇒ LLVM::Instruction
Convert an unsigned integer to a floating point.
-
#unreachable ⇒ LLVM::Instruction
Generates an instruction with no defined semantics.
-
#unwind ⇒ Object
Builds an unwind Instruction.
-
#urem(lhs, rhs, name = "") ⇒ LLVM::Instruction
Unsigned remainder.
-
#xor(lhs, rhs, name = "") ⇒ LLVM::Instruction
An integer instruction.
-
#zext(val, ty, name = "") ⇒ LLVM::Instruction
Zero extends its operand to the given type.
- #zext_or_bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
Constructor Details
#initialize ⇒ Builder
Important: Call #dispose to free backend memory after use.
8 9 10 |
# File 'lib/llvm/core/builder.rb', line 8 def initialize @ptr = C.create_builder() end |
Instance Method Details
#add(lhs, rhs, name = "") ⇒ LLVM::Instruction
Integer addition.
226 227 228 |
# File 'lib/llvm/core/builder.rb', line 226 def add(lhs, rhs, name = "") Instruction.from_ptr(C.build_add(self, lhs, rhs, name)) end |
#aggregate_ret(*vals) ⇒ LLVM::Instruction
Builds a ret instruction returning multiple values.
87 88 89 90 91 92 |
# File 'lib/llvm/core/builder.rb', line 87 def aggregate_ret(*vals) FFI::MemoryPointer.new(FFI.type_size(:pointer) * vals.size) do |vals_ptr| vals_ptr.write_array_of_pointer(vals) Instruction.from_ptr(C.build_aggregate_ret(self, vals_ptr, vals.size)) end end |
#alloca(ty, name = "") ⇒ LLVM::Instruction
Stack allocation.
544 545 546 |
# File 'lib/llvm/core/builder.rb', line 544 def alloca(ty, name = "") Instruction.from_ptr(C.build_alloca(self, LLVM::Type(ty), name)) end |
#and(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns An integer instruction.
453 454 455 |
# File 'lib/llvm/core/builder.rb', line 453 def and(lhs, rhs, name = "") Instruction.from_ptr(C.build_and(self, lhs, rhs, name)) end |
#array_alloca(ty, sz, name = "") ⇒ LLVM::Instruction
Array stack allocation
555 556 557 |
# File 'lib/llvm/core/builder.rb', line 555 def array_alloca(ty, sz, name = "") Instruction.from_ptr(C.build_array_alloca(self, LLVM::Type(ty), sz, name)) end |
#array_malloc(ty, sz, name = "") ⇒ LLVM::Instruction
Returns A pointer to the malloced array.
526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/llvm/core/builder.rb', line 526 def array_malloc(ty, sz, name = "") size = case sz when LLVM::Value sz when Integer LLVM.i(32, sz) else raise ArgumentError, "Unknown size parameter for array_malloc: #{sz}" end Instruction.from_ptr(C.build_array_malloc(self, LLVM::Type(ty), size, name)) end |
#ashr(lhs, rhs, name = "") ⇒ LLVM::Instruction
Arithmatic shift right.
444 445 446 |
# File 'lib/llvm/core/builder.rb', line 444 def ashr(lhs, rhs, name = "") Instruction.from_ptr(C.build_a_shr(self, lhs, rhs, name)) end |
#bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
Cast a value to the given type without changing any bits
830 831 832 |
# File 'lib/llvm/core/builder.rb', line 830 def bit_cast(val, ty, name = "") Instruction.from_ptr(C.build_bit_cast(self, val, LLVM::Type(ty), name)) end |
#br(block) ⇒ LLVM::Instruction
Unconditional branching (i.e. goto)
98 99 100 101 102 103 |
# File 'lib/llvm/core/builder.rb', line 98 def br(block) raise ArgumentError, "Trying to build LLVM br with non-block: #{block.inspect}" if !block.is_a?(LLVM::BasicBlock) Instruction.from_ptr( C.build_br(self, block)) end |
#call(fun, *args) ⇒ Object
Builds a call Instruction. Calls the given Function with the given args (Instructions).
974 975 976 |
# File 'lib/llvm/core/builder.rb', line 974 def call(fun, *args) call2(nil, fun, *args) end |
#call2(type, fun, *args) ⇒ Object
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File 'lib/llvm/core/builder.rb', line 993 def call2(type, fun, *args) type, fun = call2_infer_function_and_type(type, fun) name = if args.last.kind_of? String args.pop else "" end args_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) args_ptr.write_array_of_pointer(args) ins = C.build_call2(self, type, fun, args_ptr, args.size, name) call_inst = CallInst.from_ptr(ins) if fun.is_a?(Function) call_inst.call_conv = fun.call_conv end call_inst end |
#cond(cond, iftrue, iffalse) ⇒ LLVM::Instruction
Conditional branching (i.e. if)
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/llvm/core/builder.rb', line 121 def cond(cond, iftrue, iffalse) raise ArgumentError, "Trying to build LLVM cond br with non-block (true branch): #{iftrue.inspect}" if !iftrue.is_a?(LLVM::BasicBlock) raise ArgumentError, "Trying to build LLVM cond br with non-block (false branch): #{iffalse.inspect}" if !iffalse.is_a?(LLVM::BasicBlock) cond2 = cond_condition(cond) Instruction.from_ptr( C.build_cond_br(self, cond2, iftrue, iffalse)) end |
#dispose ⇒ Object
12 13 14 15 16 |
# File 'lib/llvm/core/builder.rb', line 12 def dispose return if @ptr.nil? C.dispose_builder(@ptr) @ptr = nil end |
#exact_sdiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Signed exact division
366 367 368 |
# File 'lib/llvm/core/builder.rb', line 366 def exact_sdiv(lhs, rhs, name = "") Instruction.from_ptr(C.build_exact_s_div(self, lhs, rhs, name)) end |
#extract_element(vector, idx, name = "") ⇒ LLVM::Instruction
Extract an element from a vector
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
# File 'lib/llvm/core/builder.rb', line 1037 def extract_element(vector, idx, name = "") must_be_value!(vector) must_be_value!(idx) error = element_error(vector, idx) raise ArgumentError, "Error building extract_element with #{error}" if error ins = C.build_extract_element(self, vector, idx, name) Instruction.from_ptr(ins) end |
#extract_value(aggregate, idx, name = "") ⇒ LLVM::Instruction
Extract the value of a member field from an aggregate value
1085 1086 1087 1088 1089 1090 1091 1092 1093 |
# File 'lib/llvm/core/builder.rb', line 1085 def extract_value(aggregate, idx, name = "") must_be_value!(aggregate) error = value_error(aggregate, idx) raise ArgumentError, "Error building extract_value with #{error}" if error ins = C.build_extract_value(self, aggregate, idx, name) Instruction.from_ptr(ins) end |
#fadd(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns The floating point sum of the two operands.
255 256 257 |
# File 'lib/llvm/core/builder.rb', line 255 def fadd(lhs, rhs, name = "") Instruction.from_ptr(C.build_f_add(self, lhs, rhs, name)) end |
#fcmp(pred, lhs, rhs, name = "") ⇒ LLVM::Instruction
Builds an fcmp Instruction. Compares lhs to rhs (Instructions) as Reals using the given symbol predicate (pred):
:ord - ordered
:uno - unordered: isnan(X) | isnan(Y)
:oeq - ordered and equal to
:oeq - unordered and equal to
:one - ordered and not equal to
:one - unordered and not equal to
:ogt - ordered and greater than
:uge - unordered and greater than or equal to
:olt - ordered and less than
:ule - unordered and less than or equal to
:oge - ordered and greater than or equal to
:sge - unordered and greater than or equal to
:ole - ordered and less than or equal to
:sle - unordered and less than or equal to
:true - always true and folded
:false - always false and folded
948 949 950 |
# File 'lib/llvm/core/builder.rb', line 948 def fcmp(pred, lhs, rhs, name = "") Instruction.from_ptr(C.build_f_cmp(self, pred, lhs, rhs, name)) end |
#fdiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns The floating point quotient of the two operands.
376 377 378 |
# File 'lib/llvm/core/builder.rb', line 376 def fdiv(lhs, rhs, name = "") Instruction.from_ptr(C.build_f_div(self, lhs, rhs, name)) end |
#fmul(lhs, rhs, name = "") ⇒ LLVM::Instruction
Floating point multiplication
336 337 338 |
# File 'lib/llvm/core/builder.rb', line 336 def fmul(lhs, rhs, name = "") Instruction.from_ptr(C.build_f_mul(self, lhs, rhs, name)) end |
#fneg(lhs, name = "") ⇒ LLVM::Instruction
The ‘fneg’ instruction returns the negation of its operand. llvm.org/docs/LangRef.html#fneg-instruction
415 416 417 |
# File 'lib/llvm/core/builder.rb', line 415 def fneg(lhs, name = "") Instruction.from_ptr(C.build_f_neg(self, lhs, name)) end |
#fp2si(val, ty, name = "") ⇒ LLVM::Instruction
Convert a floating point to a signed integer
752 753 754 |
# File 'lib/llvm/core/builder.rb', line 752 def fp2si(val, ty, name = "") Instruction.from_ptr(C.build_fp_to_si(self, val, LLVM::Type(ty), name)) end |
#fp2ui(val, ty, name = "") ⇒ LLVM::Instruction
Convert a floating point to an unsigned integer
741 742 743 |
# File 'lib/llvm/core/builder.rb', line 741 def fp2ui(val, ty, name = "") Instruction.from_ptr(C.build_fp_to_ui(self, val, LLVM::Type(ty), name)) end |
#fp_cast(val, ty, name = "") ⇒ LLVM::Instruction
894 895 896 |
# File 'lib/llvm/core/builder.rb', line 894 def fp_cast(val, ty, name = "") Instruction.from_ptr(C.build_fp_cast(self, val, LLVM::Type(ty), name)) end |
#fp_ext(val, ty, name = "") ⇒ LLVM::Instruction
Extend a floating point value
798 799 800 |
# File 'lib/llvm/core/builder.rb', line 798 def fp_ext(val, ty, name = "") Instruction.from_ptr(C.build_fp_ext(self, val, LLVM::Type(ty), name)) end |
#fp_trunc(val, ty, name = "") ⇒ LLVM::Instruction
Truncate a floating point value
787 788 789 |
# File 'lib/llvm/core/builder.rb', line 787 def fp_trunc(val, ty, name = "") Instruction.from_ptr(C.build_fp_trunc(self, val, LLVM::Type(ty), name)) end |
#free(ptr) ⇒ LLVM::Instruction
Returns The result of the free instruction.
561 562 563 |
# File 'lib/llvm/core/builder.rb', line 561 def free(ptr) Instruction.from_ptr(C.build_free(self, ptr)) end |
#frem(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns The floating point remainder.
405 406 407 |
# File 'lib/llvm/core/builder.rb', line 405 def frem(lhs, rhs, name = "") Instruction.from_ptr(C.build_f_rem(self, lhs, rhs, name)) end |
#fsub(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns The floating point difference of the two operands.
295 296 297 |
# File 'lib/llvm/core/builder.rb', line 295 def fsub(lhs, rhs, name = "") Instruction.from_ptr(C.build_f_sub(self, lhs, rhs, name)) end |
#gep(ptr, indices, name = "") ⇒ LLVM::Instruction
Obtain a pointer to the element at the given indices may return Instruction or GlobalVariable
604 605 606 |
# File 'lib/llvm/core/builder.rb', line 604 def gep(ptr, indices, name = "") gep2(nil, ptr, indices, name) end |
#gep2(type, ptr, indices, name = '') ⇒ LLVM::Instruction
Obtain a pointer to the element at the given indices may return Instruction or GlobalVariable
618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/llvm/core/builder.rb', line 618 def gep2(type, ptr, indices, name = '') must_be_value!(ptr) type ||= must_infer_type!(ptr) must_be_type!(type) indices = Array(indices) FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr| indices_ptr.write_array_of_pointer(indices) ins = C.build_gep2(self, type, ptr, indices_ptr, indices.size, name) return Instruction.from_ptr(ins) end end |
#global_string(string, name = "") ⇒ LLVM::Instruction
Creates a global string initialized to a given value.
686 687 688 |
# File 'lib/llvm/core/builder.rb', line 686 def global_string(string, name = "") Instruction.from_ptr(C.build_global_string(self, string, name)) end |
#global_string_pointer(string, name = "") ⇒ LLVM::Instruction
Creates a pointer to a global string initialized to a given value.
694 695 696 |
# File 'lib/llvm/core/builder.rb', line 694 def global_string_pointer(string, name = "") Instruction.from_ptr(C.build_global_string_ptr(self, string, name)) end |
#ibr(addr, num_dests) ⇒ LLVM::Instruction
Indirect branching (i.e. computed goto)
110 111 112 113 |
# File 'lib/llvm/core/builder.rb', line 110 def ibr(addr, num_dests) IndirectBr.from_ptr( C.build_indirect_br(self, addr, num_dests)) end |
#icmp(pred, lhs, rhs, name = "") ⇒ LLVM::Instruction
Builds an icmp Instruction. Compares lhs to rhs (Instructions) using the given symbol predicate (pred):
:eq - equal to
:ne - not equal to
:ugt - unsigned greater than
:uge - unsigned greater than or equal to
:ult - unsigned less than
:ule - unsigned less than or equal to
:sgt - signed greater than
:sge - signed greater than or equal to
:slt - signed less than
:sle - signed less than or equal to
918 919 920 |
# File 'lib/llvm/core/builder.rb', line 918 def icmp(pred, lhs, rhs, name = "") Instruction.from_ptr(C.build_i_cmp(self, pred, lhs, rhs, name)) end |
#inbounds_gep(ptr, indices, name = "") ⇒ LLVM::Instruction
Builds a inbounds getelementptr instruction. If the indices are outside the allocated pointer the value is undefined.
641 642 643 |
# File 'lib/llvm/core/builder.rb', line 641 def inbounds_gep(ptr, indices, name = "") inbounds_gep2(nil, ptr, indices, name) end |
#inbounds_gep2(type, ptr, indices, name = "") ⇒ Object
645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/llvm/core/builder.rb', line 645 def inbounds_gep2(type, ptr, indices, name = "") must_be_value!(ptr) type ||= must_infer_type!(ptr) must_be_type!(type) indices = Array(indices) FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr| indices_ptr.write_array_of_pointer(indices) ins = C.build_inbounds_gep2(self, type, ptr, indices_ptr, indices.size, name) return Instruction.from_ptr(ins) end end |
#insert_block ⇒ LLVM::BasicBlock
The BasicBlock at which the Builder is currently positioned.
62 63 64 |
# File 'lib/llvm/core/builder.rb', line 62 def insert_block BasicBlock.from_ptr(C.get_insert_block(self)) end |
#insert_element(vector, elem, idx, name = "") ⇒ LLVM::Instruction
Insert an element into a vector
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/llvm/core/builder.rb', line 1055 def insert_element(vector, elem, idx, name = "") must_be_value!(vector) must_be_value!(elem) must_be_value!(idx) error = element_error(vector, idx) raise ArgumentError, "Error building insert_element with #{error}" if error ins = C.build_insert_element(self, vector, elem, idx, name) Instruction.from_ptr(ins) end |
#insert_value(aggregate, elem, idx, name = "") ⇒ LLVM::Instruction
Insert a value into an aggregate value’s member field
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
# File 'lib/llvm/core/builder.rb', line 1102 def insert_value(aggregate, elem, idx, name = "") must_be_value!(aggregate) must_be_value!(elem) error = value_error(aggregate, idx) raise ArgumentError, "Error building insert_value with #{error}" if error ins = C.build_insert_value(self, aggregate, elem, idx, name) Instruction.from_ptr(ins) end |
#int2ptr(val, ty, name = "") ⇒ LLVM::Instruction
Cast an int to a pointer
820 821 822 |
# File 'lib/llvm/core/builder.rb', line 820 def int2ptr(val, ty, name = "") Instruction.from_ptr(C.build_int_to_ptr(self, val, LLVM::Type(ty), name)) end |
#int_cast(val, ty, name = "") ⇒ LLVM::Instruction
877 878 879 |
# File 'lib/llvm/core/builder.rb', line 877 def int_cast(val, ty, name = "") Instruction.from_ptr(C.build_int_cast(self, val, LLVM::Type(ty), name)) end |
#int_cast2(val, ty, signed, name = "") ⇒ LLVM::Instruction
886 887 888 |
# File 'lib/llvm/core/builder.rb', line 886 def int_cast2(val, ty, signed, name = "") Instruction.from_ptr(C.build_int_cast2(self, val, LLVM::Type(ty), signed, name)) end |
#invoke(fun, args, normal, exception, name = "") ⇒ LLVM::Instruction
Invoke a function which may potentially unwind
173 174 175 |
# File 'lib/llvm/core/builder.rb', line 173 def invoke(fun, args, normal, exception, name = "") invoke2(nil, fun, args, normal, exception, name) end |
#invoke2(type, fun, args, normal, exception, name = "") ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/llvm/core/builder.rb', line 177 def invoke2(type, fun, args, normal, exception, name = "") type, fun = call2_infer_function_and_type(type, fun) arg_count = args.size invoke_ins = nil FFI::MemoryPointer.new(FFI.type_size(:pointer) * arg_count) do |args_ptr| args_ptr.write_array_of_pointer(args) ins = C.build_invoke2(self, type, fun, args_ptr, arg_count, normal, exception, name) invoke_ins = InvokeInst.from_ptr(ins) end if fun.is_a?(Function) invoke_ins.call_conv = fun.call_conv end invoke_ins end |
#is_not_null(val, name = "") ⇒ LLVM::Instruction
Check if a value is not null
1125 1126 1127 |
# File 'lib/llvm/core/builder.rb', line 1125 def is_not_null(val, name = "") Instruction.from_ptr(C.build_is_not_null(self, val, name)) end |
#is_null(val, name = "") ⇒ LLVM::Instruction
Check if a value is null
1117 1118 1119 |
# File 'lib/llvm/core/builder.rb', line 1117 def is_null(val, name = "") Instruction.from_ptr(C.build_is_null(self, val, name)) end |
#landing_pad(type, personality_function, num_clauses, name = '') ⇒ Object
Returns LLVM::Value.
196 197 198 |
# File 'lib/llvm/core/builder.rb', line 196 def landing_pad(type, personality_function, num_clauses, name = '') C.build_landing_pad(self, type, personality_function, num_clauses, name) end |
#landing_pad_cleanup(type, personality_function, num_clauses, name = '') ⇒ Object
200 201 202 203 204 |
# File 'lib/llvm/core/builder.rb', line 200 def landing_pad_cleanup(type, personality_function, num_clauses, name = '') lp = landing_pad(type, personality_function, num_clauses, name) C.set_cleanup(lp, 1) lp end |
#load(ptr, name = "") ⇒ LLVM::Instruction
Load the value of a given pointer
571 572 573 |
# File 'lib/llvm/core/builder.rb', line 571 def load(ptr, name = "") load2(nil, ptr, name) end |
#load2(type, ptr, name = "") ⇒ Object
575 576 577 578 579 580 581 582 583 |
# File 'lib/llvm/core/builder.rb', line 575 def load2(type, ptr, name = "") must_be_value!(ptr) type ||= infer_type(ptr) must_be_type!(type) load = C.build_load2(self, type, ptr, name) Instruction.from_ptr(load) end |
#lshr(lhs, rhs, name = "") ⇒ LLVM::Instruction
Shifts right with zero fill.
434 435 436 |
# File 'lib/llvm/core/builder.rb', line 434 def lshr(lhs, rhs, name = "") Instruction.from_ptr(C.build_l_shr(self, lhs, rhs, name)) end |
#malloc(ty, name = "") ⇒ LLVM::Instruction
Returns A pointer to the malloced bytes.
517 518 519 |
# File 'lib/llvm/core/builder.rb', line 517 def malloc(ty, name = "") Instruction.from_ptr(C.build_malloc(self, LLVM::Type(ty), name)) end |
#mul(lhs, rhs, name = "") ⇒ LLVM::Instruction
Integer multiplication.
305 306 307 |
# File 'lib/llvm/core/builder.rb', line 305 def mul(lhs, rhs, name = "") Instruction.from_ptr(C.build_mul(self, lhs, rhs, name)) end |
#neg(arg, name = "") ⇒ LLVM::Instruction
Integer negation. Implemented as a shortcut to the equivalent sub
instruction.
481 482 483 |
# File 'lib/llvm/core/builder.rb', line 481 def neg(arg, name = "") Instruction.from_ptr(C.build_neg(self, arg, name)) end |
#not(arg, name = "") ⇒ LLVM::Instruction
Boolean negation.
509 510 511 |
# File 'lib/llvm/core/builder.rb', line 509 def not(arg, name = "") Instruction.from_ptr(C.build_not(self, arg, name)) end |
#nsw_add(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No signed wrap” integer addition.
236 237 238 |
# File 'lib/llvm/core/builder.rb', line 236 def nsw_add(lhs, rhs, name = "") Instruction.from_ptr(C.build_nsw_add(self, lhs, rhs, name)) end |
#nsw_mul(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No signed wrap” integer multiplication.
315 316 317 |
# File 'lib/llvm/core/builder.rb', line 315 def nsw_mul(lhs, rhs, name = "") Instruction.from_ptr(C.build_nsw_mul(self, lhs, rhs, name)) end |
#nsw_neg(arg, name = "") ⇒ LLVM::Instruction
“No signed wrap” integer negation.
490 491 492 |
# File 'lib/llvm/core/builder.rb', line 490 def nsw_neg(arg, name = "") Instruction.from_ptr(C.build_nsw_neg(self, arg, name)) end |
#nsw_sub(lhs, rhs, name = "") ⇒ LLVM::Instruction
No signed wrap integer subtraction.
275 276 277 |
# File 'lib/llvm/core/builder.rb', line 275 def nsw_sub(lhs, rhs, name = "") Instruction.from_ptr(C.build_nsw_sub(self, lhs, rhs, name)) end |
#nuw_add(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No unsigned wrap” integer addition.
246 247 248 |
# File 'lib/llvm/core/builder.rb', line 246 def nuw_add(lhs, rhs, name = "") Instruction.from_ptr(C.build_nuw_add(self, lhs, rhs, name)) end |
#nuw_mul(lhs, rhs, name = "") ⇒ LLVM::Instruction
“No unsigned wrap” integer multiplication.
325 326 327 |
# File 'lib/llvm/core/builder.rb', line 325 def nuw_mul(lhs, rhs, name = "") Instruction.from_ptr(C.build_nuw_mul(self, lhs, rhs, name)) end |
#nuw_neg(arg, name = "") ⇒ LLVM::Instruction
“No unsigned wrap” integer negation.
500 501 502 |
# File 'lib/llvm/core/builder.rb', line 500 def nuw_neg(arg, name = "") Instruction.from_ptr(C.build_nuw_neg(self, arg, name)) end |
#nuw_sub(lhs, rhs, name = "") ⇒ LLVM::Instruction
No unsigned wrap integer subtraction.
285 286 287 |
# File 'lib/llvm/core/builder.rb', line 285 def nuw_sub(lhs, rhs, name = "") Instruction.from_ptr(C.build_nuw_sub(self, lhs, rhs, name)) end |
#or(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns An integer instruction.
462 463 464 |
# File 'lib/llvm/core/builder.rb', line 462 def or(lhs, rhs, name = "") Instruction.from_ptr(C.build_or(self, lhs, rhs, name)) end |
#phi(ty, incoming, name = "") ⇒ LLVM::Instruction
Build a Phi node of the given type with the given incoming branches
961 962 963 964 965 |
# File 'lib/llvm/core/builder.rb', line 961 def phi(ty, incoming, name = "") phi = Phi.from_ptr(C.build_phi(self, LLVM::Type(ty), name)) phi.add_incoming(incoming) phi end |
#pointer_cast(val, ty, name = "") ⇒ LLVM::Instruction
Cast pointer to other type
869 870 871 |
# File 'lib/llvm/core/builder.rb', line 869 def pointer_cast(val, ty, name = "") Instruction.from_ptr(C.build_pointer_cast(self, val, LLVM::Type(ty), name)) end |
#position(block, instruction) ⇒ LLVM::Builder
Position the builder at the given Instruction within the given BasicBlock.
28 29 30 31 32 33 34 35 |
# File 'lib/llvm/core/builder.rb', line 28 def position(block, instruction) raise ArgumentError, "Block must be LLVM::BasicBlock" if !block.is_a?(LLVM::BasicBlock) raise ArgumentError, "Instruction must be LLVM::Instruction" if !instruction.is_a?(LLVM::Instruction) C.position_builder(self, block, instruction) self end |
#position_at_end(block) ⇒ LLVM::Builder
Positions the builder at the end of the given BasicBlock.
52 53 54 55 56 57 |
# File 'lib/llvm/core/builder.rb', line 52 def position_at_end(block) raise ArgumentError, "Block must be LLVM::BasicBlock" if !block.is_a?(LLVM::BasicBlock) C.position_builder_at_end(self, block) self end |
#position_before(instruction) ⇒ LLVM::Builder
Positions the builder before the given Instruction.
41 42 43 44 45 46 |
# File 'lib/llvm/core/builder.rb', line 41 def position_before(instruction) raise ArgumentError, "Instruction must be LLVM::Instruction" if !instruction.is_a?(LLVM::Instruction) C.position_builder_before(self, instruction) self end |
#ptr2int(val, ty, name = "") ⇒ LLVM::Instruction
Cast a pointer to an int. Useful for pointer arithmetic.
809 810 811 |
# File 'lib/llvm/core/builder.rb', line 809 def ptr2int(val, ty, name = "") Instruction.from_ptr(C.build_ptr_to_int(self, val, LLVM::Type(ty), name)) end |
#ptr_diff(lhs, rhs, name = "") ⇒ LLVM::Instruction
Calculate the difference between two pointers
1135 1136 1137 |
# File 'lib/llvm/core/builder.rb', line 1135 def ptr_diff(lhs, rhs, name = "") ptr_diff2(nil, lhs, rhs, name) end |
#ptr_diff2(type, lhs, rhs, name = "") ⇒ Object
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/llvm/core/builder.rb', line 1139 def ptr_diff2(type, lhs, rhs, name = "") must_be_value!(lhs) must_be_value!(rhs) type ||= begin lhs_type = must_infer_type!(lhs) rhs_type = must_infer_type!(lhs) raise ArgumentError, "ptr_diff types must match: [#{lhs_type}] [#{rhs_type}]" if lhs_type != rhs_type lhs_type end must_be_type!(type) Instruction.from_ptr(C.build_ptr_diff2(self, type, lhs, rhs, name)) end |
#ret(val = nil) ⇒ LLVM::Instruction
75 76 77 78 79 80 81 |
# File 'lib/llvm/core/builder.rb', line 75 def ret(val = nil) unless [LLVM::Value, NilClass].any? { |c| val.is_a?(c) } raise ArgumentError, "Trying to build LLVM ret with non-value: #{val.inspect}" end Instruction.from_ptr(C.build_ret(self, val)) end |
#ret_void ⇒ LLVM::Instruction
68 69 70 |
# File 'lib/llvm/core/builder.rb', line 68 def ret_void Instruction.from_ptr(C.build_ret_void(self)) end |
#sdiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Signed division
356 357 358 |
# File 'lib/llvm/core/builder.rb', line 356 def sdiv(lhs, rhs, name = "") Instruction.from_ptr(C.build_s_div(self, lhs, rhs, name)) end |
#select(_if, _then, _else, name = "") ⇒ LLVM::Instruction
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.
1026 1027 1028 |
# File 'lib/llvm/core/builder.rb', line 1026 def select(_if, _then, _else, name = "") Instruction.from_ptr(C.build_select(self, _if, _then, _else, name)) end |
#sext(val, ty, name = "") ⇒ LLVM::Instruction
Sign extension by copying the sign bit (highest order bit) of the value until it reaches the bit size of the given type.
730 731 732 |
# File 'lib/llvm/core/builder.rb', line 730 def sext(val, ty, name = "") Instruction.from_ptr(C.build_s_ext(self, val, LLVM::Type(ty), name)) end |
#sext_or_bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
850 851 852 |
# File 'lib/llvm/core/builder.rb', line 850 def sext_or_bit_cast(val, ty, name = "") Instruction.from_ptr(C.build_s_ext_or_bit_cast(self, val, LLVM::Type(ty), name)) end |
#shl(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns An integer instruction.
424 425 426 |
# File 'lib/llvm/core/builder.rb', line 424 def shl(lhs, rhs, name = "") Instruction.from_ptr(C.build_shl(self, lhs, rhs, name)) end |
#shuffle_vector(vec1, vec2, mask, name = "") ⇒ LLVM::Instruction
Shuffle two vectors according to a given mask
1075 1076 1077 |
# File 'lib/llvm/core/builder.rb', line 1075 def shuffle_vector(vec1, vec2, mask, name = "") Instruction.from_ptr(C.build_shuffle_vector(self, vec1, vec2, mask, name)) end |
#si2fp(val, ty, name = "") ⇒ LLVM::Instruction
Convert a signed integer to a floating point
776 777 778 |
# File 'lib/llvm/core/builder.rb', line 776 def si2fp(val, ty, name = "") Instruction.from_ptr(C.build_si_to_fp(self, val, LLVM::Type(ty), name)) end |
#srem(lhs, rhs, name = "") ⇒ LLVM::Instruction
Signed remainder
396 397 398 |
# File 'lib/llvm/core/builder.rb', line 396 def srem(lhs, rhs, name = "") Instruction.from_ptr(C.build_s_rem(self, lhs, rhs, name)) end |
#store(val, ptr) ⇒ LLVM::Instruction
Store a value at a given pointer
590 591 592 593 |
# File 'lib/llvm/core/builder.rb', line 590 def store(val, ptr) raise "val must be a Value, got #{val.class.name}" unless Value === val Instruction.from_ptr(C.build_store(self, val, ptr)) end |
#struct_gep(ptr, idx, name = "") ⇒ LLVM::Instruction
Builds a struct getelementptr Instruction.
668 669 670 |
# File 'lib/llvm/core/builder.rb', line 668 def struct_gep(ptr, idx, name = "") struct_gep2(nil, ptr, idx, name) end |
#struct_gep2(type, ptr, idx, name = "") ⇒ Object
672 673 674 675 676 677 678 679 680 |
# File 'lib/llvm/core/builder.rb', line 672 def struct_gep2(type, ptr, idx, name = "") must_be_value!(ptr) type ||= must_infer_type!(ptr) must_be_type!(type) ins = C.build_struct_gep2(self, type, ptr, idx.to_i, name) Instruction.from_ptr(ins) end |
#sub(lhs, rhs, name = "") ⇒ LLVM::Instruction
Integer subtraction.
265 266 267 |
# File 'lib/llvm/core/builder.rb', line 265 def sub(lhs, rhs, name = "") Instruction.from_ptr(C.build_sub(self, lhs, rhs, name)) end |
#switch(val, default, cases) ⇒ LLVM::Instruction
156 157 158 159 160 161 162 |
# File 'lib/llvm/core/builder.rb', line 156 def switch(val, default, cases) inst = SwitchInst.from_ptr(C.build_switch(self, val, default, cases.size)) cases.each do |(c, block)| inst.add_case(c, block) end inst end |
#to_ptr ⇒ Object
19 20 21 |
# File 'lib/llvm/core/builder.rb', line 19 def to_ptr @ptr end |
#trunc(val, ty, name = "") ⇒ LLVM::Instruction
Truncates its operand to the given type. The size of the value type must be greater than the size of the target type.
706 707 708 |
# File 'lib/llvm/core/builder.rb', line 706 def trunc(val, ty, name = "") Instruction.from_ptr(C.build_trunc(self, val, LLVM::Type(ty), name)) end |
#trunc_or_bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
860 861 862 |
# File 'lib/llvm/core/builder.rb', line 860 def trunc_or_bit_cast(val, ty, name = "") Instruction.from_ptr(C.build_trunc_or_bit_cast(self, val, LLVM::Type(ty), name)) end |
#udiv(lhs, rhs, name = "") ⇒ LLVM::Instruction
Unsigned integer division
346 347 348 |
# File 'lib/llvm/core/builder.rb', line 346 def udiv(lhs, rhs, name = "") Instruction.from_ptr(C.build_u_div(self, lhs, rhs, name)) end |
#ui2fp(val, ty, name = "") ⇒ LLVM::Instruction
Convert an unsigned integer to a floating point
764 765 766 |
# File 'lib/llvm/core/builder.rb', line 764 def ui2fp(val, ty, name = "") Instruction.from_ptr(C.build_ui_to_fp(self, val, LLVM::Type(ty), name)) end |
#unreachable ⇒ LLVM::Instruction
Generates an instruction with no defined semantics. Can be used to provide hints to the optimizer.
216 217 218 |
# File 'lib/llvm/core/builder.rb', line 216 def unreachable Instruction.from_ptr(C.build_unreachable(self)) end |
#unwind ⇒ Object
Builds an unwind Instruction.
208 209 210 |
# File 'lib/llvm/core/builder.rb', line 208 def unwind raise DeprecationError end |
#urem(lhs, rhs, name = "") ⇒ LLVM::Instruction
Unsigned remainder
386 387 388 |
# File 'lib/llvm/core/builder.rb', line 386 def urem(lhs, rhs, name = "") Instruction.from_ptr(C.build_u_rem(self, lhs, rhs, name)) end |
#xor(lhs, rhs, name = "") ⇒ LLVM::Instruction
Returns An integer instruction.
471 472 473 |
# File 'lib/llvm/core/builder.rb', line 471 def xor(lhs, rhs, name = "") Instruction.from_ptr(C.build_xor(self, lhs, rhs, name)) end |
#zext(val, ty, name = "") ⇒ LLVM::Instruction
Zero extends its operand to the given type. The size of the value type must be greater than the size of the target type.
718 719 720 |
# File 'lib/llvm/core/builder.rb', line 718 def zext(val, ty, name = "") Instruction.from_ptr(C.build_z_ext(self, val, LLVM::Type(ty), name)) end |
#zext_or_bit_cast(val, ty, name = "") ⇒ LLVM::Instruction
840 841 842 |
# File 'lib/llvm/core/builder.rb', line 840 def zext_or_bit_cast(val, ty, name = "") Instruction.from_ptr(C.build_z_ext_or_bit_cast(self, val, LLVM::Type(ty), name)) end |