2017-01-19 09:02:29 +02:00
|
|
|
module Risc
|
2015-08-04 22:01:20 +03:00
|
|
|
|
2018-04-19 22:13:52 +03:00
|
|
|
def self.operators
|
|
|
|
[:+, :-, :>>, :<<, :*, :&, :|]
|
|
|
|
end
|
2018-03-24 17:53:27 +02: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 22:01:20 +03:00
|
|
|
class OperatorInstruction < Instruction
|
2018-03-24 17:53:27 +02:00
|
|
|
def initialize( source , operator , left , right )
|
2015-08-04 22:01:20 +03:00
|
|
|
super(source)
|
2019-10-04 00:36:49 +03:00
|
|
|
operator = operator.value if operator.is_a?(Sol::Constant)
|
2015-08-04 22:01:20 +03:00
|
|
|
@operator = operator
|
2019-09-11 19:23:56 +03:00
|
|
|
raise "unsuported operator :#{operator}:#{operator.class}:" unless Risc.operators.include?(operator)
|
2015-08-04 22:01:20 +03:00
|
|
|
@left = left
|
|
|
|
@right = right
|
2018-06-29 11:39:07 +03:00
|
|
|
raise "Not register #{left}" unless RegisterValue.look_like_reg(left)
|
|
|
|
raise "Not register #{right}" unless RegisterValue.look_like_reg(right)
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
2015-08-07 16:46:55 +03:00
|
|
|
attr_reader :operator, :left , :right
|
2015-08-04 22:01:20 +03:00
|
|
|
|
|
|
|
def to_s
|
2018-03-22 18:38:19 +02:00
|
|
|
class_source "#{left} #{operator} #{right}"
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
|
|
|
|
2015-11-21 14:17:54 +02:00
|
|
|
end
|
2018-03-24 17:53:27 +02:00
|
|
|
def self.op( source , operator , left , right )
|
|
|
|
OperatorInstruction.new( source , operator , left , right )
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|