test no 3
This commit is contained in:
parent
f4315804c1
commit
5d9c4323bb
@ -1,6 +1,6 @@
|
|||||||
require 'asm/arm/arm_assembler'
|
require 'asm/arm/arm_assembler'
|
||||||
require 'asm/arm/instruction'
|
require 'asm/arm/instruction'
|
||||||
require 'asm/label_object'
|
require_relative 'generator_label'
|
||||||
require 'asm/nodes'
|
require 'asm/nodes'
|
||||||
require 'stream_reader'
|
require 'stream_reader'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
@ -45,7 +45,7 @@ class Asm::Arm::CodeGenerator
|
|||||||
node.args << Asm::LabelRefArgNode.new { |n|
|
node.args << Asm::LabelRefArgNode.new { |n|
|
||||||
n.label = arg.to_s
|
n.label = arg.to_s
|
||||||
}
|
}
|
||||||
elsif (arg.is_a?(GeneratorLabel) or arg.is_a?(GeneratorExternLabel))
|
elsif (arg.is_a?(Asm::Arm::GeneratorLabel) or arg.is_a?(Asm::Arm::GeneratorExternLabel))
|
||||||
node.args << arg
|
node.args << arg
|
||||||
else
|
else
|
||||||
raise 'Invalid argument `%s\' for instruction' % arg.inspect
|
raise 'Invalid argument `%s\' for instruction' % arg.inspect
|
||||||
@ -75,11 +75,11 @@ class Asm::Arm::CodeGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
def label
|
def label
|
||||||
GeneratorLabel.new(@asm)
|
Asm::Arm::GeneratorLabel.new(@asm)
|
||||||
end
|
end
|
||||||
|
|
||||||
def label!
|
def label!
|
||||||
lbl = GeneratorLabel.new(@asm)
|
lbl = Asm::Arm::GeneratorLabel.new(@asm)
|
||||||
lbl.set!
|
lbl.set!
|
||||||
lbl
|
lbl
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
require "asm/assembly_error"
|
||||||
require "asm/arm/instruction_tools"
|
require "asm/arm/instruction_tools"
|
||||||
require "asm/arm/builder_a"
|
require "asm/arm/builder_a"
|
||||||
require "asm/arm/builder_b"
|
require "asm/arm/builder_b"
|
||||||
|
@ -4,6 +4,7 @@ require "asm/arm/code_generator"
|
|||||||
# try to test that the generation of basic instructions works
|
# try to test that the generation of basic instructions works
|
||||||
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp
|
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp
|
||||||
# tests are named as per assembler code, ie test_mov testing mov instruction
|
# tests are named as per assembler code, ie test_mov testing mov instruction
|
||||||
|
# adc add and bic eor orr rsb rsc sbc sub mov mvn cmn cmp teq tst b bl bx swi strb
|
||||||
|
|
||||||
class TestArmAsm < MiniTest::Test
|
class TestArmAsm < MiniTest::Test
|
||||||
# need a code generator, for arm
|
# need a code generator, for arm
|
||||||
@ -14,7 +15,7 @@ class TestArmAsm < MiniTest::Test
|
|||||||
# code is what the generator spits out, at least one instruction worth (.first)
|
# code is what the generator spits out, at least one instruction worth (.first)
|
||||||
# the op code is wat was witten as assembler in the first place and the binary result
|
# the op code is wat was witten as assembler in the first place and the binary result
|
||||||
# is reversed and in 4 bytes as ruby can only do 31 bits and so we can't test with just one int (?)
|
# is reversed and in 4 bytes as ruby can only do 31 bits and so we can't test with just one int (?)
|
||||||
def assert_code code , op , should
|
def assert_code code , op , should , status = false
|
||||||
assert_equal op , code.opcode
|
assert_equal op , code.opcode
|
||||||
binary = @generator.assemble
|
binary = @generator.assemble
|
||||||
assert_equal 4 , binary.length
|
assert_equal 4 , binary.length
|
||||||
@ -23,23 +24,24 @@ class TestArmAsm < MiniTest::Test
|
|||||||
assert_equal should[index] , byte
|
assert_equal should[index] , byte
|
||||||
index += 1
|
index += 1
|
||||||
end
|
end
|
||||||
|
assert code.affect_status if status #no s at the end, silly for mov anyway
|
||||||
|
end
|
||||||
|
def test_adc
|
||||||
|
code = @generator.instance_eval { adc r1, r3, r5}.first
|
||||||
|
assert_code code , :adc , [0x05,0x10,0xa3,0xe0]
|
||||||
end
|
end
|
||||||
def test_mov
|
def test_mov
|
||||||
code = @generator.instance_eval { mov r0, 5 }.first
|
code = @generator.instance_eval { mov r0, 5 }.first
|
||||||
assert_code code , :mov , [0x05,0x00,0xa0,0xe3]
|
assert_code code , :mov , [0x05,0x00,0xa0,0xe3]
|
||||||
assert ! code.affect_status #no s at the end, silly for mov anyway
|
|
||||||
end
|
end
|
||||||
def test_sub
|
def test_subs
|
||||||
code = @generator.instance_eval { subs r2, r0, 1 }.first
|
code = @generator.instance_eval { subs r2, r0, 1 }.first
|
||||||
assert_code code, :sub , [0x01,0x20,0x50,0xe2]
|
assert_code code, :sub , [0x01,0x20,0x50,0xe2] , true
|
||||||
assert code.affect_status #the s at the end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def saved_other
|
def saved_other
|
||||||
@generator.instance_eval do
|
@generator.instance_eval do
|
||||||
mov r0, 5
|
mov r0, 5
|
||||||
loop_start = label
|
loop_start = label!
|
||||||
loop_start.set!
|
|
||||||
subs r0, r0, 1
|
subs r0, r0, 1
|
||||||
bne loop_start
|
bne loop_start
|
||||||
bx lr
|
bx lr
|
||||||
|
Loading…
Reference in New Issue
Block a user