fix the cpu_init for linker

cpu_init still translates from risc_init
but since interpreter is a platform risc_init is a private thing
and the cpu_init does not need to be lazily created, so it's done in the init
This commit is contained in:
Torsten Ruger 2018-07-02 15:51:50 +03:00
parent 9bd8eab999
commit 6a4c90e2bd

View File

@ -21,11 +21,11 @@ module Risc
raise "Platform must be platform, not #{platform.class}" unless platform.is_a?(Platform) raise "Platform must be platform, not #{platform.class}" unless platform.is_a?(Platform)
@platform = platform @platform = platform
@assemblers = assemblers @assemblers = assemblers
@risc_init = nil
@constants = [] @constants = []
@cpu_init = cpu_init_init
end end
attr_reader :constants , :cpu_init attr_reader :constants
attr_reader :platform , :assemblers attr_reader :platform , :assemblers
# machine keeps a list of all objects and their positions. # machine keeps a list of all objects and their positions.
@ -35,11 +35,6 @@ module Risc
Position.positions Position.positions
end end
# lazy init risc_init
def risc_init
@risc_init ||= Branch.new( "__initial_branch__" , Parfait.object_space.get_init.risc_instructions )
end
# To create binaries, objects (and labels) need to have a position # To create binaries, objects (and labels) need to have a position
# (so objects can be loaded and branches know where to jump) # (so objects can be loaded and branches know where to jump)
# #
@ -51,7 +46,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
#TODO Position.new(cpu_init).set(0) 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)
@ -104,11 +99,12 @@ module Risc
def create_binary def create_binary
prerun prerun
assemble assemble
log.debug "BinaryInit #{cpu_init.object_id.to_s(16)}" log.debug "BinaryInit #{@cpu_init.object_id.to_s(16)}"
end end
def prerun def prerun
assemblers.each do |asm| assemblers.each do |asm|
puts "method #{asm.method.name}"
asm.instructions.each {|i| i.precheck } asm.instructions.each {|i| i.precheck }
end end
end end
@ -120,6 +116,16 @@ module Risc
end end
end end
private
# cpu_init come from translating the risc_init
# risc_init is a branch to the __init__ method
#
def cpu_init_init
init = assemblers.find {|asm| asm.method.name == :__init__}
risc_init = Branch.new( "__initial_branch__" , init.method.binary )
@platform.translator.translate(risc_init)
end
end end
# module method to reset, and init # module method to reset, and init