Class: LLVM::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/llvm/core/builder.rb

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Important: Call #dispose to free backend memory after use.



6
7
8
# File 'lib/llvm/core/builder.rb', line 6

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:



201
202
203
# File 'lib/llvm/core/builder.rb', line 201

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:



85
86
87
88
89
90
# File 'lib/llvm/core/builder.rb', line 85

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:



499
500
501
# File 'lib/llvm/core/builder.rb', line 499

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:



418
419
420
# File 'lib/llvm/core/builder.rb', line 418

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:



510
511
512
# File 'lib/llvm/core/builder.rb', line 510

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:



489
490
491
# File 'lib/llvm/core/builder.rb', line 489

def array_malloc(ty, sz, name = "")
  Instruction.from_ptr(C.build_array_malloc(self, LLVM::Type(ty), sz, 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:



409
410
411
# File 'lib/llvm/core/builder.rb', line 409

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:



736
737
738
# File 'lib/llvm/core/builder.rb', line 736

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)


96
97
98
99
100
101
# File 'lib/llvm/core/builder.rb', line 96

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:

Raises:

  • (ArgumentError)


870
871
872
873
874
875
876
877
878
879
880
881
882
# File 'lib/llvm/core/builder.rb', line 870

def call(fun, *args)
  raise ArgumentError, "Trying to build LLVM call with non-function: #{fun.inspect}" if !fun.is_a?(LLVM::Function)

  if args.last.kind_of? String
    name = args.pop
  else
    name = ""
  end

  args_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size)
  args_ptr.write_array_of_pointer(args)
  CallInst.from_ptr(C.build_call(self, fun, args_ptr, args.size, name))
end

#cond(cond, iftrue, iffalse) ⇒ LLVM::Instruction

Conditional branching (i.e. if)

Parameters:

Returns:

Raises:

  • (ArgumentError)


119
120
121
122
123
124
125
126
127
128
# File 'lib/llvm/core/builder.rb', line 119

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



10
11
12
13
14
# File 'lib/llvm/core/builder.rb', line 10

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:



341
342
343
# File 'lib/llvm/core/builder.rb', line 341

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)


906
907
908
909
910
911
912
# File 'lib/llvm/core/builder.rb', line 906

def extract_element(vector, idx, name = "")
  error = element_error(vector, idx)

  raise ArgumentError, "Error building extract_element with #{error}" if error

  Instruction.from_ptr(C.build_extract_element(self, vector, idx, name))
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)


961
962
963
964
965
966
967
# File 'lib/llvm/core/builder.rb', line 961

def extract_value(aggregate, idx, name = "")
  error = value_error(aggregate, idx)

  raise ArgumentError, "Error building extract_value with #{error}" if error

  Instruction.from_ptr(C.build_extract_value(self, aggregate, idx, name))
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:



230
231
232
# File 'lib/llvm/core/builder.rb', line 230

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:



844
845
846
# File 'lib/llvm/core/builder.rb', line 844

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:



351
352
353
# File 'lib/llvm/core/builder.rb', line 351

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:



311
312
313
# File 'lib/llvm/core/builder.rb', line 311

def fmul(lhs, rhs, name = "")
  Instruction.from_ptr(C.build_f_mul(self, lhs, rhs, 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:



658
659
660
# File 'lib/llvm/core/builder.rb', line 658

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:



647
648
649
# File 'lib/llvm/core/builder.rb', line 647

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:



790
791
792
# File 'lib/llvm/core/builder.rb', line 790

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:



704
705
706
# File 'lib/llvm/core/builder.rb', line 704

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:



693
694
695
# File 'lib/llvm/core/builder.rb', line 693

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:



516
517
518
# File 'lib/llvm/core/builder.rb', line 516

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:



380
381
382
# File 'lib/llvm/core/builder.rb', line 380

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:



270
271
272
# File 'lib/llvm/core/builder.rb', line 270

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

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:



548
549
550
551
552
553
554
555
# File 'lib/llvm/core/builder.rb', line 548

def gep(ptr, indices, name = "")
  indices = Array(indices)
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
    indices_ptr.write_array_of_pointer(indices)
    return Instruction.from_ptr(
      C.build_gep(self, ptr, indices_ptr, indices.size, name))
  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:



592
593
594
# File 'lib/llvm/core/builder.rb', line 592

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:



600
601
602
# File 'lib/llvm/core/builder.rb', line 600

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:



108
109
110
111
# File 'lib/llvm/core/builder.rb', line 108

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:



814
815
816
# File 'lib/llvm/core/builder.rb', line 814

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:



566
567
568
569
570
571
572
573
# File 'lib/llvm/core/builder.rb', line 566

def inbounds_gep(ptr, indices, name = "")
  indices = Array(indices)
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
    indices_ptr.write_array_of_pointer(indices)
    return Instruction.from_ptr(
      C.build_in_bounds_gep(self, ptr, indices_ptr, indices.size, name))
  end
end

#insert_blockLLVM::BasicBlock

The BasicBlock at which the Builder is currently positioned.

Returns:



60
61
62
# File 'lib/llvm/core/builder.rb', line 60

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)


921
922
923
924
925
926
927
928
929
930
931
# File 'lib/llvm/core/builder.rb', line 921

def insert_element(vector, elem, idx, name = "")
  error = element_error(vector, idx)

  error ||= if !elem.is_a?(LLVM::Value)
    "elem: #{elem.inspect}"
  end

  raise ArgumentError, "Error building insert_element with #{error}" if error

  Instruction.from_ptr(C.build_insert_element(self, vector, elem, idx, name))
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)


976
977
978
979
980
981
982
983
984
985
986
# File 'lib/llvm/core/builder.rb', line 976

def insert_value(aggregate, elem, idx, name = "")
  error = value_error(aggregate, idx)

  error ||= if !elem.is_a?(LLVM::Value)
    "elem: #{elem.inspect}"
  end

  raise ArgumentError, "Error building insert_value with #{error}" if error

  Instruction.from_ptr(C.build_insert_value(self, aggregate, elem, idx, name))
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:



726
727
728
# File 'lib/llvm/core/builder.rb', line 726

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:



782
783
784
# File 'lib/llvm/core/builder.rb', line 782

def int_cast(val, ty, name = "")
  Instruction.from_ptr(C.build_int_cast(self, val, LLVM::Type(ty), 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



171
172
173
174
175
176
177
178
179
# File 'lib/llvm/core/builder.rb', line 171

def invoke(fun, args, normal, exception, name = "")
  s = args.size
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * s) do |args_ptr|
    args_ptr.write_array_of_pointer(args)
    return Instruction.from_ptr(
      C.build_invoke(self,
        fun, args_ptr, s, normal, exception, name))
  end
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:



1010
1011
1012
# File 'lib/llvm/core/builder.rb', line 1010

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:



1002
1003
1004
# File 'lib/llvm/core/builder.rb', line 1002

def is_null(val, name = "")
  Instruction.from_ptr(C.build_is_null(self, val, name))
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.



526
527
528
# File 'lib/llvm/core/builder.rb', line 526

def load(ptr, name = "")
  Instruction.from_ptr(C.build_load(self, ptr, name))
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:



399
400
401
# File 'lib/llvm/core/builder.rb', line 399

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:



480
481
482
# File 'lib/llvm/core/builder.rb', line 480

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:



280
281
282
# File 'lib/llvm/core/builder.rb', line 280

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:



446
447
448
# File 'lib/llvm/core/builder.rb', line 446

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:



472
473
474
# File 'lib/llvm/core/builder.rb', line 472

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:



211
212
213
# File 'lib/llvm/core/builder.rb', line 211

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:



290
291
292
# File 'lib/llvm/core/builder.rb', line 290

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:



455
456
457
# File 'lib/llvm/core/builder.rb', line 455

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:



250
251
252
# File 'lib/llvm/core/builder.rb', line 250

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:



221
222
223
# File 'lib/llvm/core/builder.rb', line 221

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:



300
301
302
# File 'lib/llvm/core/builder.rb', line 300

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.

Parameters:

  • arg (LLVM::Value)

    Integer or vector of integers

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

    Name of the result in LLVM IR

Returns:



464
465
466
# File 'lib/llvm/core/builder.rb', line 464

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:



260
261
262
# File 'lib/llvm/core/builder.rb', line 260

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:



427
428
429
# File 'lib/llvm/core/builder.rb', line 427

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:



857
858
859
860
861
# File 'lib/llvm/core/builder.rb', line 857

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

Parameters:

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

    The name of the result in LLVM IR

Returns:



774
775
776
# File 'lib/llvm/core/builder.rb', line 774

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)


26
27
28
29
30
31
32
33
# File 'lib/llvm/core/builder.rb', line 26

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)


50
51
52
53
54
55
# File 'lib/llvm/core/builder.rb', line 50

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)


39
40
41
42
43
44
# File 'lib/llvm/core/builder.rb', line 39

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



715
716
717
# File 'lib/llvm/core/builder.rb', line 715

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:



1020
1021
1022
# File 'lib/llvm/core/builder.rb', line 1020

def ptr_diff(lhs, rhs, name = "")
  Instruction.from_ptr(C.build_ptr_diff(lhs, rhs, name))
end

#ret(val = nil) ⇒ LLVM::Instruction

Parameters:

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

    The value to return

Returns:



73
74
75
76
77
78
79
# File 'lib/llvm/core/builder.rb', line 73

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:



66
67
68
# File 'lib/llvm/core/builder.rb', line 66

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:



331
332
333
# File 'lib/llvm/core/builder.rb', line 331

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:



895
896
897
# File 'lib/llvm/core/builder.rb', line 895

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:



636
637
638
# File 'lib/llvm/core/builder.rb', line 636

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:



756
757
758
# File 'lib/llvm/core/builder.rb', line 756

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:



389
390
391
# File 'lib/llvm/core/builder.rb', line 389

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:



951
952
953
# File 'lib/llvm/core/builder.rb', line 951

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:



682
683
684
# File 'lib/llvm/core/builder.rb', line 682

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:



371
372
373
# File 'lib/llvm/core/builder.rb', line 371

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:



535
536
537
538
# File 'lib/llvm/core/builder.rb', line 535

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(pointer, idx, name = "") ⇒ LLVM::Instruction

Builds a struct getelementptr Instruction.

Parameters:

  • pointer (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:



584
585
586
# File 'lib/llvm/core/builder.rb', line 584

def struct_gep(pointer, idx, name = "")
  Instruction.from_ptr(C.build_struct_gep(self, pointer, idx, name))
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:



240
241
242
# File 'lib/llvm/core/builder.rb', line 240

def sub(lhs, rhs, name = "")
  Instruction.from_ptr(C.build_sub(self, lhs, rhs, name))
end

#switch(val, default, cases) ⇒ LLVM::Instruction

Parameters:

Returns:



154
155
156
157
158
159
160
# File 'lib/llvm/core/builder.rb', line 154

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



17
18
19
# File 'lib/llvm/core/builder.rb', line 17

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:



612
613
614
# File 'lib/llvm/core/builder.rb', line 612

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:



766
767
768
# File 'lib/llvm/core/builder.rb', line 766

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:



321
322
323
# File 'lib/llvm/core/builder.rb', line 321

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:



670
671
672
# File 'lib/llvm/core/builder.rb', line 670

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:



191
192
193
# File 'lib/llvm/core/builder.rb', line 191

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

#unwindObject

Builds an unwind Instruction.



183
184
185
# File 'lib/llvm/core/builder.rb', line 183

def unwind
  Instruction.from_ptr(C.build_unwind(self))
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:



361
362
363
# File 'lib/llvm/core/builder.rb', line 361

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:



436
437
438
# File 'lib/llvm/core/builder.rb', line 436

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:



624
625
626
# File 'lib/llvm/core/builder.rb', line 624

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:



746
747
748
# File 'lib/llvm/core/builder.rb', line 746

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