diff --git a/lib/arm/instructions/instruction.rb b/lib/arm/instructions/instruction.rb index 32296595..386950a5 100644 --- a/lib/arm/instructions/instruction.rb +++ b/lib/arm/instructions/instruction.rb @@ -23,11 +23,12 @@ module Arm def insert(instruction) super - @next.set_position( Risc::Position.position(self) + self.byte_length , 0) #FIXME + my_pos = Risc::Position.position(self) + @next.set_position( my_pos + self.byte_length , 0 , my_pos.binary) end - def set_position( position , count ) - Risc::Position.set_position(self,position) + def set_position( position , count , extra = nil) + Risc::Position.set_position(self,position , extra) position += byte_length if self.next count += 1 #assumes 4 byte instructions, as does the whole setup @@ -35,7 +36,7 @@ module Arm count = 0 position += 12 # 12=3*4 , 3 for marker,type,next words to jump over end - self.next.set_position( position , count ) + self.next.set_position( position , count , extra) else position end diff --git a/lib/risc/instructions/label.rb b/lib/risc/instructions/label.rb index 37ca0f50..582f61af 100644 --- a/lib/risc/instructions/label.rb +++ b/lib/risc/instructions/label.rb @@ -45,9 +45,9 @@ module Risc end # labels have the same position as their next - def set_position( position , count = 0) - Position.set_position(self,position) - self.next.set_position(position,count) if self.next + def set_position( position , count = 0 , extra = nil) + Position.set_position(self,position , extra) + self.next.set_position(position,count,extra) if self.next end # shame we need this, just for logging diff --git a/lib/risc/machine.rb b/lib/risc/machine.rb index f6d70f33..956b4f0b 100644 --- a/lib/risc/machine.rb +++ b/lib/risc/machine.rb @@ -78,7 +78,7 @@ module Risc translate_arm unless @translated #need the initial jump at 0 and then functions Position.set_position(binary_init,0) - cpu_init.set_position( 12 ,0) + cpu_init.set_position( 12 ,0 , binary_init) @code_start = position_objects( binary_init.padded_length ) # and then everything code position_code @@ -110,7 +110,7 @@ module Risc at = @code_start objects.each do |id , method| next unless method.is_a? Parfait::TypedMethod - method.cpu_instructions.set_position( at + 12) + method.cpu_instructions.set_position( at + 12 , 0 , method.binary) before = at nekst = method.binary while(nekst) diff --git a/lib/risc/position.rb b/lib/risc/position.rb index b0f7faf7..39f20e4c 100644 --- a/lib/risc/position.rb +++ b/lib/risc/position.rb @@ -36,12 +36,14 @@ module Risc "0x#{@at.to_s(16)}" end def reset_to(pos) + return false if pos == at if((at - pos).abs > 1000) raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}" end @at = pos - self + true end + def self.positions @positions end @@ -62,7 +64,10 @@ module Risc # in measures (of 32) #puts "Setting #{pos} for #{self.class}" old = Position.positions[object] - return old.reset_to(pos) if old != nil + if old != nil + old.reset_to(pos) + return old + end self.positions[object] = for_at( object , pos , extra) end @@ -71,7 +76,7 @@ module Risc when Parfait::BinaryCode BPosition.new(object,at , extra) when Arm::Instruction , Risc::Label - IPosition.new(object,at) + IPosition.new(object,at , extra) else Position.new(at) end @@ -79,11 +84,22 @@ module Risc end # handle event propagation class IPosition < Position - attr_reader :instruction - def initialize(instruction, pos) + attr_reader :instruction , :binary + def initialize(instruction, pos , binary) + raise "not set " unless binary super(pos) @instruction = instruction + @binary = binary end + + def reset_to(pos) + changed = super(pos) + puts "Reset (#{changed}) #{instruction}" + return unless changed + return unless instruction.next + instruction.next.set_position( pos + instruction.byte_length , 0) + end + end class BPosition < Position attr_reader :code , :method