change to position objects complete

This commit is contained in:
Torsten Ruger 2018-05-05 20:25:10 +03:00
parent 3244c7d633
commit 40f4bfc287
6 changed files with 25 additions and 12 deletions

View File

@ -27,7 +27,7 @@ module Elf
type.each_method do |f|
f.cpu_instructions.each do |label|
next unless label.is_a?(Risc::Label)
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Risc::Position.position(label)
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Risc::Position.position(label).at
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}::#{Risc::Position.position(slot).to_s(16)}"
label = "#{slot.class.name}::#{Risc::Position.position(slot)}"
end
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
add_symbol label , Risc::Position.position(slot)
add_symbol label , Risc::Position.position(slot).at
if slot.is_a?(Parfait::TypedMethod)
add_symbol slot.name.to_s , Risc::Position.position(slot.binary)
add_symbol slot.name.to_s , Risc::Position.position(slot.binary).at
end
end
end

View File

@ -14,7 +14,7 @@ module Risc
class Machine
include Logging
log_level :debug
log_level :info
def initialize
@booted = false
@ -158,6 +158,7 @@ module Risc
def boot
initialize
Position.positions.clear
@objects = nil
@translated = false
boot_parfait!

View File

@ -25,13 +25,15 @@ module Risc
end
def +(offset)
offset = offset.at if offset.is_a?(Position)
@at + offset
end
def -(offset)
offset = offset.at if offset.is_a?(Position)
@at - offset
end
def to_s
@at.to_s(16)
"0x#{@at.to_s(16)}"
end
def self.positions
@ -55,7 +57,7 @@ module Risc
#puts "Setting #{pos} for #{self.class}"
old = Position.positions[object]
if old != nil and ((old - pos).abs > 1000)
raise "position set too far off #{pos}!=#{old} for #{object}"
raise "position set too far off #{pos}!=#{old} for #{object}:#{object.class}"
end
self.positions[object] = Position.new( pos )
end

View File

@ -41,7 +41,7 @@ module Risc
def write_debug
@machine.objects.each do |id , objekt|
next if objekt.is_a?(Risc::Label)
log.debug "Linked #{objekt.class}:0x#{objekt.object_id.to_s(16)} at 0x#{Position.position(objekt).to_s(16)} / 0x#{objekt.padded_length.to_s(16)}"
log.debug "Linked #{objekt.class}:0x#{objekt.object_id.to_s(16)} at #{Position.position(objekt)} / 0x#{objekt.padded_length.to_s(16)}"
end
end
@ -71,8 +71,8 @@ module Risc
# Write any object just logs a bit and passes to write_any_out
def write_any( obj )
write_any_log( obj , "Write")
if @stream.length != Position.position(obj)
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not 0x#{Position.position(obj).to_s(16)}"
if @stream.length != Position.position(obj).at
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.position(obj)}"
end
write_any_out(obj)
write_any_log( obj , "Wrote")
@ -80,7 +80,7 @@ module Risc
end
def write_any_log( obj , at)
log.debug "#{at} #{obj.class}:0x#{obj.object_id.to_s(16)} at stream 0x#{stream_position.to_s(16)} pos:0x#{Position.position(obj).to_s(16)} , len:0x#{obj.padded_length.to_s(16)}"
log.debug "#{at} #{obj.class}:0x#{obj.object_id.to_s(16)} at stream #{stream_position} pos:#{Position.position(obj)} , len:0x#{obj.padded_length.to_s(16)}"
end
# Most objects are the same and get passed to write_object
@ -178,7 +178,7 @@ module Risc
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 0x#{Position.position(string).to_s(16)} length 0x#{string.length.to_s(16)}"
log.debug "#{string.class} is #{string} at 0x#{Position.position(string)} length 0x#{string.length.to_s(16)}"
write_checked_string(string , str)
end

View File

@ -2,6 +2,9 @@ require_relative "../helper"
class HelloTest < MiniTest::Test
def setup
Risc.machine
end
def check
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{@input};end;end" )
writer = Elf::ObjectWriter.new(Risc.machine)

View File

@ -17,10 +17,17 @@ module Risc
res = Position.new(5) - 1
assert_equal 4 , res
end
def test_sub_pos
res = Position.new(5) - Position.new(1)
assert_equal 4 , res
end
def test_set
pos = Position.set_position(self , 5)
assert_equal 5 , pos.at
end
def tet_tos
assert_equal "0x10" , Position.set_position(self).to_s
end
def test_reset_ok
pos = Position.set_position(self , 5)
pos = Position.set_position(self , 10)