diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index e24fdb97..6c0743b1 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -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" diff --git a/lib/arm/passes/branch_implementation.rb b/lib/arm/passes/branch_implementation.rb new file mode 100644 index 00000000..20b9b19a --- /dev/null +++ b/lib/arm/passes/branch_implementation.rb @@ -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 diff --git a/lib/arm/passes/main_implementation.rb b/lib/arm/passes/main_implementation.rb deleted file mode 100644 index fd0f0cf4..00000000 --- a/lib/arm/passes/main_implementation.rb +++ /dev/null @@ -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 diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 8e0cb476..807a9eb9 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -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 diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index ac45a232..76ac2c81 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -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" diff --git a/lib/register/instructions/branch.rb b/lib/register/instructions/branch.rb new file mode 100644 index 00000000..63a50e89 --- /dev/null +++ b/lib/register/instructions/branch.rb @@ -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 diff --git a/lib/register/passes/main_implementation.rb b/lib/register/passes/main_implementation.rb new file mode 100644 index 00000000..bd1b2b50 --- /dev/null +++ b/lib/register/passes/main_implementation.rb @@ -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 diff --git a/lib/register/register.rb b/lib/register/register.rb index 21dd6d5f..b936af83 100644 --- a/lib/register/register.rb +++ b/lib/register/register.rb @@ -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" diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index ae13696a..edc48d52 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -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" diff --git a/lib/register/instructions/register_main.rb b/lib/virtual/instructions/virtual_main.rb similarity index 73% rename from lib/register/instructions/register_main.rb rename to lib/virtual/instructions/virtual_main.rb index e751e4cc..cbac171b 100644 --- a/lib/register/instructions/register_main.rb +++ b/lib/virtual/instructions/virtual_main.rb @@ -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 diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 5cf7ab89..94071097 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -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