2017-04-08 11:10:42 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2018-06-29 21:56:49 +02:00
|
|
|
module Risc
|
2018-06-30 22:26:28 +02:00
|
|
|
class TestMethodCompiler < MiniTest::Test
|
2018-06-29 22:04:50 +02:00
|
|
|
include ScopeHelper
|
2017-04-08 11:10:42 +02:00
|
|
|
|
|
|
|
def setup
|
2019-09-28 14:34:09 +02:00
|
|
|
code = in_Test("def meth; @ivar = 5;return ;end")
|
|
|
|
rubyx = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
2019-10-03 19:55:41 +02:00
|
|
|
@compiler = rubyx.ruby_to_slot(code).compilers.to_risc
|
2019-09-28 14:34:09 +02:00
|
|
|
end
|
|
|
|
def test_compiles_risc
|
|
|
|
assert_equal Risc::MethodCompiler , @compiler.class
|
|
|
|
assert_equal Risc::Label , @compiler.risc_instructions.class
|
|
|
|
end
|
|
|
|
def test_compiles_all_risc
|
|
|
|
assert_equal Risc::LoadConstant , @compiler.risc_instructions.next.class
|
2020-03-13 14:49:36 +01:00
|
|
|
assert_equal 15 , @compiler.risc_instructions.length
|
2019-09-28 14:34:09 +02:00
|
|
|
end
|
|
|
|
def test_translate_cpu
|
|
|
|
cpu = @compiler.translate_cpu(Platform.for(:arm).translator)
|
|
|
|
assert_equal Assembler , cpu.class
|
|
|
|
assert_equal :meth , cpu.callable.name
|
|
|
|
end
|
|
|
|
def test_translate_method
|
|
|
|
ass = @compiler.translate_method(Platform.for(:arm).translator , [])
|
|
|
|
assert_equal Array , ass.class
|
|
|
|
assert_equal Assembler , ass.first.class
|
|
|
|
assert_equal :meth , ass.first.callable.name
|
2018-08-02 16:37:27 +02:00
|
|
|
end
|
2017-04-08 11:10:42 +02:00
|
|
|
end
|
|
|
|
end
|