Move the Main instruction from register to virtual
also needs a branch in register. This way the register level is self sufficient (noticed while writing debugger)
This commit is contained in:
parent
60d09ab057
commit
50da6a40f2
@ -112,6 +112,7 @@ module Arm
|
||||
end
|
||||
Arm::ArmMachine.init
|
||||
require_relative "passes/call_implementation"
|
||||
require_relative "passes/branch_implementation"
|
||||
require_relative "passes/syscall_implementation"
|
||||
require_relative "passes/save_implementation"
|
||||
require_relative "passes/transfer_implementation"
|
||||
@ -119,4 +120,3 @@ require_relative "passes/get_implementation"
|
||||
require_relative "passes/set_implementation"
|
||||
require_relative "passes/return_implementation"
|
||||
require_relative "passes/constant_implementation"
|
||||
require_relative "passes/main_implementation"
|
||||
|
17
lib/arm/passes/branch_implementation.rb
Normal file
17
lib/arm/passes/branch_implementation.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Arm
|
||||
# This implements branch logic, which is simply assembler branch
|
||||
#
|
||||
# The only target for a call is a Block, so we just need to get the address for the code
|
||||
# and branch to it.
|
||||
#
|
||||
class BranchImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Register::Branch
|
||||
br = ArmMachine.b( code.block )
|
||||
block.replace(code , br )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual.machine.add_pass "Arm::BranchImplementation"
|
||||
end
|
@ -1,17 +0,0 @@
|
||||
module Arm
|
||||
|
||||
# "Boot" the register machine at the function given
|
||||
# meaning jump to that function currently. Maybe better to do some machine setup
|
||||
# and possibly some cleanup/exit has to tie in, but that is not this day
|
||||
|
||||
class MainImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Register::RegisterMain
|
||||
call = ArmMachine.b( code.method )
|
||||
block.replace(code , call )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual.machine.add_pass "Arm::MainImplementation"
|
||||
end
|
@ -23,7 +23,7 @@ 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.info.blocks.each do |b|
|
||||
f.source.blocks.each do |b|
|
||||
add_symbol "#{clazz.name}::#{f.name}:#{b.name}" , b.position
|
||||
end
|
||||
end
|
||||
|
@ -43,4 +43,4 @@ require_relative "instructions/function_call"
|
||||
require_relative "instructions/function_return"
|
||||
require_relative "instructions/save_return"
|
||||
require_relative "instructions/register_transfer"
|
||||
require_relative "instructions/register_main"
|
||||
require_relative "instructions/branch"
|
||||
|
12
lib/register/instructions/branch.rb
Normal file
12
lib/register/instructions/branch.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module Register
|
||||
|
||||
|
||||
# a branch must branch to a block.
|
||||
class Branch < Instruction
|
||||
def initialize to
|
||||
raise "No block" unless to
|
||||
@block = to
|
||||
end
|
||||
attr_reader :block
|
||||
end
|
||||
end
|
17
lib/register/passes/main_implementation.rb
Normal file
17
lib/register/passes/main_implementation.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Register
|
||||
|
||||
# "Boot" the virtual machine at the function given
|
||||
# meaning jump to that function currently. Maybe better to do some machine setup
|
||||
# and possibly some cleanup/exit has to tie in, but that is not this day
|
||||
|
||||
class MainImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Virtual::VirtualMain
|
||||
branch = Register::Branch.new( code.method.source.blocks.first )
|
||||
block.replace(code , branch )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual.machine.add_pass "Register::MainImplementation"
|
||||
end
|
@ -1,6 +1,7 @@
|
||||
require_relative "instruction"
|
||||
require_relative "register_reference"
|
||||
require_relative "assembler"
|
||||
require_relative "passes/main_implementation"
|
||||
require_relative "passes/frame_implementation"
|
||||
require_relative "passes/message_implementation"
|
||||
require_relative "passes/set_implementation"
|
||||
|
@ -26,3 +26,4 @@ require_relative "instructions/method_return"
|
||||
require_relative "instructions/new_frame"
|
||||
require_relative "instructions/new_message"
|
||||
require_relative "instructions/set"
|
||||
require_relative "instructions/virtual_main"
|
||||
|
@ -1,11 +1,11 @@
|
||||
module Register
|
||||
module Virtual
|
||||
|
||||
# This starts the register machine machine at the given function.
|
||||
# This starts the Virtual machine machine at the given function.
|
||||
|
||||
# The implementation is most likely a jump/branch , but since we have the extra layer
|
||||
# we make good use of it, ie give things descriptive names (what they do, not how)
|
||||
|
||||
class RegisterMain < Instruction
|
||||
class VirtualMain < Instruction
|
||||
include Positioned
|
||||
|
||||
def initialize method
|
@ -124,7 +124,7 @@ module Virtual
|
||||
return if @booted
|
||||
boot_parfait!
|
||||
@init = Block.new("init",nil)
|
||||
@init.add_code Register::RegisterMain.new( self.space.get_init )
|
||||
@init.add_code Virtual::VirtualMain.new( self.space.get_init )
|
||||
@booted = true
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user