Class: Kumi::Core::LIR::Structs::Instruction

Inherits:
Struct
  • Object
show all
Defined in:
lib/kumi/core/lir/structs/instruction.rb

Constant Summary collapse

SIDE_EFFECT_OPCODES =
Set.new(i[
  LoopStart
  LoopEnd
  DeclareAccumulator
  Accumulate LoadAccumulator
  Yield
]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def attributes
  @attributes
end

#immediatesObject

Returns the value of attribute immediates

Returns:

  • (Object)

    the current value of immediates



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def immediates
  @immediates
end

#inputsObject

Returns the value of attribute inputs

Returns:

  • (Object)

    the current value of inputs



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def inputs
  @inputs
end

#locationObject

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def location
  @location
end

#opcodeObject

Returns the value of attribute opcode

Returns:

  • (Object)

    the current value of opcode



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def opcode
  @opcode
end

#result_registerObject

Returns the value of attribute result_register

Returns:

  • (Object)

    the current value of result_register



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def result_register
  @result_register
end

#stampObject

Returns the value of attribute stamp

Returns:

  • (Object)

    the current value of stamp



8
9
10
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8

def stamp
  @stamp
end

Instance Method Details

#produces?Boolean

Returns:

  • (Boolean)


20
# File 'lib/kumi/core/lir/structs/instruction.rb', line 20

def produces? = !result_register.nil?

#pure?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/kumi/core/lir/structs/instruction.rb', line 26

def pure?
  !side_effect?
end

#side_effect?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/kumi/core/lir/structs/instruction.rb', line 22

def side_effect?
  SIDE_EFFECT_OPCODES.include?(opcode)
end

#to_hObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/kumi/core/lir/structs/instruction.rb', line 30

def to_h
  h = { op: opcode }
  h[:result]     = result_register if result_register
  h[:stamp]      = stamp.to_h if stamp
  h[:inputs]     = inputs unless inputs.nil? || inputs.empty?
  h[:immediates] = immediates&.map { |x| x.respond_to?(:to_h) ? x.to_h : x } unless immediates.nil? || immediates.empty?
  h[:attrs]      = attributes unless attributes.nil? || attributes.empty?
  h[:loc] = { file: location.file, line: location.line, column: location.column } if location
  h
end