rubyx/test/label_test.rb

33 lines
711 B
Ruby
Raw Normal View History

2014-04-20 22:47:02 +02:00
require_relative 'helper'
#try to call an extern function
class TestExtern < MiniTest::Test
# need a code generator, for arm
def setup
@generator = Asm::Arm::CodeGenerator.new
end
2014-04-21 16:27:05 +02:00
def test_extern
2014-04-20 22:47:02 +02:00
@generator.instance_eval {
2014-04-21 16:27:05 +02:00
push lr
ldr r0, "hello world".to_sym
mov r7, 4 #4 is write
swi 0
pop pc
mov r7, 1 #1 == exit
swi 0
2014-04-20 22:47:02 +02:00
}
2014-04-21 16:27:05 +02:00
write(7 , 'label')
end
#helper to write the file
def write len ,name
2014-04-20 22:47:02 +02:00
writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM)
assembly = @generator.assemble
2014-04-21 16:27:05 +02:00
assert_equal len * 4 , assembly.length
2014-04-20 22:47:02 +02:00
writer.set_text assembly
2014-04-21 16:27:05 +02:00
writer.save("#{name}_test.o")
2014-04-20 22:47:02 +02:00
end
end