rubyx/lib/risc/instructions/operator_instruction.rb
Torsten Ruger d50893bb0f rename risc_value to register_value
almost to register, but it still carries that value
2018-06-29 11:39:07 +03:00

35 lines
986 B
Ruby

module Risc
def self.operators
[:+, :-, :>>, :<<, :*, :&, :|]
end
# 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 "+" , "-", ">>", "<<", "*", "&", "|"
#
class OperatorInstruction < Instruction
def initialize( source , operator , left , right )
super(source)
@operator = operator
raise "unsuported operator :#{operator}:" unless Risc.operators.include?(operator)
@left = left
@right = right
raise "Not register #{left}" unless RegisterValue.look_like_reg(left)
raise "Not register #{right}" unless RegisterValue.look_like_reg(right)
end
attr_reader :operator, :left , :right
def to_s
class_source "#{left} #{operator} #{right}"
end
end
def self.op( source , operator , left , right )
OperatorInstruction.new( source , operator , left , right )
end
end