Class: Kumi::Core::LIR::Structs::Instruction
- Inherits:
-
Struct
- Object
- Struct
- Kumi::Core::LIR::Structs::Instruction
- 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
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#immediates ⇒ Object
Returns the value of attribute immediates.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#location ⇒ Object
Returns the value of attribute location.
-
#opcode ⇒ Object
Returns the value of attribute opcode.
-
#result_register ⇒ Object
Returns the value of attribute result_register.
-
#stamp ⇒ Object
Returns the value of attribute stamp.
Instance Method Summary collapse
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def attributes @attributes end |
#immediates ⇒ Object
Returns the value of attribute immediates
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def immediates @immediates end |
#inputs ⇒ Object
Returns the value of attribute inputs
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def inputs @inputs end |
#location ⇒ Object
Returns the value of attribute location
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def location @location end |
#opcode ⇒ Object
Returns the value of attribute opcode
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def opcode @opcode end |
#result_register ⇒ Object
Returns the value of attribute result_register
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def result_register @result_register end |
#stamp ⇒ Object
Returns the value of attribute stamp
8 9 10 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 8 def stamp @stamp end |
Instance Method Details
#produces? ⇒ Boolean
20 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 20 def produces? = !result_register.nil? |
#pure? ⇒ Boolean
26 27 28 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 26 def pure? !side_effect? end |
#side_effect? ⇒ Boolean
22 23 24 |
# File 'lib/kumi/core/lir/structs/instruction.rb', line 22 def side_effect? SIDE_EFFECT_OPCODES.include?(opcode) end |
#to_h ⇒ Object
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 |