Class: LLVM::Builder

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/llvm/core/builder.rb

Instance Method Summary collapse

Constructor Details

#initializeBuilder

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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

Returns:



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.

Parameters:

  • ty (LLVM::Type, #type)

    The type or value whose type should be allocad

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • ty (LLVM::Type, #type)

    The type or value whose type will be the element type of the allocad array

  • sz (LLVM::Value)

    Unsigned integer representing size of the array

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • ty (LLVM::Type, #type)

    The type or value whose type will be the element type of the malloced array

  • sz (LLVM::Value)

    Unsigned integer representing size of the array

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    The value to cast

  • ty (LLVM::Type, #ty)

    The target type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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)

Parameters:

Returns:

Raises:

  • (ArgumentError)


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).

Parameters:



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)

Parameters:

Returns:

Raises:

  • (ArgumentError)


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

#disposeObject



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

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • vector (LLVM::Value)

    The vector from which to extract a value

  • idx (LLVM::Value)

    The index of the element to extract, an unsigned integer

  • name (String) (defaults to: "")

    The value of the result in LLVM IR

Returns:

Raises:

  • (ArgumentError)


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

Parameters:

  • aggregate (LLVM::Value)

    An aggregate value

  • idx (Integer)

    The index of the member to extract

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • lhs (LLVM::Value)

    Floating point or vector of floating points

  • rhs (LLVM::Value)

    Floating point or vector of floating points

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • pred (Symbol)

    A predicate

  • lhs (LLVM::Value)

    The left hand side of the comparison, of floating point type

  • rhs (LLVM::Value)

    The right hand side of the comparison, of the same type as lhs

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Floating point or vector of floating points

  • rhs (LLVM::Value)

    Floating point or vector of floating points

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • lhs (LLVM::Value)

    Floating point or vector of floating points

  • rhs (LLVM::Value)

    Floating point or vector of floating points

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • lhs (LLVM::Value)

    Floating point or vector of floating points

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    Floating point or vector of floating points to convert

  • ty (LLVM::Type, #type)

    Integer or vector of integer target type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    Floating point or vector of floating points to convert

  • ty (LLVM::Type, #type)

    Integer or vector of integer target type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    Floating point or vector of floating point

  • ty (LLVM::Type, #type)

    Floating point or vector of floating point type of greater size than val’s type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    Floating point or vector of floating point

  • ty (LLVM::Type, #type)

    Floating point or vector of floating point type of lesser size than val’s type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Floating point or vector of floating points

  • rhs (LLVM::Value)

    Floating point or vector of floating points

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Floating point or vector of floating points

  • rhs (LLVM::Value)

    Floating point or vector of floating points

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • ptr (LLVM::Value)

    A pointer to an aggregate value

  • indices (Array<LLVM::Value>)

    Ruby array of LLVM::Value representing indices into the aggregate

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

See Also:



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

Parameters:

  • type (LLVM::Type)

    An LLVM::Type

  • ptr (LLVM::Value)

    A pointer to an aggregate value

  • indices (Array<LLVM::Value>)

    Ruby array of LLVM::Value representing indices into the aggregate

  • name (String) (defaults to: '')

    The name of the result in LLVM IR

Returns:

See Also:



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.

Parameters:

  • string (String)

    The string used by the initialize

  • name (Name) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • string (String)

    The string used by the initializer

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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)

Parameters:

  • addr (LLVM::BasicBlock)

    Where to jump

  • num_dests (Integer)

    Number of possible destinations to be added

Returns:



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

Parameters:

  • pred (Symbol)

    A predicate

  • lhs (LLVM::Value)

    The left hand side of the comparison, of integer or pointer type

  • rhs (LLVM::Value)

    The right hand side of the comparison, of the same type as lhs

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • ptr (LLVM::Value)

    A pointer to an aggregate value

  • indices (Array<LLVM::Value>)

    Ruby array of LLVM::Value representing indices into the aggregate

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

See Also:



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_blockLLVM::BasicBlock

The BasicBlock at which the Builder is currently positioned.

Returns:



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

Parameters:

  • vector (LLVM::Value)

    The vector into which to insert the element

  • elem (LLVM::Value)

    The element to be inserted into the vector

  • idx (LLVM::Value)

    The index at which to insert the element

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

Raises:

  • (ArgumentError)


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

Parameters:

  • aggregate (LLVM::Value)

    An aggregate value

  • elem (LLVM::Value)

    The value to insert into ‘aggregate’

  • idx (Integer)

    The index at which to insert the value

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

Raises:

  • (ArgumentError)


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

Parameters:

  • val (LLVM::Value)

    An integer value

  • ty (LLVM::Type, #ty)

    A pointer type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

  • signed (bool)

    whether to sign or zero extend

Returns:



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

Parameters:

Returns:

  • (LLVM::Instruction)

    The value returned by ‘fun’, unless an unwind instruction occurs



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

Parameters:

  • val (LLVM::Value)

    The value to check

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    The value to check

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

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

Parameters:

  • ptr (LLVM::Value)

    The pointer to be loaded

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

  • (LLVM::Instruction)

    The result of the load operation. Represents a value of the pointer’s type.



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • ty (LLVM::Type, #type)

    The type or value whose type should be malloced

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • arg (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • arg (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • arg (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Deprecated.

“No unsigned wrap” integer negation.

Parameters:

  • arg (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • ty (LLVM::Type)

    Specifies the result type

  • incoming (Hash{LLVM::BasicBlock => LLVM::Value})

    A hash mapping basic blocks to a corresponding value. If the phi node is jumped to from a given basic block, the phi instruction takes on its corresponding value.

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • val (LLVM::Value)

    A pointer

  • ty (LLVM::Type, #type)

    An integer type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

  • (LLVM::Instruction)

    An integer of the given type representing the pointer’s address



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

Parameters:

  • lhs (LLVM::Value)

    A pointer

  • rhs (LLVM::Value)

    A pointer

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value) (defaults to: nil)

    The value to return

Returns:



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_voidLLVM::Instruction

Returns:



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

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • _if (LLVM::Value)

    An i1 or a vector of i1

  • _then (LLVM::Value)

    A value or vector of the same arity as _if

  • _else (LLVM::Value)

    A value or vector of values of the same arity as _if, and of the same type as _then

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • val (LLVM::Value)

    Integer or vector of integers to be extended

  • ty (LLVM::Type)

    Integer or vector of integer type of greater size than the size of val

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • vec1 (LLVM::Value)

    A vector

  • vec2 (LLVM::Value)

    A vector of the same type and arity as vec1

  • mask (LLVM::Value)

    A vector of i1 of the same arity as vec1 and vec2

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    Signed integer or vector of signed integer to convert

  • ty (LLVM::Type, #type)

    Floating point or vector of floating point target type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

Returns:



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.

Parameters:

  • ptr (LLVM::Value)

    A pointer to a structure

  • idx (LLVM::Value)

    Unsigned integer representing the index of a structure member

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:

See Also:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

Returns:



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_ptrObject



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.

Parameters:

  • val (LLVM::Value)

    Integer or vector of integers to be truncated

  • ty (LLVM::Type, #type)

    Integer or vector of integers of equal size to val

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)

    Unsigned integer or vector of unsigned integer to convert

  • ty (LLVM::Type, #type)

    Floating point or vector of floating point target type

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

#unreachableLLVM::Instruction

Generates an instruction with no defined semantics. Can be used to provide hints to the optimizer.

Returns:



216
217
218
# File 'lib/llvm/core/builder.rb', line 216

def unreachable
  Instruction.from_ptr(C.build_unreachable(self))
end

#unwindObject

Builds an unwind Instruction.

Raises:



208
209
210
# File 'lib/llvm/core/builder.rb', line 208

def unwind
  raise DeprecationError
end

#urem(lhs, rhs, name = "") ⇒ LLVM::Instruction

Unsigned remainder

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • lhs (LLVM::Value)

    Integer or vector of integers

  • rhs (LLVM::Value)

    Integer or vector of integers

  • name (String) (defaults to: "")

    Name of the result in LLVM IR

Returns:



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.

Parameters:

  • val (LLVM::Value)

    Integer or vector of integers to be extended

  • ty (LLVM::Type, #type)

    Integer or vector of integer type of greater size than val

  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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

Parameters:

  • val (LLVM::Value)
  • ty (LLVM::Type, #ty)
  • name (String) (defaults to: "")

    The name of the result in LLVM IR

Returns:



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