rubyx/lib/risc/instructions/operator_instruction.rb

36 lines
1.0 KiB
Ruby
Raw Normal View History

module Risc
2015-08-04 21:01:20 +02:00
def self.operators
[:+, :-, :>>, :<<, :*, :&, :|]
end
2018-03-24 16:53:27 +01:00
# Destructive operator instructions on the two registers given
#
# left = left OP right
#
# With OP being the normal logical and mathematical operations provided by
# cpus. Ie "+" , "-", ">>", "<<", "*", "&", "|"
#
2015-08-04 21:01:20 +02:00
class OperatorInstruction < Instruction
2018-03-24 16:53:27 +01:00
def initialize( source , operator , left , right )
2015-08-04 21:01:20 +02:00
super(source)
2019-09-11 18:23:56 +02:00
operator = operator.value if operator.is_a?(Vool::Constant)
2015-08-04 21:01:20 +02:00
@operator = operator
2019-09-11 18:23:56 +02:00
raise "unsuported operator :#{operator}:#{operator.class}:" unless Risc.operators.include?(operator)
2015-08-04 21:01:20 +02:00
@left = left
@right = right
raise "Not register #{left}" unless RegisterValue.look_like_reg(left)
raise "Not register #{right}" unless RegisterValue.look_like_reg(right)
2015-08-04 21:01:20 +02:00
end
2015-08-07 15:46:55 +02:00
attr_reader :operator, :left , :right
2015-08-04 21:01:20 +02:00
def to_s
2018-03-22 17:38:19 +01:00
class_source "#{left} #{operator} #{right}"
2015-08-04 21:01:20 +02:00
end
2015-11-21 13:17:54 +01:00
end
2018-03-24 16:53:27 +01:00
def self.op( source , operator , left , right )
OperatorInstruction.new( source , operator , left , right )
2015-08-04 21:01:20 +02:00
end
end