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.



614
615
616
# File 'lib/llvm/core/value.rb', line 614

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.



637
638
639
# File 'lib/llvm/core/value.rb', line 637

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

#eachObject

Iterates through each BasicBlock in the collection.



624
625
626
627
628
629
630
631
632
633
634
# File 'lib/llvm/core/value.rb', line 624

def each
  return to_enum :each unless block_given?

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

  self
end

#entryObject

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



643
644
645
# File 'lib/llvm/core/value.rb', line 643

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

#firstObject

Returns the first BasicBlock in the collection.



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

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

#lastObject

Returns the last BasicBlock in the collection.



654
655
656
657
# File 'lib/llvm/core/value.rb', line 654

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

#sizeObject

Returns the number of BasicBlocks in the collection.



619
620
621
# File 'lib/llvm/core/value.rb', line 619

def size
  C.LLVMCountBasicBlocks(@fun)
end