2014-08-30 18:40:37 +02:00
|
|
|
require_relative '../helper'
|
|
|
|
|
|
|
|
# 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 call bx swi strb
|
|
|
|
|
|
|
|
module ArmHelper
|
|
|
|
# need Assembler and a block (see those classes)
|
|
|
|
def setup
|
2014-10-04 16:34:51 +02:00
|
|
|
@machine = Arm::ArmMachine
|
2014-08-30 18:40:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
|
|
|
assert_equal op , code.opcode
|
|
|
|
io = StringIO.new
|
2014-09-18 16:06:30 +02:00
|
|
|
code.assemble(io)
|
2014-08-30 18:40:37 +02:00
|
|
|
binary = io.string
|
2014-09-18 16:06:30 +02:00
|
|
|
assert_equal should.length , binary.length , "code length wrong for #{code.inspect}"
|
2014-08-30 18:40:37 +02:00
|
|
|
index = 0
|
|
|
|
binary.each_byte do |byte |
|
|
|
|
assert_equal should[index] , byte , "byte #{index} 0x#{should[index].to_s(16)} != 0x#{byte.to_s(16)}"
|
|
|
|
index += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|