starting on risc allocation
inserting allocator stage in method translation
This commit is contained in:
parent
d5411c7727
commit
2e109a16dc
@ -29,6 +29,7 @@ require_relative "risc/linker"
|
||||
require_relative "risc/callable_compiler"
|
||||
require_relative "risc/method_compiler"
|
||||
require_relative "risc/block_compiler"
|
||||
require_relative "risc/allocator"
|
||||
require_relative "risc/assembler"
|
||||
require_relative "risc/risc_collection"
|
||||
|
||||
|
@ -5,11 +5,13 @@ module Risc
|
||||
# upon request. they must be returned in order
|
||||
class Allocator
|
||||
|
||||
def initialize()
|
||||
def initialize( compiler , platform)
|
||||
@compiler = compiler
|
||||
@platform = platform
|
||||
@regs = []
|
||||
reset_regs
|
||||
end
|
||||
attr_reader :regs
|
||||
attr_reader :regs , :compiler , :platform
|
||||
|
||||
def regs_empty?
|
||||
@regs.empty?
|
||||
|
@ -18,10 +18,8 @@ module Risc
|
||||
def initialize( callable , slot_label)
|
||||
raise "No method" unless callable
|
||||
@callable = callable
|
||||
@allocator = Allocator.new
|
||||
@constants = []
|
||||
@current = @risc_instructions = slot_label.risc_label(self)
|
||||
@allocator.reset_regs
|
||||
end
|
||||
attr_reader :risc_instructions , :constants , :callable , :current
|
||||
|
||||
@ -137,11 +135,24 @@ module Risc
|
||||
|
||||
# translate this method, which means the method itself and all blocks inside it
|
||||
# returns the array (of assemblers) that you pass in as collection
|
||||
def translate_method( translator , collection)
|
||||
collection << translate_cpu( translator )
|
||||
# first arg is the platform object representing the platform that we
|
||||
# translate to
|
||||
#
|
||||
# This calls allocate_regs first, to change register naming to the platform
|
||||
#
|
||||
def translate_method( platform , collection)
|
||||
allocate_regs( platform )
|
||||
collection << translate_cpu( platform.translator )
|
||||
collection
|
||||
end
|
||||
|
||||
# allocate registers to the platform specific names (and amount)
|
||||
# This is actually done by the Allocator , with the help of the Platform
|
||||
# The Platform specifies how many registers there are, and the
|
||||
# Allocator changes SSA names to allocated names
|
||||
def allocate_regs(platform)
|
||||
allocator = Allocator.new(self , platform)
|
||||
end
|
||||
end
|
||||
end
|
||||
require_relative "allocator"
|
||||
|
@ -122,7 +122,7 @@ module Parfait
|
||||
List: {indexed_length: :Integer , next_list: :List} ,
|
||||
Message: { next_message: :Message, receiver: :Object, frame: :Object ,
|
||||
return_address: :Integer, return_value: :Object,
|
||||
caller: :Message , method: :TypedMethod ,
|
||||
caller: :Message , method: :CallableMethod ,
|
||||
arguments_given: :Integer ,
|
||||
arg1: :Object , arg2: :Object, arg3: :Object,
|
||||
arg4: :Object, arg5: :Object, arg6: :Object,
|
||||
|
@ -29,7 +29,7 @@ module Risc
|
||||
end
|
||||
|
||||
def class_name
|
||||
return :fixnum unless @type
|
||||
return :Integer unless @type
|
||||
@type.class_name
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,7 @@ module Risc
|
||||
platform = Platform.for(platform_sym)
|
||||
assemblers = []
|
||||
@method_compilers.each_compiler do |compiler|
|
||||
compiler.translate_method( platform.translator , assemblers)
|
||||
compiler.translate_method( platform , assemblers)
|
||||
end
|
||||
Risc::Linker.new(platform , assemblers , constants)
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
require_relative "helper"
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestLinkerObjects < MiniTest::Test
|
||||
|
@ -1,4 +1,4 @@
|
||||
require_relative "helper"
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestMachinePos < MiniTest::Test
|
||||
|
@ -5,7 +5,7 @@ module Risc
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@allocator = Allocator.new
|
||||
@allocator = Allocator.new(Risc.test_compiler , Platform.for(:arm))
|
||||
end
|
||||
def tmp_reg
|
||||
Risc.tmp_reg(:Type)
|
||||
@ -16,6 +16,13 @@ module Risc
|
||||
def test_empty
|
||||
assert @allocator.regs_empty?
|
||||
end
|
||||
def test_compiler
|
||||
assert_equal CallableCompiler , @allocator.compiler.class
|
||||
assert_equal :fake_name , @allocator.compiler.callable.name
|
||||
end
|
||||
def test_platform
|
||||
assert_equal Arm::ArmPlatform , @allocator.platform.class
|
||||
end
|
||||
def test_add_ok
|
||||
assert_equal Array, @allocator.add_reg(tmp_reg).class
|
||||
end
|
||||
|
21
test/risc/test_callable_compiler1.rb
Normal file
21
test/risc/test_callable_compiler1.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestCallableCompiler1 < MiniTest::Test
|
||||
include SolCompile
|
||||
|
||||
def setup
|
||||
@compiler = compile_main("return 5").to_risc
|
||||
@platform = Platform.for(:arm)
|
||||
end
|
||||
def test_init
|
||||
@compiler.risc_instructions.each do |ins|
|
||||
puts ins.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def test_1
|
||||
@compiler.translate_method( @platform , [])
|
||||
end
|
||||
end
|
||||
end
|
@ -4,7 +4,7 @@ module ScopeHelper
|
||||
|
||||
def compiler_with_main(options = {})
|
||||
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options.merge(options))
|
||||
compiler.ruby_to_sol( "class Space;def main(arg);return;end;end" )
|
||||
compiler.ruby_to_sol( in_Space( as_main("return")) )
|
||||
compiler
|
||||
end
|
||||
def in_Test(statements)
|
||||
|
Loading…
Reference in New Issue
Block a user