From a5b4f3d9ad6c6a29d1b9dde684a7c9d6f82471d5 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 14 May 2014 12:08:06 +0300 Subject: [PATCH] remove NumLiteral, replace with IntegerConstant --- lib/arm/call_instruction.rb | 16 ++++++++-------- lib/arm/logic_helper.rb | 14 +++++++------- lib/arm/memory_instruction.rb | 2 +- lib/arm/nodes.rb | 7 ------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/arm/call_instruction.rb b/lib/arm/call_instruction.rb index 18664ee4..e4ab3fd2 100644 --- a/lib/arm/call_instruction.rb +++ b/lib/arm/call_instruction.rb @@ -32,14 +32,14 @@ module Arm arg = @attributes[:left] #puts "BLAB #{arg.inspect}" if( arg.is_a? Fixnum ) #HACK to not have to change the code just now - arg = Arm::NumLiteral.new( arg ) + arg = Vm::IntegerConstant.new( arg ) end - if arg.is_a? Vm::Code + if arg.is_a? Vm::Block diff = arg.position - self.position - 8 - arg = Arm::NumLiteral.new(diff) + arg = Vm::IntegerConstant.new(diff) end - if (arg.is_a?(Arm::NumLiteral)) - jmp_val = arg.value >> 2 + if (arg.is_a?(Vm::IntegerConstant)) + jmp_val = arg.integer >> 2 packed = [jmp_val].pack('l') # signed 32-bit, condense to 24-bit # TODO add check that the value fits into 24 bits @@ -51,10 +51,10 @@ module Arm when :swi arg = @attributes[:left] if( arg.is_a? Fixnum ) #HACK to not have to change the code just now - arg = Arm::NumLiteral.new( arg ) + arg = Vm::IntegerConstant.new( arg ) end - if (arg.is_a?(Arm::NumLiteral)) - packed = [arg.value].pack('L')[0,3] + if (arg.is_a?(Vm::IntegerConstant)) + packed = [arg.integer].pack('L')[0,3] io << packed io.write_uint8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4) else diff --git a/lib/arm/logic_helper.rb b/lib/arm/logic_helper.rb index 2b22c1d6..47201ddc 100644 --- a/lib/arm/logic_helper.rb +++ b/lib/arm/logic_helper.rb @@ -25,19 +25,19 @@ module Arm if arg.is_a?(Vm::StringConstant) # do pc relative addressing with the difference to the instuction # 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute) - arg = Arm::NumLiteral.new( arg.position - self.position - 8 ) + arg = Vm::IntegerConstant.new( arg.position - self.position - 8 ) @rn = :pc end if( arg.is_a? Fixnum ) #HACK to not have to change the code just now - arg = Arm::NumLiteral.new( arg ) + arg = Vm::IntegerConstant.new( arg ) end if( arg.is_a? Vm::Integer ) #HACK to not have to change the code just now - arg = Arm::NumLiteral.new( arg.value ) + arg = Vm::IntegerConstant.new( arg.value ) end - if (arg.is_a?(Arm::NumLiteral)) - if (arg.value.fits_u8?) + if (arg.is_a?(Vm::IntegerConstant)) + if (arg.integer.fits_u8?) # no shifting needed - @operand = arg.value + @operand = arg.integer @i = 1 elsif (op_with_rot = calculate_u8_with_rr(arg)) @operand = op_with_rot @@ -59,7 +59,7 @@ module Arm end arg1 = arg.value - if (arg1.is_a?(Arm::NumLiteral)) + if (arg1.is_a?(Vm::IntegerConstant)) if (arg1.value >= 32) raise "cannot shift by more than 31 #{arg1} #{inspect}" end diff --git a/lib/arm/memory_instruction.rb b/lib/arm/memory_instruction.rb index 082377f7..febe4606 100644 --- a/lib/arm/memory_instruction.rb +++ b/lib/arm/memory_instruction.rb @@ -57,7 +57,7 @@ module Arm if (@operand.abs > 4095) raise "reference offset too large/small (max 4095) #{arg} #{inspect}" end - elsif (arg.is_a?(Arm::Label) or arg.is_a?(Arm::NumLiteral)) + elsif (arg.is_a?(Arm::Label) or arg.is_a?(Vm::IntegerConstant)) @pre_post_index = 1 @rn = pc @use_addrtable_reloc = true diff --git a/lib/arm/nodes.rb b/lib/arm/nodes.rb index 112a6f52..c95950ce 100644 --- a/lib/arm/nodes.rb +++ b/lib/arm/nodes.rb @@ -34,11 +34,4 @@ module Arm end end - class NumLiteral - attr_accessor :value - def initialize val - @value = val - end - end - end