fix tests after register allocation work

This commit is contained in:
Torsten Ruger 2014-05-24 16:52:54 +03:00
parent 4a67504a61
commit 1e326e00b9
6 changed files with 15 additions and 20 deletions

View File

@ -25,7 +25,15 @@ module Arm
end
def assemble(io)
build
if (@first.is_a?(Array))
@operand = 0
@first.each do |r|
raise "nil register in push, index #{r}- #{inspect}" if r.nil?
@operand |= (1 << reg_code(r))
end
else
raise "invalid operand argument #{inspect}"
end
write_base = 1
if (opcode == :push)
pre_post_index = 1
@ -51,20 +59,5 @@ module Arm
val |= (cond << 16+4+ 1+1+1+1 +2+2)
io.write_uint32 val
end
private
# Build representation for source value
def build
regs = @first
if (regs.is_a?(Array))
@operand = 0
regs.each_with_index do |reg , index|
raise "nil register in push, index #{index}" if reg == nil
@operand |= (1 << reg_code(reg))
end
else
raise "invalid operand argument #{regs.inspect} #{inspect}"
end
end
end
end

View File

@ -65,7 +65,7 @@ class TestSmallProg < MiniTest::Test
assembly = writer.text
# use this for getting the bytes to compare to :
# puts assembly
writer.save("#{name}_test.o")
#writer.save("#{name}_test.o")
assembly.text.bytes.each_with_index do |byte , index|
is = @should[index]
assert_equal byte , is , "@#{index.to_s(16)} #{byte.to_s(16)} != #{is.to_s(16)}"

View File

@ -2,3 +2,5 @@
require_relative "test_hello"
require_relative "test_foo"
require_relative "test_putint"
require_relative "test_while"
require_relative "test_if"

View File

@ -10,7 +10,7 @@ class TestFoo < MiniTest::Test
end
foo( 3 )
HERE
@should = [0x0,0xb0,0xa0,0xe3,0xe,0x0,0x2d,0xe9,0x3,0x0,0xa0,0xe3,0x2,0x0,0x0,0xeb,0xe,0x0,0xbd,0xe8,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0x5,0x10,0xa0,0xe3,0x0,0x80,0xbd,0xe8]
@should = [0x0,0xb0,0xa0,0xe3,0x3,0x0,0xa0,0xe3,0x1,0x0,0x0,0xeb,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0x5,0x10,0xa0,0xe3,0x0,0x80,0xbd,0xe8]
parse
write "foo"
end

View File

@ -7,7 +7,7 @@ class TestHello < MiniTest::Test
@string_input = <<HERE
putstring( "Hello Raisa, I am crystksdfkljsncjncn" )
HERE
@should = [0x0,0xb0,0xa0,0xe3,0xe,0x0,0x2d,0xe9,0x2c,0x0,0x8f,0xe2,0x28,0x10,0xa0,0xe3,0x2,0x0,0x0,0xeb,0xe,0x0,0xbd,0xe8,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0x1,0x20,0xa0,0xe1,0x0,0x10,0xa0,0xe1,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8,0x48,0x65,0x6c,0x6c,0x6f,0x20,0x52,0x61,0x69,0x73,0x61,0x2c,0x20,0x49,0x20,0x61,0x6d,0x20,0x63,0x72,0x79,0x73,0x74,0x6b,0x73,0x64,0x66,0x6b,0x6c,0x6a,0x73,0x6e,0x63,0x6a,0x6e,0x63,0x6e,0x0,0x0,0x0]
@should = [0x0,0xb0,0xa0,0xe3,0x28,0x0,0x8f,0xe2,0x28,0x10,0xa0,0xe3,0x1,0x0,0x0,0xeb,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0x1,0x20,0xa0,0xe1,0x0,0x10,0xa0,0xe1,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8,0x48,0x65,0x6c,0x6c,0x6f,0x20,0x52,0x61,0x69,0x73,0x61,0x2c,0x20,0x49,0x20,0x61,0x6d,0x20,0x63,0x72,0x79,0x73,0x74,0x6b,0x73,0x64,0x66,0x6b,0x6c,0x6a,0x73,0x6e,0x63,0x6a,0x6e,0x63,0x6e,0x0,0x0,0x0]
parse
write "hello"
end

View File

@ -7,7 +7,7 @@ class TestPutint < MiniTest::Test
@string_input = <<HERE
putint( 42 )
HERE
@should = [0x0,0xb0,0xa0,0xe3,0xe,0x0,0x2d,0xe9,0x2a,0x0,0xa0,0xe3,0x13,0x0,0x0,0xeb,0xe,0x0,0xbd,0xe8,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0xa,0x20,0x41,0xe2,0x21,0x11,0x41,0xe0,0x21,0x12,0x81,0xe0,0x21,0x14,0x81,0xe0,0x21,0x18,0x81,0xe0,0xa1,0x11,0xa0,0xe1,0x1,0x31,0x81,0xe0,0x83,0x20,0x52,0xe0,0x1,0x10,0x81,0x52,0xa,0x20,0x82,0x42,0x30,0x20,0x82,0xe2,0x0,0x20,0xc0,0xe5,0x1,0x0,0x40,0xe2,0x0,0x0,0x51,0xe3,0xef,0xff,0xff,0x1b,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x0,0x10,0xa0,0xe1,0x24,0x0,0x8f,0xe2,0x9,0x0,0x80,0xe2,0xe9,0xff,0xff,0xeb,0x18,0x0,0x8f,0xe2,0xc,0x10,0xa0,0xe3,0x1,0x20,0xa0,0xe1,0x0,0x10,0xa0,0xe1,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0]
@should = [0x0,0xb0,0xa0,0xe3,0x2a,0x0,0xa0,0xe3,0x12,0x0,0x0,0xeb,0x1,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x40,0x2d,0xe9,0xa,0x20,0x41,0xe2,0x21,0x11,0x41,0xe0,0x21,0x12,0x81,0xe0,0x21,0x14,0x81,0xe0,0x21,0x18,0x81,0xe0,0xa1,0x11,0xa0,0xe1,0x1,0x31,0x81,0xe0,0x83,0x20,0x52,0xe0,0x1,0x10,0x81,0x52,0xa,0x20,0x82,0x42,0x30,0x20,0x82,0xe2,0x0,0x20,0xc0,0xe5,0x1,0x0,0x40,0xe2,0x0,0x0,0x51,0xe3,0xef,0xff,0xff,0x1b,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x0,0x10,0xa0,0xe1,0x24,0x0,0x8f,0xe2,0x9,0x0,0x80,0xe2,0xe9,0xff,0xff,0xeb,0x18,0x0,0x8f,0xe2,0xc,0x10,0xa0,0xe3,0x1,0x20,0xa0,0xe1,0x0,0x10,0xa0,0xe1,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x80,0xbd,0xe8,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0]
parse
write "putint"
end