make operator_instruction single ass

create result register automatically
usually not used, but register allocation will sort that
This commit is contained in:
2020-03-14 12:22:37 +02:00
parent 1378745907
commit 61fc8a3991
4 changed files with 43 additions and 9 deletions

View File

@ -3,33 +3,42 @@ module Risc
def self.operators
[:+, :-, :>>, :<<, :*, :&, :|]
end
# Destructive operator instructions on the two registers given
# Operator instructions on the first two registers given
# # Result into the last register
#
# left = left OP right
# result = left OP right
#
# With OP being the normal logical and mathematical operations provided by
# cpus. Ie "+" , "-", ">>", "<<", "*", "&", "|"
#
# Result may be nil, then register is autogenerated
#
class OperatorInstruction < Instruction
def initialize( source , operator , left , right )
def initialize( source , operator , left , right , result = nil)
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)
raise "Not register #{left}" unless left.is_a?(RegisterValue)
raise "Not register #{right}" unless right.is_a?(RegisterValue)
unless result
result = RegisterValue.new("op_#{operator}_#{object_id.to_s(16)}".to_sym , :Integer)
end
raise "Not register #{result}" unless result.is_a?(RegisterValue)
@result = result
end
attr_reader :operator, :left , :right
attr_reader :operator, :left , :right , :result
def to_s
class_source "#{left} #{operator} #{right}"
end
end
def self.op( source , operator , left , right )
OperatorInstruction.new( source , operator , left , right )
def self.op( source , operator , left , right , result = nil)
OperatorInstruction.new( source , operator , left , right , result)
end
end

View File

@ -23,6 +23,7 @@ module Risc
extra = {} unless extra
@extra = extra
@symbol = reg
raise "not Symbol #{symbol}:#{symbol.class}" unless symbol.is_a?(Symbol)
raise "Not Hash #{extra}" unless extra.is_a?(Hash)
known_type(type)
end