Class: LLVM::Function::BasicBlockCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/llvm/core/value.rb

Instance Method Summary collapse

Constructor Details

#initialize(fun) ⇒ BasicBlockCollection

Returns a new instance of BasicBlockCollection.



909
910
911
# File 'lib/llvm/core/value.rb', line 909

def initialize(fun)
  @fun = fun
end

Instance Method Details

#append(name = "") ⇒ Object

Adds a BasicBlock with the given name to the end of the collection.



932
933
934
# File 'lib/llvm/core/value.rb', line 932

def append(name = "")
  BasicBlock.create(@fun, name)
end

#eachObject

Iterates through each BasicBlock in the collection.



919
920
921
922
923
924
925
926
927
928
929
# File 'lib/llvm/core/value.rb', line 919

def each
  return to_enum :each unless block_given?

  ptr = C.get_first_basic_block(@fun)
  0.upto(size - 1) do |i|
    yield BasicBlock.from_ptr(ptr)
    ptr = C.get_next_basic_block(ptr)
  end

  self
end

#entryObject

Returns the entry BasicBlock in the collection. This is the block the function starts on.



938
939
940
# File 'lib/llvm/core/value.rb', line 938

def entry
  BasicBlock.from_ptr(C.get_entry_basic_block(@fun))
end

#firstObject

Returns the first BasicBlock in the collection.



943
944
945
946
# File 'lib/llvm/core/value.rb', line 943

def first
  ptr = C.get_first_basic_block(@fun)
  BasicBlock.from_ptr(ptr) unless ptr.null?
end

#lastObject

Returns the last BasicBlock in the collection.



949
950
951
952
# File 'lib/llvm/core/value.rb', line 949

def last
  ptr = C.get_last_basic_block(@fun)
  BasicBlock.from_ptr(ptr) unless ptr.null?
end

#sizeObject

Returns the number of BasicBlocks in the collection.



914
915
916
# File 'lib/llvm/core/value.rb', line 914

def size
  C.count_basic_blocks(@fun)
end