fix instruction positioning
use at as at and only compute difference when needed (to determine if there is a jump in binary) Easier to understand that way
This commit is contained in:
@ -112,7 +112,7 @@ module Risc
|
||||
next unless method.is_a? Parfait::TypedMethod
|
||||
before = at
|
||||
Position.set( method.binary , at , method)
|
||||
Position.set( method.cpu_instructions, 3 , method.binary)
|
||||
Position.set( method.cpu_instructions, at + 12 , method.binary)
|
||||
# before = at
|
||||
# nekst = method.binary
|
||||
# while(nekst)
|
||||
|
@ -65,7 +65,7 @@ module Risc
|
||||
when Arm::Instruction , Risc::Label
|
||||
InstructionPosition.new(object,at , extra)
|
||||
else
|
||||
ObjectPosition.new(at)
|
||||
ObjectPosition.new(at,object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,16 @@
|
||||
module Risc
|
||||
module Position
|
||||
|
||||
# BinaryCodes form a linked list
|
||||
#
|
||||
# We want to keep all code for a method continous, so we propagate Positions
|
||||
#
|
||||
class CodePosition < ObjectPosition
|
||||
|
||||
attr_reader :code , :method
|
||||
|
||||
def initialize(code, pos , method)
|
||||
super(pos)
|
||||
super(pos,code)
|
||||
@code = code
|
||||
@method = method
|
||||
end
|
||||
|
@ -1,23 +1,37 @@
|
||||
module Risc
|
||||
module Position
|
||||
|
||||
# Instructions are also a linked list, but their position is not really
|
||||
# the position of the object.
|
||||
# Rather it is the position of the assembled code in the binary.
|
||||
# (Luckily arm is sane, so this is realtively simple)
|
||||
#
|
||||
# Really we only need to calculate Positions at a jump, so between the
|
||||
# Jump and the label it jumps too. The other instructions are "just" fill.
|
||||
# But off course we need to propagate positions to get it right.
|
||||
#
|
||||
# Assembled instructions are kept in BinaryCode objects.
|
||||
# When propagating positions we have to see that the next position assembles into
|
||||
# the same BinaryCode, or else move it and the code along
|
||||
#
|
||||
class InstructionPosition < ObjectPosition
|
||||
attr_reader :instruction , :binary
|
||||
def initialize(instruction, pos , binary)
|
||||
raise "not set " unless binary
|
||||
super(pos)
|
||||
super(pos, instruction)
|
||||
@instruction = instruction
|
||||
@binary = binary
|
||||
end
|
||||
|
||||
def init(at)
|
||||
diff = at - Position.get(@binary).at
|
||||
if( diff % 60 == 13*4)
|
||||
@binary.extend_one unless @binary.next
|
||||
@binary = @binary.next
|
||||
raise "end of line " unless @binary
|
||||
at = Position.get(@binary).at + 3*4
|
||||
end
|
||||
return unless instruction.next
|
||||
at += instruction.byte_length
|
||||
bin = binary
|
||||
if( 12 == at % 60)
|
||||
at = 12
|
||||
bin = binary.next
|
||||
end
|
||||
Position.set(instruction.next, at , binary)
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
module Risc
|
||||
module Position
|
||||
class ObjectPosition
|
||||
attr_reader :at
|
||||
attr_reader :at , :object
|
||||
|
||||
def initialize( at )
|
||||
def initialize( at , object)
|
||||
@at = at
|
||||
raise "not int #{self}-#{at}" unless @at.is_a?(Integer)
|
||||
end
|
||||
|
@ -72,7 +72,7 @@ module Risc
|
||||
def write_any( obj )
|
||||
write_any_log( obj , "Write")
|
||||
if @stream.length != Position.get(obj).at
|
||||
puts "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.get(obj)}"
|
||||
#puts "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.get(obj)}"
|
||||
end
|
||||
write_any_out(obj)
|
||||
write_any_log( obj , "Wrote")
|
||||
|
Reference in New Issue
Block a user