2020-03-18 12:10:09 +01:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestStandardAllocator < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
|
|
|
@allocator = StandardAllocator.new(Risc.test_compiler , Platform.for(:arm))
|
|
|
|
end
|
|
|
|
def tmp_reg
|
|
|
|
Risc.tmp_reg(:Type)
|
|
|
|
end
|
|
|
|
def test_regs
|
|
|
|
assert_equal Hash , @allocator.used_regs.class
|
|
|
|
end
|
|
|
|
def test_empty
|
|
|
|
assert @allocator.used_regs_empty?
|
|
|
|
end
|
2020-03-18 14:27:40 +01:00
|
|
|
def test_reg_names
|
|
|
|
assert_equal 16 , @allocator.reg_names.length
|
|
|
|
end
|
2020-03-18 12:10:09 +01:00
|
|
|
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
|
2020-03-18 16:50:22 +01:00
|
|
|
def test_allocate_runs
|
2020-03-19 11:30:44 +01:00
|
|
|
assert_nil @allocator.allocate_regs
|
2020-03-18 16:50:22 +01:00
|
|
|
end
|
|
|
|
def test_live
|
2020-03-19 11:30:44 +01:00
|
|
|
live = @allocator.walk_and_mark(@allocator.compiler.risc_instructions)
|
2020-03-18 16:50:22 +01:00
|
|
|
assert_equal 0 , live.length
|
|
|
|
end
|
2020-03-18 12:10:09 +01:00
|
|
|
def test_add_ok
|
2020-03-19 11:30:44 +01:00
|
|
|
assert_equal Symbol, @allocator.use_reg(:r1, :some).class
|
|
|
|
assert @allocator.used_regs.include?(:r1)
|
2020-03-18 12:10:09 +01:00
|
|
|
end
|
|
|
|
def test_add_fail
|
|
|
|
assert_raises{ @allocator.use_reg(1)}
|
|
|
|
end
|
|
|
|
def test_release_reg
|
2020-03-19 11:30:44 +01:00
|
|
|
@allocator.use_reg(:r1 , :some)
|
|
|
|
assert @allocator.used_regs.include?(:r1)
|
|
|
|
assert_equal Symbol , @allocator.release_reg(tmp_reg).class
|
|
|
|
assert !@allocator.used_regs.include?(:r1)
|
2020-03-18 12:10:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|