Class: RLTK::CG::BasicBlock
Overview
A BasicBlock is what instructions are inserted into and what functions are made of. BasicBlock objects may be created either using BasicBlock.new or using the Function::BasicBlockCollection#append method.
Defined Under Namespace
Classes: InstructionCollection
Instance Attribute Summary
Attributes included from BindingClass
Instance Method Summary collapse
-
#build(builder = nil, *block_args, &block) ⇒ Object
Used to add instructions to a BasicBlock.
-
#initialize(overloaded, name = '', builder = nil, context = nil, *block_args, &block) ⇒ BasicBlock
constructor
Create a new BasicBlock object.
-
#insert_before(name = '', context = nil) ⇒ BasicBlock
Creates a new BasicBlock inserted immediately before this block.
-
#instructions ⇒ InstructionCollect
Collection of all instructions inside this BasicBlock.
-
#next ⇒ BasicBlock?
BasicBlock that occures immediately after this block or nil.
-
#parent ⇒ Function
Function object that this BasicBlock belongs to.
-
#previous ⇒ BasicBlock?
BasicBlock that occures immediately before this block or nil.
Methods inherited from Value
#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast
Methods included from BindingClass
Constructor Details
#initialize(overloaded, name = '', builder = nil, context = nil, *block_args, &block) ⇒ BasicBlock
Create a new BasicBlock object. The way the block is created is determined by the overloaded parameter. If it is a Function object then the new block is appended to the end of the function. If overloaded is another BasicBlock object the new block will be inserted before that block.
A block may be given to this function to be invoked by #build.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rltk/cg/basic_block.rb', line 42 def initialize(overloaded, name = '', builder = nil, context = nil, *block_args, &block) check_type(context, Context, 'context') if context @ptr = case overloaded when FFI::Pointer overloaded when Function if context Bindings.append_basic_block_in_context(context, overloaded, name) else Bindings.append_basic_block(overloaded, name) end when BasicBlock if context Bindings.insert_basic_block_in_context(context, overloaded, name) else Bindings.insert_basic_block(overloaded, name) end end self.build(builder, *block_args, &block) if block end |
Instance Method Details
#build(builder = nil, *block_args, &block) ⇒ Object
Used to add instructions to a BasicBlock. The block given to this method is executed inside the context of a RLTK::CG::Builder object, either the one passed in the builder parameter or one created for this call. Arguments may be passed into this block via the block_args parameter.
85 86 87 |
# File 'lib/rltk/cg/basic_block.rb', line 85 def build(builder = nil, *block_args, &block) if builder then builder else Builder.new end.build(self, *block_args, &block) end |
#insert_before(name = '', context = nil) ⇒ BasicBlock
Creates a new BasicBlock inserted immediately before this block.
95 96 97 |
# File 'lib/rltk/cg/basic_block.rb', line 95 def insert_before(name = '', context = nil) BasicBlock.new(self, name, context) end |
#instructions ⇒ InstructionCollect
Returns Collection of all instructions inside this BasicBlock.
100 101 102 |
# File 'lib/rltk/cg/basic_block.rb', line 100 def instructions @instructions ||= InstructionCollection.new(self) end |
#next ⇒ BasicBlock?
Returns BasicBlock that occures immediately after this block or nil.
105 106 107 |
# File 'lib/rltk/cg/basic_block.rb', line 105 def next if (ptr = Bindings.get_next_basic_block(@ptr)).null? then nil else BasicBlock.new(ptr) end end |
#parent ⇒ Function
Returns Function object that this BasicBlock belongs to.
110 111 112 |
# File 'lib/rltk/cg/basic_block.rb', line 110 def parent if (ptr = Bindings.get_basic_block_parent(@ptr)).null? then nil else Function.new(ptr) end end |
#previous ⇒ BasicBlock?
Returns BasicBlock that occures immediately before this block or nil.
115 116 117 |
# File 'lib/rltk/cg/basic_block.rb', line 115 def previous if (ptr = Bindings.get_previous_basic_block(@ptr)).null? then nil else BasicBlock.new(ptr) end end |