diff --git a/lib/risc/machine.rb b/lib/risc/machine.rb index 2fec8cb6..357709d6 100644 --- a/lib/risc/machine.rb +++ b/lib/risc/machine.rb @@ -50,7 +50,7 @@ module Risc # machine keeps a list of all objects and their positions. # this is lazily created with a collector def object_positions - Collector.collect_space if Position.positions.empty? + Collector.collect_space if Position.positions.length < 2 #one is the label Position.positions end @@ -105,9 +105,7 @@ module Risc sorted.each do |objekt| next unless Position.is_object(objekt) before = at - unless( Position.set?(objekt)) - raise objekt.class - end + raise objekt.class unless( Position.set?(objekt)) #debug check position = Position.get(objekt).set(at) previous.position_listener(objekt) if previous previous = position @@ -145,7 +143,7 @@ module Risc # constant loads into one instruction. # def create_binary - object_positions.each do |method,position| + object_positions.keys.each do |method| next unless method.is_a? Parfait::TypedMethod writer = BinaryWriter.new(method.binary) writer.assemble(method.cpu_instructions) diff --git a/lib/risc/position/code_listener.rb b/lib/risc/position/code_listener.rb index eae0cc39..3eaba0e4 100644 --- a/lib/risc/position/code_listener.rb +++ b/lib/risc/position/code_listener.rb @@ -13,6 +13,7 @@ module Risc Position.log.debug "extending one at #{position}" pos = CodeListener.init( position.object.next ) return unless position.valid? + puts "insert #{position.object.next.object_id.to_s(16)}" unless position.valid? pos.set( position + position.object.padded_length) set_jump_for(position) end diff --git a/lib/risc/position/instruction_listener.rb b/lib/risc/position/instruction_listener.rb index 570424a0..1ca0a716 100644 --- a/lib/risc/position/instruction_listener.rb +++ b/lib/risc/position/instruction_listener.rb @@ -91,8 +91,7 @@ module Risc while(instruction) position = Position.get_or_create(instruction) first = position unless first - il = InstructionListener.new( code ) - position.position_listener(il) + position.position_listener( InstructionListener.new( code ) ) if instruction.respond_to?(:branch) # label_pos = Position.get(instruction.branch) # label_pos.position_listener( BranchListener.new(il)) diff --git a/lib/risc/position/position.rb b/lib/risc/position/position.rb index 59e0ef98..5e4139ea 100644 --- a/lib/risc/position/position.rb +++ b/lib/risc/position/position.rb @@ -69,7 +69,7 @@ module Risc def set(int) return int if int == self.at trigger_changing( int ) - Position.set_to(self , int) + Position.set_cache(self , int) @at = int trigger_changed self @@ -157,9 +157,9 @@ module Risc if pos == nil str = "position accessed but not initialized, " str += "0x#{object.object_id.to_s(16)}\n" - str += "for #{object.class} " + str += "class: #{object.class} " str += "byte_length #{object.byte_length}" if object.respond_to?(:byte_length) - str += " for #{object.to_s[0...130]}" + str += " object: #{object.to_s[0...130]}" raise str end pos @@ -186,7 +186,7 @@ module Risc # forward caches object -> position # reverse caches position.at > position # Labels do not participatein reverse cache - def self.set_to( position , to) + def self.set_cache( position , to) postest = Position.positions[position.object] unless to < 0 raise "Mismatch #{position}" if postest and postest != position @reverse_cache.delete(position.at) unless position.object.is_a?(Label) diff --git a/lib/risc/position/position_listener.rb b/lib/risc/position/position_listener.rb index d92dd1c5..546c9c6e 100644 --- a/lib/risc/position/position_listener.rb +++ b/lib/risc/position/position_listener.rb @@ -19,15 +19,14 @@ module Risc def position_changing(position , to) end - # when the argument changes position, we update the objects + # when the argument changes position, we update the next objects # position to reflect that change # def position_changed(previous) add = previous.object ? previous.object.padded_length : 0 - my_pos = previous.at + add - object_pos = Position.get(@object) - return if my_pos == object_pos.at - Position.set_to(object_pos , my_pos) + next_at = previous.at + add + next_pos = Position.get(@object) + next_pos.set(next_at) end end end diff --git a/lib/risc/text_writer.rb b/lib/risc/text_writer.rb index d560aef4..6701bdc8 100644 --- a/lib/risc/text_writer.rb +++ b/lib/risc/text_writer.rb @@ -104,7 +104,6 @@ module Risc # write type of the instance, and the variables that are passed # variables ar values, ie int or refs. For refs the object needs to save the object first def write_object( object ) - write_object_check(object) obj_written = write_object_variables(object) log.debug "instances=#{object.get_instance_variables.inspect} mem_len=0x#{object.padded_length.to_s(16)}" indexed_written = write_object_indexed(object) @@ -114,15 +113,6 @@ module Risc Position.get(object) end - 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 - unless object.is_a?(Parfait::BinaryCode) - log.debug "Object at 0x#{Position.get(object)}:#{object.get_type()}" - raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}" - end - end - def write_object_indexed(object) written = 0 if( object.is_a? Parfait::List) diff --git a/test/risc/position/test_position_listener.rb b/test/risc/position/test_position_listener.rb index 007e79c4..128004a8 100644 --- a/test/risc/position/test_position_listener.rb +++ b/test/risc/position/test_position_listener.rb @@ -15,7 +15,7 @@ module Risc end def test_no_fire @pos.position_listener(self) - Position.set_to(@pos,0) + @pos.set(0) assert_equal 0 , Position.get(@object).at end def test_at diff --git a/test/risc/test_text_writer.rb b/test/risc/test_text_writer.rb index 184aadf1..f6bdac4a 100644 --- a/test/risc/test_text_writer.rb +++ b/test/risc/test_text_writer.rb @@ -33,6 +33,7 @@ module Risc sorted_objects = @text_writer.sorted_objects sorted_objects.each_slice(2) do |l,r| next unless r + next if l.is_a?(Label) or r.is_a?(Label) assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}" end end @@ -41,6 +42,7 @@ module Risc sorted_objects.shift sorted_objects.each_slice(2) do |l,r| next unless r + next if l.is_a?(Label) or r.is_a?(Label) assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}" end end diff --git a/test/risc/test_translator.rb b/test/risc/test_translator.rb index 2ef4ad1f..8ade50a2 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.object_positions.each do |method , position| + @machine.object_positions.keys.each do |method| next unless method.is_a? Parfait::TypedMethod method.cpu_instructions.each do |ins| ins.assemble(DevNull.new)