Class: Kumi::IR::Base::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/ir/base/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, parameters: [], blocks: []) ⇒ Function

Returns a new instance of Function.



9
10
11
12
13
# File 'lib/kumi/ir/base/function.rb', line 9

def initialize(name:, parameters: [], blocks: [])
  @name = name.to_sym
  @parameters = parameters.map(&:to_sym)
  @blocks = blocks.map { |b| ensure_block(b) }
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



7
8
9
# File 'lib/kumi/ir/base/function.rb', line 7

def blocks
  @blocks
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/kumi/ir/base/function.rb', line 7

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



7
8
9
# File 'lib/kumi/ir/base/function.rb', line 7

def parameters
  @parameters
end

Instance Method Details

#append_block(block) ⇒ Object



19
20
21
# File 'lib/kumi/ir/base/function.rb', line 19

def append_block(block)
  @blocks << ensure_block(block)
end

#entry_blockObject



15
16
17
# File 'lib/kumi/ir/base/function.rb', line 15

def entry_block
  @blocks.first
end

#to_hObject



23
24
25
26
27
28
29
# File 'lib/kumi/ir/base/function.rb', line 23

def to_h
  {
    name:,
    parameters:,
    blocks: @blocks.map { |b| { name: b.name, instructions: b.instructions.map(&:to_h) } }
  }
end