From 09210730254b47436d027d9326b06e0cb5e0adc4 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 25 Oct 2015 12:03:31 +0200 Subject: [PATCH] remove last block occurrences fixed. --- Gemfile.lock | 2 +- lib/elf/object_writer.rb | 9 +++------ lib/register/assembler.rb | 12 ++++-------- lib/register/instruction.rb | 5 +++++ lib/register/instructions/branch.rb | 5 +++++ lib/register/instructions/label.rb | 7 +++++++ lib/register/method_source.rb | 2 +- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 83f053e1..ae1b6410 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/salama/salama-arm.git - revision: b6acdc95e954aa1580faa7eaf34685625be6fdbe + revision: eaba799b1773771328842b1b3d59fb07fa712c87 specs: salama-arm (0.3.0) diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 2fce81d7..49331b7d 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -24,15 +24,12 @@ module Elf # for debug add labels to the block positions @object_machine.space.classes.values.each do |clazz| clazz.instance_methods.each do |f| - f.source.blocks.each do |b| - add_symbol "#{clazz.name}::#{f.name}:#{b.name}" , b.position + f.source.instructions.each_label do |label| + add_symbol "#{clazz.name}::#{f.name}:#{label.name}" , label.position end end end -# @object_machine.space.main.blocks.each do |b| -# add_symbol "main@#{b.name}" , b.position -# end -# add_symbol "#register@#{@object_machine.space.init.name}" , @object_machine.space.init.position + @object_machine.objects.each do |id,slot| if( slot.respond_to? :sof_reference_name ) label = "#{slot.sof_reference_name}" diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index de9e0eae..73a3a159 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -32,7 +32,7 @@ module Register end #need the initial jump at 0 and then functions @machine.init.set_position(at) - at += @machine.init.total_byte_length + at += @machine.init.byte_length at += 8 # thats the padding # then we make sure we really get the binary codes first @@ -61,7 +61,6 @@ module Register return try_write rescue LinkException # knowing that we fix the problem, we hope to get away with retry. - puts "retry" retry end end @@ -82,9 +81,7 @@ module Register assemble_binary_method(objekt) end @stream = StringIO.new - @machine.init.codes.each do |code| - code.assemble( @stream ) - end + @machine.init.assemble( @stream ) 8.times do @stream.write_uint8(0) end @@ -107,9 +104,9 @@ module Register # and then plonk that binary data into the method.code array def assemble_binary_method method stream = StringIO.new - puts "Method #{method.source.instructions.to_ac}" + #puts "Method #{method.source.instructions.to_ac}" begin - puts "assemble #{method.source.instructions}" + #puts "assemble #{method.source.instructions}" method.source.instructions.assemble_all( stream ) rescue => e puts "Assembly error #{method.name}\n#{Sof.write(method.source.instructions).to_s[0...2000]}" @@ -227,7 +224,6 @@ module Register @stream.write_uint8(0) end after = stream_position - before - after # shut up the linter #puts "padded #{length.to_s(16)} with #{pad.to_s(16)} stream #{before}/#{after}" end diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index ccecedbe..0002d751 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -106,6 +106,11 @@ module Register position end end + + def each_label labels =[] , &block + self.next.each_label(labels , &block) if self.next + end + end end diff --git a/lib/register/instructions/branch.rb b/lib/register/instructions/branch.rb index 77306603..a5edb203 100644 --- a/lib/register/instructions/branch.rb +++ b/lib/register/instructions/branch.rb @@ -45,6 +45,11 @@ module Register self.next.assemble_all(io, labels) if self.next end + def each_label labels =[] , &block + super + self.label.each_label(labels , &block) if self.label + end + end class IsZero < Branch diff --git a/lib/register/instructions/label.rb b/lib/register/instructions/label.rb index 966c1853..3b4dca84 100644 --- a/lib/register/instructions/label.rb +++ b/lib/register/instructions/label.rb @@ -56,5 +56,12 @@ module Register self.position = position self.next.set_position(position,labels) end + + def each_label labels =[] , &block + return if labels.include?(self) + labels << self + block.yield(self) + super + end end end diff --git a/lib/register/method_source.rb b/lib/register/method_source.rb index 5b89da30..7d60769a 100644 --- a/lib/register/method_source.rb +++ b/lib/register/method_source.rb @@ -46,7 +46,7 @@ module Register def init method , return_type = nil set_return_type( return_type ) - @instructions = @current = Label.new(self, "Method_#{method.name}") + @instructions = @current = Label.new(self, "#{method.for_class.name}_#{method.name}") add_code enter = Register.save_return(self, :message , :return_address) add_code Label.new( method, "return") # move the current message to new_message