From 047c77e1867c94c4c6f395bfd7cf2ce7a8d77624 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 1 Jul 2015 09:47:10 +0300 Subject: [PATCH] fixed that darn method address bug --- lib/arm/instructions/call_instruction.rb | 1 - lib/arm/instructions/logic_instruction.rb | 3 ++- lib/arm/instructions/move_instruction.rb | 6 ++---- lib/register/assembler.rb | 3 +-- lib/virtual/compiled_method_info.rb | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/arm/instructions/call_instruction.rb b/lib/arm/instructions/call_instruction.rb index 1e6f003a..07b5b765 100644 --- a/lib/arm/instructions/call_instruction.rb +++ b/lib/arm/instructions/call_instruction.rb @@ -44,7 +44,6 @@ module Arm # so there it balances out, but not blocks # have to use the code, not the mthod object for methods diff = arg.code.position - self.position - diff -= 4 if diff > 0 # hmm, stil having troubles with this one. but it works :-) end arg = diff end diff --git a/lib/arm/instructions/logic_instruction.rb b/lib/arm/instructions/logic_instruction.rb index 6bc54e9e..a2c0fd29 100644 --- a/lib/arm/instructions/logic_instruction.rb +++ b/lib/arm/instructions/logic_instruction.rb @@ -48,6 +48,7 @@ module Arm #TODO this is copied from MoveInstruction, should rework unless @extra @extra = 1 + puts "RELINK L at #{self.position.to_s(16)}" raise ::Register::LinkException.new("cannot fit numeric literal argument in operand #{right.inspect}") end # now we can do the actual breaking of instruction, by splitting the operand @@ -87,7 +88,7 @@ module Arm val << by end - def word_length + def byte_length @extra ? 8 : 4 end diff --git a/lib/arm/instructions/move_instruction.rb b/lib/arm/instructions/move_instruction.rb index f442faa2..b45377f4 100644 --- a/lib/arm/instructions/move_instruction.rb +++ b/lib/arm/instructions/move_instruction.rb @@ -18,9 +18,6 @@ module Arm @immediate = 0 @rn = :r0 # register zero = zero bit pattern @extra = nil - if @rn.is_a?(Numeric) and !@rn.fits_u8? and !calculate_u8_with_rr(@rn) - @extra = 1 - end end attr_accessor :to , :from @@ -31,7 +28,7 @@ module Arm # alas, full transparency is not achieved as we only know when to use 2 instruction once we # know where the other object is, and that position is only set after code positions have been # determined (in link) and so see below in assemble - def word_length + def byte_length @extra ? 8 : 4 end @@ -65,6 +62,7 @@ module Arm # then on subsequent assemblies we can assemble unless @extra @extra = 1 + puts "RELINK M at #{self.position.to_s(16)}" raise ::Register::LinkException.new("cannot fit numeric literal argument in operand #{right.inspect}") end # now we can do the actual breaking of instruction, by splitting the operand diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 7d4327cc..4dd65282 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -60,7 +60,6 @@ module Register begin return try_write rescue LinkException - puts "RELINK" # knowing that we fix the problem, we hope to get away with retry. return try_write end @@ -123,7 +122,7 @@ module Register stream.rewind #puts "Assembled #{method.name} with length #{stream.length}" raise "length error #{method.code.length} != #{method.info.byte_length}" if method.code.length != method.info.byte_length - raise "length error #{stream.length} != #{method.info.byte_length}" if method.info.byte_length - stream.length > 6 + raise "length error #{stream.length} != #{method.info.byte_length}" if method.info.byte_length != stream.length stream.each_byte do |b| method.code.set_char(index , b ) index = index + 1 diff --git a/lib/virtual/compiled_method_info.rb b/lib/virtual/compiled_method_info.rb index 98e3b92d..b5b3d0c3 100644 --- a/lib/virtual/compiled_method_info.rb +++ b/lib/virtual/compiled_method_info.rb @@ -137,7 +137,7 @@ module Virtual end def byte_length - @blocks.inject(0) { |c , block| c += block.byte_length } + 4 + @blocks.inject(0) { |c , block| c += block.byte_length } end # position of the function is the position of the entry block, is where we call