more refactoring on compare

This commit is contained in:
Torsten Ruger 2016-12-15 12:38:03 +02:00
parent ec2b0a563e
commit fdefb8e7a5

View File

@ -10,7 +10,6 @@ module Arm
@right = right.is_a?(Fixnum) ? IntegerConstant.new(right) : right @right = right.is_a?(Fixnum) ? IntegerConstant.new(right) : right
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil @attributes[:condition_code] = :al if @attributes[:condition_code] == nil
@operand = 0 @operand = 0
@immediate = 0
@attributes[:update_status] = 1 @attributes[:update_status] = 1
@rn = left @rn = left
@rd = :r0 @rd = :r0
@ -18,9 +17,7 @@ module Arm
def assemble(io) def assemble(io)
# don't overwrite instance variables, to make assembly repeatable # don't overwrite instance variables, to make assembly repeatable
rn = @rn rn , operand , immediate= @rn , @operand , 1
operand = @operand
immediate = @immediate
arg = @right arg = @right
if arg.is_a?(Parfait::Object) if arg.is_a?(Parfait::Object)
@ -29,25 +26,13 @@ module Arm
arg = arg.position - self.position - 8 arg = arg.position - self.position - 8
rn = :pc rn = :pc
end end
if( arg.is_a? Symbol ) operand = Register::RegisterValue.new( arg , :Integer) if( arg.is_a? Symbol )
arg = Register::RegisterValue.new( arg , :Integer) case operand
end when Numeric
if (arg.is_a?(Numeric)) operand = handle_numeric(arg)
if (arg.fits_u8?) when Symbol , ::Register::RegisterValue
# no shifting needed
operand = arg
immediate = 1
elsif (op_with_rot = calculate_u8_with_rr(arg))
operand = op_with_rot
immediate = 1
raise "hmm"
else
raise "cannot fit numeric literal argument in operand #{arg.inspect}"
end
elsif (arg.is_a?(Symbol) or arg.is_a?(::Register::RegisterValue))
operand = arg
immediate = 0 immediate = 0
elsif (arg.is_a?(Arm::Shift)) when Arm::Shift
handle_shift handle_shift
else else
raise "invalid operand argument #{arg.inspect} , #{inspect}" raise "invalid operand argument #{arg.inspect} , #{inspect}"
@ -61,11 +46,22 @@ module Arm
val |= shift(@attributes[:update_status], 12 + 4 + 4)#20 val |= shift(@attributes[:update_status], 12 + 4 + 4)#20
val |= shift(op_bit_code , 12 + 4 + 4 + 1) val |= shift(op_bit_code , 12 + 4 + 4 + 1)
val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= shift(immediate , 12 + 4 + 4 + 1 + 4)
val |= shift(instuction_class , 12 + 4 + 4 + 1 + 4 + 1) val |= instruction_code
val |= shift(cond_bit_code , 12 + 4 + 4 + 1 + 4 + 1 + 2) val |= condition_code
io.write_uint32 val io.write_uint32 val
end end
def handle_numeric(arg)
if (arg.fits_u8?) # no shifting needed
return arg
elsif (op_with_rot = calculate_u8_with_rr(arg))
#operand = op_with_rot
raise "hmm"
else
raise "cannot fit numeric literal argument in operand #{arg.inspect}"
end
end
def instuction_class def instuction_class
0b00 # OPC_DATA_PROCESSING 0b00 # OPC_DATA_PROCESSING
end end