rubyx/lib/risc/instructions/operator_instruction.rb
Torsten Rüger d1f8733623 Rename Vool to Sol
Simple is really the descriptive name for the layer
Sure, it is "virtual" but that is not as important as the fact that it is simple (or simplified)
Also objct (based really) is better, since orientated implies it is a little like that, but only orientated, not really it. Sol only has objects, nothing else
Just cause i was renaming anyway
2019-10-04 00:38:47 +03:00

36 lines
1.0 KiB
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.value if operator.is_a?(Sol::Constant)
@operator = operator
raise "unsuported operator :#{operator}:#{operator.class}:" 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