change to position objects complete
This commit is contained in:
parent
3244c7d633
commit
40f4bfc287
@ -27,7 +27,7 @@ module Elf
|
|||||||
type.each_method do |f|
|
type.each_method do |f|
|
||||||
f.cpu_instructions.each do |label|
|
f.cpu_instructions.each do |label|
|
||||||
next unless label.is_a?(Risc::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
|
end
|
||||||
end
|
end
|
||||||
@ -37,12 +37,12 @@ module Elf
|
|||||||
if( slot.respond_to? :sof_reference_name )
|
if( slot.respond_to? :sof_reference_name )
|
||||||
label = "#{slot.sof_reference_name}"
|
label = "#{slot.sof_reference_name}"
|
||||||
else
|
else
|
||||||
label = "#{slot.class.name}::#{Risc::Position.position(slot).to_s(16)}"
|
label = "#{slot.class.name}::#{Risc::Position.position(slot)}"
|
||||||
end
|
end
|
||||||
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
|
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)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ module Risc
|
|||||||
|
|
||||||
class Machine
|
class Machine
|
||||||
include Logging
|
include Logging
|
||||||
log_level :debug
|
log_level :info
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@booted = false
|
@booted = false
|
||||||
@ -158,6 +158,7 @@ module Risc
|
|||||||
|
|
||||||
def boot
|
def boot
|
||||||
initialize
|
initialize
|
||||||
|
Position.positions.clear
|
||||||
@objects = nil
|
@objects = nil
|
||||||
@translated = false
|
@translated = false
|
||||||
boot_parfait!
|
boot_parfait!
|
||||||
|
@ -25,13 +25,15 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def +(offset)
|
def +(offset)
|
||||||
|
offset = offset.at if offset.is_a?(Position)
|
||||||
@at + offset
|
@at + offset
|
||||||
end
|
end
|
||||||
def -(offset)
|
def -(offset)
|
||||||
|
offset = offset.at if offset.is_a?(Position)
|
||||||
@at - offset
|
@at - offset
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
@at.to_s(16)
|
"0x#{@at.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.positions
|
def self.positions
|
||||||
@ -55,7 +57,7 @@ module Risc
|
|||||||
#puts "Setting #{pos} for #{self.class}"
|
#puts "Setting #{pos} for #{self.class}"
|
||||||
old = Position.positions[object]
|
old = Position.positions[object]
|
||||||
if old != nil and ((old - pos).abs > 1000)
|
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
|
end
|
||||||
self.positions[object] = Position.new( pos )
|
self.positions[object] = Position.new( pos )
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ module Risc
|
|||||||
def write_debug
|
def write_debug
|
||||||
@machine.objects.each do |id , objekt|
|
@machine.objects.each do |id , objekt|
|
||||||
next if objekt.is_a?(Risc::Label)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ module Risc
|
|||||||
# Write any object just logs a bit and passes to write_any_out
|
# Write any object just logs a bit and passes to write_any_out
|
||||||
def write_any( obj )
|
def write_any( obj )
|
||||||
write_any_log( obj , "Write")
|
write_any_log( obj , "Write")
|
||||||
if @stream.length != Position.position(obj)
|
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 0x#{Position.position(obj).to_s(16)}"
|
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.position(obj)}"
|
||||||
end
|
end
|
||||||
write_any_out(obj)
|
write_any_out(obj)
|
||||||
write_any_log( obj , "Wrote")
|
write_any_log( obj , "Wrote")
|
||||||
@ -80,7 +80,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write_any_log( obj , at)
|
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
|
end
|
||||||
|
|
||||||
# Most objects are the same and get passed to write_object
|
# 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
|
raise "length mismatch #{str.length} != #{string.char_length}" if str.length != string.char_length
|
||||||
end
|
end
|
||||||
str = string.to_s if string.is_a? Symbol
|
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)
|
write_checked_string(string , str)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ require_relative "../helper"
|
|||||||
|
|
||||||
class HelloTest < MiniTest::Test
|
class HelloTest < MiniTest::Test
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Risc.machine
|
||||||
|
end
|
||||||
def check
|
def check
|
||||||
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{@input};end;end" )
|
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{@input};end;end" )
|
||||||
writer = Elf::ObjectWriter.new(Risc.machine)
|
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||||
|
@ -17,10 +17,17 @@ module Risc
|
|||||||
res = Position.new(5) - 1
|
res = Position.new(5) - 1
|
||||||
assert_equal 4 , res
|
assert_equal 4 , res
|
||||||
end
|
end
|
||||||
|
def test_sub_pos
|
||||||
|
res = Position.new(5) - Position.new(1)
|
||||||
|
assert_equal 4 , res
|
||||||
|
end
|
||||||
def test_set
|
def test_set
|
||||||
pos = Position.set_position(self , 5)
|
pos = Position.set_position(self , 5)
|
||||||
assert_equal 5 , pos.at
|
assert_equal 5 , pos.at
|
||||||
end
|
end
|
||||||
|
def tet_tos
|
||||||
|
assert_equal "0x10" , Position.set_position(self).to_s
|
||||||
|
end
|
||||||
def test_reset_ok
|
def test_reset_ok
|
||||||
pos = Position.set_position(self , 5)
|
pos = Position.set_position(self , 5)
|
||||||
pos = Position.set_position(self , 10)
|
pos = Position.set_position(self , 10)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user