diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index 06f0ee48..39d146ce 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -12,14 +12,15 @@ module Parfait def initialize(total_size) super() if total_size > self.data_length - @next = BinaryCode.new(total_size - data_length) #one for the jump + @next = BinaryCode.new(total_size - data_length) end - #puts "Init with #{total_size} for #{object_id}" + puts "Init with #{total_size} for #{object_id}" (1..(data_length+1)).each{ |index| set_word(index , 0) } end def to_s "BinaryCode #{}" end + #16 - 2 -1 , two instance varaibles and one for the jump def data_length 13 end diff --git a/lib/risc/assembler.rb b/lib/risc/assembler.rb index 01f4a016..97571edd 100644 --- a/lib/risc/assembler.rb +++ b/lib/risc/assembler.rb @@ -33,26 +33,27 @@ module Risc at += 8 # thats the padding # want to have the objects first in the executable @objects.each do | id , objekt| - if objekt.is_a? Risc::Label # will get assembled as method.cpu_instructions + case objekt + when Risc::Label # will get assembled as method.cpu_instructions Positioned.set_position(objekt,at) - next + when Parfait::BinaryCode + else + Positioned.set_position(objekt,at) + at += objekt.padded_length end - next if objekt.is_a? Parfait::BinaryCode - Positioned.set_position(objekt,at) - at += objekt.padded_length end at end def position_code_from( at ) - @objects.each do |id , objekt| - next unless objekt.is_a? Parfait::TypedMethod - log.debug "CODE1 #{objekt.name}" + @objects.each do |id , method| + next unless method.is_a? Parfait::TypedMethod + log.debug "CODE1 #{method.name}" # create binary for assembly - objekt.create_binary if objekt.is_a? Parfait::TypedMethod - binary = objekt.binary + method.create_binary + binary = method.binary Positioned.set_position(binary,at) - objekt.cpu_instructions.set_position( at + 12) # BinaryCode header + method.cpu_instructions.set_position( at + 12) # BinaryCode header len = 4 * 14 at += binary.padded_length nekst = binary.next @@ -63,7 +64,7 @@ module Risc len += 4 * 16 #puts "LENGTH #{len}" end - log.debug "CODE2 #{objekt.name} at #{Positioned.position(binary)} len: #{len}" + log.debug "CODE2 #{method.name} at #{Positioned.position(binary)} len: #{len}" end at end @@ -74,7 +75,7 @@ module Risc write_debug write_create_binary write_objects - write_method + write_code log.debug "Assembled #{stream_position} bytes" return @stream.string end @@ -111,7 +112,7 @@ module Risc end end - def write_method + def write_code # then write the methods to file @objects.each do |id, objekt| next unless objekt.is_a? Parfait::BinaryCode @@ -121,7 +122,7 @@ module Risc # assemble the MethodSource into a stringio # and then plonk that binary data into the method.code array - def assemble_binary_method method + def assemble_binary_method( method ) stream = StringIO.new #puts "Method #{method.source.cpu_instructions.to_ac}" begin diff --git a/lib/risc/instruction.rb b/lib/risc/instruction.rb index 21b20db7..5befdba2 100644 --- a/lib/risc/instruction.rb +++ b/lib/risc/instruction.rb @@ -36,24 +36,10 @@ module Risc ret end - # derived classes must provide a byte_length - def byte_length - raise "Abstract called on #{self}" - end - def to_cpu( translator ) translator.translate( self ) end - def assemble_all( io ) - self.assemble(io) - self.next.assemble_all(io) if self.next - end - - def assemble io - raise "Abstract called on #{self}" - end - def total_byte_length ret = 0 self.each{|ins| ret += ins.byte_length} diff --git a/lib/risc/instructions/label.rb b/lib/risc/instructions/label.rb index 5bf64f76..0d0b5425 100644 --- a/lib/risc/instructions/label.rb +++ b/lib/risc/instructions/label.rb @@ -31,6 +31,10 @@ module Risc @name.split(".").length == 2 end + def assemble_all( io ) + self.each {|ins| ins.assemble(io)} + end + def assemble io end