fix all positioned uses as helper (not included anymore)

This commit is contained in:
Torsten Ruger 2017-01-01 21:52:55 +02:00
parent cd474f66f6
commit 0397d4064d
4 changed files with 22 additions and 21 deletions

View File

@ -48,7 +48,7 @@ module Arm
# relative addressing for jumps/calls
# but because of the arm "theoretical" 3- stage pipeline,
# we have to subtract 2 words (fetch/decode)
arg = @first.position - self.position - 8
arg = Positioned.position(@first) - Positioned.position(self) - 8
when Parfait::TypedMethod
# But, for methods, this happens to be the size of the object header,
# so there it balances out, but not blocks

View File

@ -91,7 +91,7 @@ module Arm
(@left.is_a?(Symbol) and !Register::RegisterValue.look_like_reg(@left)))
# do pc relative addressing with the difference to the instuction
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
right = @left.position - self.position - 8
right = Positioned.position(@left) - Positioned.position(self) - 8
if( (right < 0) && ((opcode == :add) || (opcode == :sub)) )
right *= -1 # this works as we never issue sub only add
set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode

View File

@ -27,7 +27,7 @@ module Elf
Parfait.object_space.each_type do |type|
type.methods.each do |f|
f.instructions.each_label do |label|
add_symbol "#{type.name}::#{f.name}:#{label.name}" , label.position
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Positioned.position(label)
end
end
end
@ -37,12 +37,12 @@ module Elf
if( slot.respond_to? :sof_reference_name )
label = "#{slot.sof_reference_name}"
else
label = "#{slot.class.name}::#{slot.position.to_s(16)}"
label = "#{slot.class.name}::#{Positioned.position(slot).to_s(16)}"
end
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
add_symbol label , slot.position
add_symbol label , Positioned.position(slot)
if slot.is_a?(Parfait::TypedMethod)
add_symbol slot.name.to_s , slot.binary.position
add_symbol slot.name.to_s , Positioned.position(slot.binary)
end
end
end

View File

@ -23,7 +23,7 @@ module Register
def assemble
at = 0
#need the initial jump at 0 and then functions
@machine.init.set_position(0)
@machine.init.set_position( 0)
at = @machine.init.byte_length
at = assemble_objects( at )
# and then everything code
@ -35,10 +35,10 @@ module Register
next unless objekt.is_a? Parfait::TypedMethod
log.debug "CODE1 #{objekt.name}"
binary = objekt.binary
binary.set_position( at )
objekt.instructions.set_position( at + 12 )# BinaryCode header
Positioned.set_position(binary,at)
objekt.instructions.set_position( at + 12) # BinaryCode header
len = objekt.instructions.total_byte_length
log.debug "CODE2 #{objekt.name} at #{binary.position} len: #{len}"
log.debug "CODE2 #{objekt.name} at #{Positioned.position(binary)} len: #{len}"
binary.set_length(len , 0)
at += binary.padded_length
end
@ -51,7 +51,7 @@ module Register
@objects.each do | id , objekt|
next if objekt.is_a? Register::Label # will get assembled as method.instructions
next if objekt.is_a? Parfait::BinaryCode
objekt.set_position at
Positioned.set_position(objekt,at)
at += objekt.padded_length
end
at
@ -81,11 +81,11 @@ module Register
# debugging loop accesses all positions to force an error if it's not set
def try_write_debug
all = @objects.values.sort{|a,b| a.position <=> b.position}
all = @objects.values.sort{|a,b| Positioned.position(a) <=> Positioned.position(b)}
all.each do |objekt|
next if objekt.is_a?(Register::Label)
log.debug "Linked #{objekt.class}(#{objekt.object_id}) at #{objekt.position} / #{objekt.padded_length}"
objekt.position
log.debug "Linked #{objekt.class}(#{objekt.object_id}) at #{Positioned.position(objekt)} / #{objekt.padded_length}"
Positioned.position(objekt)
end
end
@ -101,6 +101,7 @@ module Register
@stream.write_unsigned_int_8(0)
end
end
def try_write_objects
# then the objects , not code yet
@objects.each do | id, objekt|
@ -153,16 +154,16 @@ module Register
def write_any obj
write_any_log( obj , "Write")
if @stream.length != obj.position
raise "Write #{obj.class} #{obj.object_id} at #{stream_position} not #{obj.position}"
if @stream.length != Positioned.position(obj)
raise "Write #{obj.class} #{obj.object_id} at #{stream_position} not #{Positioned.position(obj)}"
end
write_any_out(obj)
write_any_log( obj , "Wrote")
obj.position
Positioned.position(obj)
end
def write_any_log( obj , at)
log.debug "#{at} #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{obj.position} , len:#{obj.padded_length}"
log.debug "#{at} #{obj.class}(#{obj.object_id}) at stream #{stream_position} pos:#{Positioned.position(obj)} , len:#{obj.padded_length}"
end
def write_any_out(obj)
@ -182,7 +183,7 @@ module Register
log.debug "type #{obj_written} , total #{obj_written + indexed_written} (array #{indexed_written})"
log.debug "Len = #{object.get_length} , inst = #{object.get_type.instance_length}" if object.is_a? Parfait::Type
pad_after( obj_written + indexed_written )
object.position
Positioned.position(object)
end
def write_object_check(object)
@ -225,7 +226,7 @@ module Register
raise "length mismatch #{str.length} != #{string.char_length}" if str.length != string.char_length
end
str = string.to_s if string.is_a? Symbol
log.debug "#{string.class} is #{string} at #{string.position} length #{string.length}"
log.debug "#{string.class} is #{string} at #{Positioned.position(string)} length #{string.length}"
write_checked_string(string , str)
end
@ -253,7 +254,7 @@ module Register
when Fixnum
@stream.write_signed_int_32(object)
else
@stream.write_signed_int_32(object.position + @load_at)
@stream.write_signed_int_32(Positioned.position(object) + @load_at)
end
end