2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2015-08-04 21:01:20 +02:00
|
|
|
|
2018-04-19 21:13:52 +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-10-03 23:36:49 +02:00
|
|
|
operator = operator.value if operator.is_a?(Sol::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
|
2018-06-29 10:39:07 +02:00
|
|
|
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
|