test no 3
This commit is contained in:
parent
f4315804c1
commit
5d9c4323bb
@ -1,6 +1,6 @@
|
||||
require 'asm/arm/arm_assembler'
|
||||
require 'asm/arm/instruction'
|
||||
require 'asm/label_object'
|
||||
require_relative 'generator_label'
|
||||
require 'asm/nodes'
|
||||
require 'stream_reader'
|
||||
require 'stringio'
|
||||
@ -45,7 +45,7 @@ class Asm::Arm::CodeGenerator
|
||||
node.args << Asm::LabelRefArgNode.new { |n|
|
||||
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
|
||||
else
|
||||
raise 'Invalid argument `%s\' for instruction' % arg.inspect
|
||||
@ -75,11 +75,11 @@ class Asm::Arm::CodeGenerator
|
||||
}
|
||||
|
||||
def label
|
||||
GeneratorLabel.new(@asm)
|
||||
Asm::Arm::GeneratorLabel.new(@asm)
|
||||
end
|
||||
|
||||
def label!
|
||||
lbl = GeneratorLabel.new(@asm)
|
||||
lbl = Asm::Arm::GeneratorLabel.new(@asm)
|
||||
lbl.set!
|
||||
lbl
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
require "asm/assembly_error"
|
||||
require "asm/arm/instruction_tools"
|
||||
require "asm/arm/builder_a"
|
||||
require "asm/arm/builder_b"
|
||||
|
@ -4,6 +4,7 @@ require "asm/arm/code_generator"
|
||||
# try to test that the generation of basic instructions works
|
||||
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp
|
||||
# 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
|
||||
# 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)
|
||||
# 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 (?)
|
||||
def assert_code code , op , should
|
||||
def assert_code code , op , should , status = false
|
||||
assert_equal op , code.opcode
|
||||
binary = @generator.assemble
|
||||
assert_equal 4 , binary.length
|
||||
@ -23,23 +24,24 @@ class TestArmAsm < MiniTest::Test
|
||||
assert_equal should[index] , byte
|
||||
index += 1
|
||||
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
|
||||
def test_mov
|
||||
code = @generator.instance_eval { mov r0, 5 }.first
|
||||
assert_code code , :mov , [0x05,0x00,0xa0,0xe3]
|
||||
assert ! code.affect_status #no s at the end, silly for mov anyway
|
||||
end
|
||||
def test_sub
|
||||
def test_subs
|
||||
code = @generator.instance_eval { subs r2, r0, 1 }.first
|
||||
assert_code code, :sub , [0x01,0x20,0x50,0xe2]
|
||||
assert code.affect_status #the s at the end
|
||||
assert_code code, :sub , [0x01,0x20,0x50,0xe2] , true
|
||||
end
|
||||
|
||||
def saved_other
|
||||
@generator.instance_eval do
|
||||
mov r0, 5
|
||||
loop_start = label
|
||||
loop_start.set!
|
||||
loop_start = label!
|
||||
subs r0, r0, 1
|
||||
bne loop_start
|
||||
bx lr
|
||||
|
Loading…
Reference in New Issue
Block a user