move all position setting into position
Position and subclasses handle the logic, external to the classes, so it can be swapped out later (at runtime positions can’t change)
This commit is contained in:
@ -44,12 +44,6 @@ module Risc
|
||||
ret
|
||||
end
|
||||
|
||||
# labels have the same position as their next
|
||||
def set_position( position , count = 0 , extra = nil)
|
||||
Position.set(self,position , extra)
|
||||
self.next.set_position(position,count,extra) if self.next
|
||||
end
|
||||
|
||||
# shame we need this, just for logging
|
||||
def byte_length
|
||||
0
|
||||
|
@ -78,7 +78,7 @@ module Risc
|
||||
translate_arm unless @translated
|
||||
#need the initial jump at 0 and then functions
|
||||
Position.set(binary_init,0)
|
||||
cpu_init.set_position( 12 ,0 , binary_init)
|
||||
Position.set(cpu_init , 3 , binary_init)
|
||||
@code_start = position_objects( binary_init.padded_length )
|
||||
# and then everything code
|
||||
position_code
|
||||
@ -91,8 +91,8 @@ module Risc
|
||||
# want to have the objects first in the executable
|
||||
objects.each do | id , objekt|
|
||||
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
|
||||
Position.set(objekt,at)
|
||||
before = at
|
||||
Position.set(objekt,at)
|
||||
at += objekt.padded_length
|
||||
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
end
|
||||
@ -110,14 +110,16 @@ module Risc
|
||||
at = @code_start
|
||||
objects.each do |id , method|
|
||||
next unless method.is_a? Parfait::TypedMethod
|
||||
method.cpu_instructions.set_position( at + 12 , 0 , method.binary)
|
||||
before = at
|
||||
nekst = method.binary
|
||||
while(nekst)
|
||||
Position.set(nekst , at , method)
|
||||
at += nekst.padded_length
|
||||
nekst = nekst.next
|
||||
end
|
||||
Position.set( method.binary , at , method)
|
||||
Position.set( method.cpu_instructions, 3 , method.binary)
|
||||
# before = at
|
||||
# nekst = method.binary
|
||||
# while(nekst)
|
||||
# Position.set(nekst , at , method)
|
||||
# at += nekst.padded_length
|
||||
# nekst = nekst.next
|
||||
# end
|
||||
log.debug "Method #{method.name}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
log.debug "Instructions #{method.cpu_instructions.object_id.to_s(16)}:#{(before+12).to_s(16)}"
|
||||
end
|
||||
|
@ -35,6 +35,9 @@ module Risc
|
||||
def to_s
|
||||
"0x#{@at.to_s(16)}"
|
||||
end
|
||||
# just a callback after creation AND insertion
|
||||
def init
|
||||
end
|
||||
def reset_to(pos)
|
||||
return false if pos == at
|
||||
if((at - pos).abs > 1000)
|
||||
@ -72,7 +75,10 @@ module Risc
|
||||
old.reset_to(pos)
|
||||
return old
|
||||
end
|
||||
self.positions[object] = for_at( object , pos , extra)
|
||||
position = for_at( object , pos , extra)
|
||||
self.positions[object] = position
|
||||
position.init
|
||||
position
|
||||
end
|
||||
|
||||
def self.for_at(object , at , extra)
|
||||
@ -96,9 +102,26 @@ module Risc
|
||||
@binary = binary
|
||||
end
|
||||
|
||||
def set_position( position , binary = nil)
|
||||
raise "invalid position #{position}" if position > 15
|
||||
binary = Risc::Position.get(self).binary unless binary
|
||||
Risc::Position.set(self, position , binary)
|
||||
position += byte_length / 4 #assumes 4 byte instructions, as does the whole setup
|
||||
if self.next
|
||||
if( 3 == position % 15) # 12 is the amount of instructions that fit into a BinaryCode
|
||||
position = 3
|
||||
binary = binary.next
|
||||
end
|
||||
self.next.set_position( position , binary)
|
||||
else
|
||||
position
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def reset_to(pos)
|
||||
changed = super(pos)
|
||||
puts "Reset (#{changed}) #{instruction}"
|
||||
#puts "Reset (#{changed}) #{instruction}"
|
||||
return unless changed
|
||||
return unless instruction.next
|
||||
instruction.next.set_position( pos + instruction.byte_length , 0)
|
||||
|
Reference in New Issue
Block a user