change platform to return register names

not just the number of them
also adds protocol to map registers
(like message to r0 , or syscalls)
This commit is contained in:
2020-03-19 18:18:22 +02:00
parent f13e6dcf57
commit 0137056b89
4 changed files with 50 additions and 17 deletions

View File

@ -13,8 +13,24 @@ module Risc
assert_raises{ Platform.for("NotArm")}
end
def test_allocate
allocator = Platform.new.allocator(FakeCompiler.new)
allocator = Platform.for("Interpreter").allocator(FakeCompiler.new)
assert_equal FakeCompiler , allocator.compiler.class
end
def test_map_message
assert_equal :r0 , Platform.new.assign_reg?(:message)
end
def test_map_sys
assert_equal :r0 , Platform.new.assign_reg?(:syscall_1)
end
def test_map_id
assert_nil Platform.new.assign_reg?(:id_some_id)
end
def test_names_len
assert_equal 15 , Platform.new.register_names.length
end
def test_names_r
assert_equal "r" , Platform.new.register_names.first.to_s[0]
assert_equal "r" , Platform.new.register_names.last.to_s[0]
end
end
end

View File

@ -13,11 +13,8 @@ module Risc
def test_regs
assert_equal Hash , @allocator.used_regs.class
end
def test_empty
assert @allocator.used_regs_empty?
end
def test_reg_names
assert_equal 16 , @allocator.reg_names.length
assert_equal 15 , @allocator.reg_names.length
end
def test_compiler
assert_equal CallableCompiler , @allocator.compiler.class