Class: LLVM::Builder

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

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



3
4
5
# File 'lib/llvm/core/builder.rb', line 3

def initialize
  @ptr = C.LLVMCreateBuilder()
end

Instance Method Details

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

Returns The integer sum of the two operands.

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:



140
141
142
# File 'lib/llvm/core/builder.rb', line 140

def add(lhs, rhs, name = "")
  Instruction.from_ptr(C.LLVMBuildAdd(self, lhs, rhs, name))
end

#aggregate_ret(*vals) ⇒ LLVM::Instruction

Builds a ret instruction returning multiple values.

Parameters:

Returns:



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

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.LLVMBuildAggregateRet(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:



367
368
369
# File 'lib/llvm/core/builder.rb', line 367

def alloca(ty, name = "")
  Instruction.from_ptr(C.LLVMBuildAlloca(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:



304
305
306
# File 'lib/llvm/core/builder.rb', line 304

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



378
379
380
# File 'lib/llvm/core/builder.rb', line 378

def array_alloca(ty, sz, name = "")
  Instruction.from_ptr(C.LLVMBuildArrayAlloca(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:



357
358
359
# File 'lib/llvm/core/builder.rb', line 357

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



295
296
297
# File 'lib/llvm/core/builder.rb', line 295

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



602
603
604
# File 'lib/llvm/core/builder.rb', line 602

def bit_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildBitCast(self, val, LLVM::Type(ty), name))
end

#br(block) ⇒ LLVM::Instruction

Unconditional branching (i.e. goto)

Parameters:

Returns:



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

def br(block)
  Instruction.from_ptr(
    C.LLVMBuildBr(self, block))
end

#call(fun, *args) ⇒ Object

Builds a call Instruction. Calls the given Function with the given args (Instructions).

Parameters:



736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/llvm/core/builder.rb', line 736

def call(fun, *args)
  raise "No fun" if fun.nil?
  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.LLVMBuildCall(self, fun, args_ptr, args.size, name))
end

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

Conditional branching (i.e. if)

Parameters:

Returns:



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

def cond(cond, iftrue, iffalse)
  Instruction.from_ptr(
    C.LLVMBuildCondBr(self, cond, iftrue, iffalse))
end

#disposeObject

Disposes the builder.

Returns:

  • nil



847
848
849
# File 'lib/llvm/core/builder.rb', line 847

def dispose
  C.LLVMDisposeBuilder(@ptr)
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:



227
228
229
# File 'lib/llvm/core/builder.rb', line 227

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



771
772
773
# File 'lib/llvm/core/builder.rb', line 771

def extract_element(vector, idx, name = "")
  Instruction.from_ptr(C.LLVMBuildExtractElement(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 (LLVM::Value)

    The index of the member to extract

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

    The name of the result in LLVM IR

Returns:



804
805
806
# File 'lib/llvm/core/builder.rb', line 804

def extract_value(aggregate, idx, name = "")
  Instruction.from_ptr(C.LLVMBuildExtractValue(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:



159
160
161
# File 'lib/llvm/core/builder.rb', line 159

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



710
711
712
# File 'lib/llvm/core/builder.rb', line 710

def fcmp(pred, lhs, rhs, name = "")
  Instruction.from_ptr(C.LLVMBuildFCmp(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:



237
238
239
# File 'lib/llvm/core/builder.rb', line 237

def fdiv(lhs, rhs, name = "")
  Instruction.from_ptr(C.LLVMBuildFDiv(self, lhs, rhs, name))
end

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

Returns The floating point product 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:



197
198
199
# File 'lib/llvm/core/builder.rb', line 197

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



524
525
526
# File 'lib/llvm/core/builder.rb', line 524

def fp2si(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildFPToSI(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:



513
514
515
# File 'lib/llvm/core/builder.rb', line 513

def fp2ui(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildFPToUI(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:



656
657
658
# File 'lib/llvm/core/builder.rb', line 656

def fp_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildFPCast(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:



570
571
572
# File 'lib/llvm/core/builder.rb', line 570

def fp_ext(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildFPExt(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:



559
560
561
# File 'lib/llvm/core/builder.rb', line 559

def fp_trunc(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildFPTrunc(self, val, LLVM::Type(ty), name))
end

#free(ptr) ⇒ LLVM::Instruction

Returns The result of the free instruction.

Parameters:

Returns:



384
385
386
# File 'lib/llvm/core/builder.rb', line 384

def free(ptr)
  Instruction.from_ptr(C.LLVMBuildFree(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:



266
267
268
# File 'lib/llvm/core/builder.rb', line 266

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



178
179
180
# File 'lib/llvm/core/builder.rb', line 178

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



415
416
417
418
419
420
421
422
# File 'lib/llvm/core/builder.rb', line 415

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.LLVMBuildGEP(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:



458
459
460
# File 'lib/llvm/core/builder.rb', line 458

def global_string(string, name = "")
  Instruction.from_ptr(C.LLVMBuildGlobalString(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:



466
467
468
# File 'lib/llvm/core/builder.rb', line 466

def global_string_pointer(string, name = "")
  Instruction.from_ptr(C.LLVMBuildGlobalStringPtr(self, string, name))
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:



680
681
682
# File 'lib/llvm/core/builder.rb', line 680

def icmp(pred, lhs, rhs, name = "")
  Instruction.from_ptr(C.LLVMBuildICmp(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:



433
434
435
436
437
438
439
440
# File 'lib/llvm/core/builder.rb', line 433

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.LLVMBuildInBoundsGEP(self, ptr, indices_ptr, indices.size, name))
  end
end

#insert_blockLLVM::BasicBlock

The BasicBlock at which the Builder is currently positioned.

Returns:



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

def insert_block
  BasicBlock.from_ptr(C.LLVMGetInsertBlock(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:



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

def insert_element(vector, elem, idx, name = "")
  Instruction.from_ptr(C.LLVMBuildInsertElement(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 (LLVM::Value)

    The index at which to insert the value

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

    The name of the result in LLVM IR

Returns:



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

def insert_value(aggregate, elem, idx, name = "")
  Instruction.from_ptr(C.LLVMBuildInsertValue(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:



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

def int2ptr(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildIntToPtr(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:



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

def int_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildIntCast(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



114
115
116
117
118
# File 'lib/llvm/core/builder.rb', line 114

def invoke(fun, args, normal, exception, name = "")
  Instruction.from_ptr(
    C.LLVMBuildInvoke(self,
      fun, args, args.size, normal, exception, name))
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:



831
832
833
# File 'lib/llvm/core/builder.rb', line 831

def is_not_null(val, name = "")
  Instruction.from_ptr(C.LLVMBuildIsNotNull(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:



823
824
825
# File 'lib/llvm/core/builder.rb', line 823

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



394
395
396
# File 'lib/llvm/core/builder.rb', line 394

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



285
286
287
# File 'lib/llvm/core/builder.rb', line 285

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



348
349
350
# File 'lib/llvm/core/builder.rb', line 348

def malloc(ty, name = "")
  Instruction.from_ptr(C.LLVMBuildMalloc(self, LLVM::Type(ty), name))
end

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

Returns The integer product of the two operands.

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:



187
188
189
# File 'lib/llvm/core/builder.rb', line 187

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



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

def neg(arg, name = "")
  Instruction.from_ptr(C.LLVMBuildNeg(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:



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

def not(arg, name = "")
  Instruction.from_ptr(C.LLVMBuildNot(self, arg, name))
end

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

No signed wrap 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:



150
151
152
# File 'lib/llvm/core/builder.rb', line 150

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



313
314
315
# File 'lib/llvm/core/builder.rb', line 313

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



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

def phi(ty, incoming, name = "")

  phi = Phi.from_ptr(C.LLVMBuildPhi(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:



640
641
642
# File 'lib/llvm/core/builder.rb', line 640

def pointer_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildPointerCast(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:



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

def position(block, instruction)
  raise "Block must not be nil" if block.nil?
  C.LLVMPositionBuilder(self, block, instruction)
  self
end

#position_at_end(block) ⇒ LLVM::Builder

Positions the builder at the end of the given BasicBlock.

Parameters:

Returns:



34
35
36
37
38
# File 'lib/llvm/core/builder.rb', line 34

def position_at_end(block)
  raise "Block must not be nil" if block.nil?
  C.LLVMPositionBuilderAtEnd(self, block)
  self
end

#position_before(instruction) ⇒ LLVM::Builder

Positions the builder before the given Instruction.

Parameters:

Returns:



25
26
27
28
29
# File 'lib/llvm/core/builder.rb', line 25

def position_before(instruction)
  raise "Instruction must not be nil" if instruction.nil?
  C.LLVMPositionBuilderBefore(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



581
582
583
# File 'lib/llvm/core/builder.rb', line 581

def ptr2int(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildPtrToInt(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:



841
842
843
# File 'lib/llvm/core/builder.rb', line 841

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

#ret(val) ⇒ LLVM::Instruction

Parameters:

Returns:



55
56
57
# File 'lib/llvm/core/builder.rb', line 55

def ret(val)
  Instruction.from_ptr(C.LLVMBuildRet(self, val))
end

#ret_voidLLVM::Instruction

Returns:



48
49
50
# File 'lib/llvm/core/builder.rb', line 48

def ret_void
  Instruction.from_ptr(C.LLVMBuildRetVoid(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:



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

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



760
761
762
# File 'lib/llvm/core/builder.rb', line 760

def select(_if, _then, _else, name = "")
  Instruction.from_ptr(C.LLVMBuildSelect(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:



502
503
504
# File 'lib/llvm/core/builder.rb', line 502

def sext(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildSExt(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:



622
623
624
# File 'lib/llvm/core/builder.rb', line 622

def sext_or_bit_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildSExtOrBitCast(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:



275
276
277
# File 'lib/llvm/core/builder.rb', line 275

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



794
795
796
# File 'lib/llvm/core/builder.rb', line 794

def shuffle_vector(vec1, vec2, mask, name = "")
  Instruction.from_ptr(C.LLVMBuildShuffleVector(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:



548
549
550
# File 'lib/llvm/core/builder.rb', line 548

def si2fp(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildSIToFP(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:



257
258
259
# File 'lib/llvm/core/builder.rb', line 257

def srem(lhs, rhs, name = "")
  Instruction.from_ptr(C.LLVMBuildSRem(self, lhs, rhs, name))
end

#store(val, ptr) ⇒ LLVM::Instruction

Store a value at a given pointer

Parameters:

Returns:



403
404
405
# File 'lib/llvm/core/builder.rb', line 403

def store(val, ptr)
  Instruction.from_ptr(C.LLVMBuildStore(self, val, ptr))
end

#struct_gep(pointer, 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:



450
451
452
# File 'lib/llvm/core/builder.rb', line 450

def struct_gep(pointer, idx, name = "")
  Instruction.from_ptr(C.LLVMBuildStructGEP(self, pointer, idx, name))
end

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

Returns The integer difference of the two operands.

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:



168
169
170
# File 'lib/llvm/core/builder.rb', line 168

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

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

Parameters:

Returns:



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

def switch(val, default, cases)
  inst = SwitchInst.from_ptr(C.LLVMBuildSwitch(self, val, default, cases.size))
  cases.each do |(val, block)|
    inst.add_case(val, block)
  end
  inst
end

#to_ptrObject



8
9
10
# File 'lib/llvm/core/builder.rb', line 8

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:



478
479
480
# File 'lib/llvm/core/builder.rb', line 478

def trunc(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildTrunc(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:



632
633
634
# File 'lib/llvm/core/builder.rb', line 632

def trunc_or_bit_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildTruncOrBitCast(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:



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

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



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

def ui2fp(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildUIToFP(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:



131
132
133
# File 'lib/llvm/core/builder.rb', line 131

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

#unwindLLVM::Instruction

Builds an unwind Instruction.

Returns:



123
124
125
# File 'lib/llvm/core/builder.rb', line 123

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



247
248
249
# File 'lib/llvm/core/builder.rb', line 247

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



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

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



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

def zext(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildZExt(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:



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

def zext_or_bit_cast(val, ty, name = "")
  Instruction.from_ptr(C.LLVMBuildZExtOrBitCast(self, val, LLVM::Type(ty), name))
end