diff --git a/lib/arm/compare_instruction.rb b/lib/arm/compare_instruction.rb index da966350..ea805303 100644 --- a/lib/arm/compare_instruction.rb +++ b/lib/arm/compare_instruction.rb @@ -29,7 +29,7 @@ module Arm arg = Register::RegisterReference.new( arg ) end if (arg.is_a?(Virtual::IntegerConstant)) - if (arg.integer.fits_u8?) + if (arg.fits_u8?) # no shifting needed operand = arg.integer immediate = 1 diff --git a/lib/arm/constants.rb b/lib/arm/constants.rb index ec4a7eb3..e0102bed 100644 --- a/lib/arm/constants.rb +++ b/lib/arm/constants.rb @@ -78,7 +78,7 @@ module Arm else u8_imm = parts[1].to_i(2) end - if (u8_imm.fits_u8?) + if (Virtual::IntegerConstant.new(u8_imm).fits_u8?) # can do! rot_imm = (pre_zeros+imm_len) / 2 if (rot_imm > 15) diff --git a/lib/arm/logic_instruction.rb b/lib/arm/logic_instruction.rb index 0ffab048..f4e3c903 100644 --- a/lib/arm/logic_instruction.rb +++ b/lib/arm/logic_instruction.rb @@ -31,7 +31,7 @@ module Arm right = Virtual::IntegerConstant.new( right ) end if (right.is_a?(Virtual::IntegerConstant)) - if true #TODO (right.integer.fits_u8?) + if true #TODO (right.fits_u8?) # no shifting needed operand = right.integer immediate = 1 diff --git a/lib/arm/move_instruction.rb b/lib/arm/move_instruction.rb index beb5e178..023f407c 100644 --- a/lib/arm/move_instruction.rb +++ b/lib/arm/move_instruction.rb @@ -35,7 +35,7 @@ module Arm right = Virtual::IntegerConstant.new( r_pos - self.position - 8 ) end if (right.is_a?(Virtual::IntegerConstant)) - if (right.integer.fits_u8?) + if (right.fits_u8?) return true elsif (calculate_u8_with_rr(right)) return true @@ -63,7 +63,7 @@ module Arm rn = :pc end if (right.is_a?(Virtual::IntegerConstant)) - if (right.integer.fits_u8?) + if (right.fits_u8?) # no shifting needed operand = right.integer immediate = 1 @@ -75,7 +75,7 @@ module Arm operand = right.integer / 256 immediate = 1 -# raise "cannot fit numeric literal argument in operand #{right.inspect}" + raise "cannot fit numeric literal argument in operand #{right.inspect}" end elsif (right.is_a?(Symbol) or right.is_a?(Virtual::Integer)) operand = reg_code(right) #integer means the register the integer is in (otherwise constant) diff --git a/lib/stream_reader.rb b/lib/stream_reader.rb index 45598c87..ed88b079 100644 --- a/lib/stream_reader.rb +++ b/lib/stream_reader.rb @@ -1,9 +1,3 @@ -class Numeric - def fits_u8? - self >= 0 and self <= 255 - end -end - module StreamReader def read_binary(size, count, type) d = __sr_read(size*count) diff --git a/lib/virtual/constants.rb b/lib/virtual/constants.rb index 63987b75..892f4f76 100644 --- a/lib/virtual/constants.rb +++ b/lib/virtual/constants.rb @@ -28,6 +28,9 @@ module Virtual def type Virtual::Integer end + def fits_u8? + integer >= 0 and integer <= 255 + end end # The name really says it all.