diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 072bd64d..59cf4dc2 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -36,7 +36,7 @@ module Elf end end - @machine.objects.each do |id,slot| + @machine.object_positions.each do |slot , position| next if slot.is_a?(Parfait::BinaryCode) if( slot.respond_to? :rxf_reference_name ) label = "#{slot.rxf_reference_name}" diff --git a/lib/risc/collector.rb b/lib/risc/collector.rb index 15d1efcc..fc6b6470 100644 --- a/lib/risc/collector.rb +++ b/lib/risc/collector.rb @@ -30,7 +30,7 @@ module Risc # Objects are data and get assembled after functions def self.add_object( objekt , depth) - return false if @objects[objekt.object_id] + return false if @objects[objekt] return true if objekt.is_a? Fixnum return true if objekt.is_a?( Risc::Label) #puts message(objekt , depth) @@ -39,7 +39,7 @@ module Risc raise "adding non parfait #{objekt.class}:#{objekt}" end #raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod - @objects[objekt.object_id] = objekt + @objects[objekt] = objekt true end diff --git a/lib/risc/machine.rb b/lib/risc/machine.rb index 54f83296..e879dd7b 100644 --- a/lib/risc/machine.rb +++ b/lib/risc/machine.rb @@ -47,8 +47,9 @@ module Risc end end - # machine keeps a list of all objects. this is lazily created with a collector - def objects + # machine keeps a list of all objects and their positions. + # this is lazily created with a collector + def object_positions @objects ||= Collector.collect_space end @@ -96,7 +97,9 @@ module Risc # return final position that is stored in code_start def position_objects(at) # want to have the objects first in the executable - sorted = objects.values.sort{|left,right| left.class.name <=> right.class.name} + sorted = object_positions.values.sort do |left,right| + left.class.name <=> right.class.name + end previous = nil sorted.each do | objekt| next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label ) @@ -141,7 +144,7 @@ module Risc # constant loads into one instruction. # def create_binary - objects.each do |id , method| + object_positions.each do |id , method| next unless method.is_a? Parfait::TypedMethod writer = BinaryWriter.new(method.binary) writer.assemble(method.cpu_instructions) diff --git a/lib/risc/text_writer.rb b/lib/risc/text_writer.rb index e83dc558..78aec1ba 100644 --- a/lib/risc/text_writer.rb +++ b/lib/risc/text_writer.rb @@ -35,7 +35,7 @@ module Risc end def sorted_objects - @machine.objects.values.sort do |left , right| + @machine.object_positions.values.sort do |left , right| Position.get(left).at <=> Position.get(right).at end end @@ -118,7 +118,7 @@ module Risc def write_object_check(object) log.debug "Write object #{object.class} #{object.inspect[0..100]}" #Only initially created codes are collected. Binary_init and method "tails" not - if !@machine.objects.has_key?(object.object_id) and !object.is_a?(Parfait::BinaryCode) + if !@machine.object_positions.has_key?(object) and !object.is_a?(Parfait::BinaryCode) log.debug "Object at 0x#{Position.get(object).to_s(16)}:#{object.get_type()}" raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}" end diff --git a/test/risc/position/test_position3.rb b/test/risc/position/test_position3.rb index 1c4ef676..aacb7045 100644 --- a/test/risc/position/test_position3.rb +++ b/test/risc/position/test_position3.rb @@ -34,7 +34,7 @@ module Risc end def has_positions(platform) setup_for(platform) - @machine.objects.each do |id,obj| + @machine.object_positions.each do |obj , pos| assert Position.get(obj) end end diff --git a/test/risc/test_interpreter_platform.rb b/test/risc/test_interpreter_platform.rb index 504d75dd..8baae9d9 100644 --- a/test/risc/test_interpreter_platform.rb +++ b/test/risc/test_interpreter_platform.rb @@ -54,7 +54,7 @@ module Risc @machine.translate(:interpreter) @machine.position_all @machine.create_binary - @machine.objects.each do |id , method| + @machine.object_positions.each do | method , position| next unless method.is_a? Parfait::TypedMethod method.cpu_instructions.each do |ins| ins.assemble(DevNull.new) diff --git a/test/risc/test_machine.rb b/test/risc/test_machine.rb index e2715836..c4f0da62 100644 --- a/test/risc/test_machine.rb +++ b/test/risc/test_machine.rb @@ -7,7 +7,7 @@ module Risc @machine = Risc.machine.boot end def test_objects - objects = @machine.objects + objects = @machine.object_positions assert_equal Hash , objects.class assert 350 < objects.length end @@ -41,7 +41,7 @@ module Risc @machine.position_all end def test_positions_set - @machine.objects.each do |id,obj| + @machine.object_positions.each do |id,obj| assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}" end end @@ -71,7 +71,7 @@ module Risc assert 0 != bin.get_word(0) , "index 0 is 0 #{bin.inspect}" end def test_positions_set - @machine.objects.each do |id,obj| + @machine.object_positions.each do |id,obj| assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}" end end diff --git a/test/risc/test_translator.rb b/test/risc/test_translator.rb index 1c579e8d..2ef4ad1f 100644 --- a/test/risc/test_translator.rb +++ b/test/risc/test_translator.rb @@ -30,7 +30,7 @@ module Risc def test_no_risc #by assembling, risc doesnt have assemble method @machine.translate(:arm) @machine.position_all - @machine.objects.each do |id , method| + @machine.object_positions.each do |method , position| next unless method.is_a? Parfait::TypedMethod method.cpu_instructions.each do |ins| ins.assemble(DevNull.new)