linker goes through assemblers, not space

used to traverse all methods in space
now "just" use the passed assemblers, which usually should be compiled and builtin (but for testing . . .)
tests fixed accordingly
This commit is contained in:
Torsten Ruger 2018-07-02 09:37:58 +03:00
parent c6f0dc636d
commit 8952b39446
2 changed files with 25 additions and 31 deletions

View File

@ -51,7 +51,7 @@ module Risc
# in place and we don't have to deal with changing loading code # in place and we don't have to deal with changing loading code
def position_all def position_all
#need the initial jump at 0 and then functions #need the initial jump at 0 and then functions
Position.new(cpu_init).set(0) #TODO Position.new(cpu_init).set(0)
code_start = position_objects( @platform.padding ) code_start = position_objects( @platform.padding )
# and then everything code # and then everything code
position_code(code_start) position_code(code_start)
@ -86,43 +86,37 @@ module Risc
# #
# start at code_start. # start at code_start.
def position_code(code_start) def position_code(code_start)
Parfait.object_space.types.values.each do |type| assemblers.each do |asm|
next unless type.methods
type.methods.each_method do |method|
#next unless method.name == :main or method.name == :__init__ #next unless method.name == :main or method.name == :__init__
Position.log.debug "Method start #{code_start.to_s(16)} #{method.name}" Position.log.debug "Method start #{code_start.to_s(16)} #{asm.method.name}"
code_pos = CodeListener.init(method.binary) code_pos = CodeListener.init(asm.method.binary, platform)
InstructionListener.init(method.cpu_instructions, method.binary) instructions = asm.instructions
code_pos.position_listener( LabelListener.new(method.cpu_instructions)) InstructionListener.init( instructions, asm.method.binary)
code_pos.position_listener( LabelListener.new(instructions))
code_pos.set(code_start) code_pos.set(code_start)
code_start = Position.get(method.binary.last_code).next_slot code_start = Position.get(asm.method.binary.last_code).next_slot
end
end end
end end
# Create Binary code for all methods and the initial jump # Create Binary code for all methods and the initial jump
# BinaryWriter handles the writing from instructions into BinaryCode objects # BinaryWriter handles the writing from instructions into BinaryCode objects
# #
# current (poor) design throws an exception when the assembly can't fit
# constant loads into one instruction.
#
def create_binary def create_binary
methods = object_positions.keys.find_all{|obj| obj.is_a? Parfait::TypedMethod} prerun
prerun(methods) assemble
assemble(methods)
log.debug "BinaryInit #{cpu_init.object_id.to_s(16)}" log.debug "BinaryInit #{cpu_init.object_id.to_s(16)}"
end end
def prerun(methods) def prerun
methods.each do |method| assemblers.each do |asm|
method.cpu_instructions.each {|i| i.precheck } asm.instructions.each {|i| i.precheck }
end end
end end
def assemble(methods) def assemble
methods.each do |method| assemblers.each do |asm|
writer = BinaryWriter.new(method.binary) writer = BinaryWriter.new(asm.method.binary)
writer.assemble(method.cpu_instructions) writer.assemble(asm.instructions)
end end
end end

View File

@ -25,18 +25,18 @@ module Risc
@linker.position_all @linker.position_all
end end
def test_positions_set def test_positions_set
@machine.object_positions.each do |obj , position| @linker.object_positions.each do |obj , position|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}" assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end end
end end
end end
class TestMachineInit #< MiniTest::Test class TestMachineInit < MiniTest::Test
def setup def setup
Parfait.boot! Parfait.boot!
@machine = Risc.machine.boot Risc.boot!
@machine.translate(:arm) @linker = Mom::MomCompiler.new.translate(:arm)
@machine.position_all @linker.position_all
@machine.create_binary @linker.create_binary
end end
def test_pos_cpu def test_pos_cpu
assert_equal 0 , Position.get(@machine.cpu_init).at assert_equal 0 , Position.get(@machine.cpu_init).at