From 1e326e00b9f3c7acc2bf2e21a0626fbd196560cb Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 24 May 2014 16:52:54 +0300 Subject: [PATCH] fix tests after register allocation work --- lib/arm/stack_instruction.rb | 25 +++++++++---------------- test/arm/test_small_program.rb | 2 +- test/fragments/test_all.rb | 2 ++ test/fragments/test_foo.rb | 2 +- test/fragments/test_hello.rb | 2 +- test/fragments/test_putint.rb | 2 +- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/arm/stack_instruction.rb b/lib/arm/stack_instruction.rb index cd20ab03..527efb7a 100644 --- a/lib/arm/stack_instruction.rb +++ b/lib/arm/stack_instruction.rb @@ -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 diff --git a/test/arm/test_small_program.rb b/test/arm/test_small_program.rb index 6f4defb4..831a22fa 100644 --- a/test/arm/test_small_program.rb +++ b/test/arm/test_small_program.rb @@ -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)}" diff --git a/test/fragments/test_all.rb b/test/fragments/test_all.rb index 2966c793..85336f93 100644 --- a/test/fragments/test_all.rb +++ b/test/fragments/test_all.rb @@ -2,3 +2,5 @@ require_relative "test_hello" require_relative "test_foo" require_relative "test_putint" +require_relative "test_while" +require_relative "test_if" diff --git a/test/fragments/test_foo.rb b/test/fragments/test_foo.rb index b2eb14fa..6118fc03 100644 --- a/test/fragments/test_foo.rb +++ b/test/fragments/test_foo.rb @@ -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 diff --git a/test/fragments/test_hello.rb b/test/fragments/test_hello.rb index 0f49d125..98d7e469 100644 --- a/test/fragments/test_hello.rb +++ b/test/fragments/test_hello.rb @@ -7,7 +7,7 @@ class TestHello < MiniTest::Test @string_input = <