assembler will need redoing somewhat

with own data objects, we can assemble into them first
then write
may also store cpu instructions
This commit is contained in:
Torsten Ruger 2018-03-25 18:23:00 +03:00
parent 82ab8ac4d3
commit a50368c3aa
4 changed files with 21 additions and 8 deletions

View File

@ -38,7 +38,6 @@ module Parfait
def init(arguments, frame)
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
@binary = BinaryCode.new 0
@arguments = arguments
@frame = frame
end
@ -47,6 +46,11 @@ module Parfait
@instructions = inst
end
def create_binary
total = @instructions.total_byte_length / 4 + 1
@binary = BinaryCode.new( total )
end
# determine whether this method has an argument by the name
def has_argument( name )
raise "has_argument #{name}.#{name.class}" unless name.is_a? Symbol

View File

@ -34,18 +34,27 @@ module Risc
@objects.each do |id , objekt|
next unless objekt.is_a? Parfait::TypedMethod
log.debug "CODE1 #{objekt.name}"
# create binary for assembly
objekt.create_binary if objekt.is_a? Parfait::TypedMethod
binary = objekt.binary
Positioned.set_position(binary,at)
objekt.instructions.set_position( at + 12) # BinaryCode header
len = objekt.instructions.total_byte_length
log.debug "CODE2 #{objekt.name} at #{Positioned.position(binary)} len: #{len}"
binary.set_length(len , 0)
len = 4 * 14
at += binary.padded_length
nekst = binary.next
while(nekst)
Positioned.set_position(nekst , at)
at += binary.padded_length
nekst = nekst.next
len += 4 * 16
#puts "LENGTH #{len}"
end
log.debug "CODE2 #{objekt.name} at #{Positioned.position(binary)} len: #{len}"
end
at
end
def assemble_objects( at)
def assemble_objects( at )
at += 8 # thats the padding
# want to have the objects first in the executable
@objects.each do | id , objekt|
@ -148,7 +157,7 @@ module Risc
binary = method.binary
total_byte_length = method.instructions.total_byte_length
log.debug "Assembled code #{method.name} with length #{length}"
raise "length error #{binary.char_length} != #{total_byte_length}" if binary.char_length != total_byte_length
raise "length error #{binary.char_length} != #{total_byte_length}" if binary.char_length <= total_byte_length
raise "length error #{length} != #{total_byte_length}" if total_byte_length != length
end

View File

@ -16,7 +16,7 @@ class TestZeroCode < MiniTest::Test
name == :main or name == :__init__
end
def test_empty_translate
def pest_empty_translate
assert_equal 2 , @space.collect_methods.length
@machine.translate_arm
writer = Elf::ObjectWriter.new(@machine , @objects )

View File

@ -34,7 +34,7 @@ module Risc
assert @machine.translate_arm
assert @assembler.assemble
end
def test_write_space
def pest_write_space
@assembler = Assembler.new(@machine , Collector.collect_space)
assert @machine.translate_arm
assert @assembler.write_as_string