just use register nodes as registers (no more arrays)

This commit is contained in:
Torsten Ruger 2014-04-22 11:58:17 +03:00
parent 40a6437893
commit 2784a8da98
5 changed files with 12 additions and 11 deletions

View File

@ -22,7 +22,7 @@ module Asm
rfp sl fp ip sp lr pc
).each { |reg|
define_method(reg) {
[:reg, reg]
Asm::RegisterNode.new(reg)
}
}
@ -32,10 +32,8 @@ module Asm
node.args = []
args.each { |arg|
if (arg.is_a?(Array))
if (arg[0] == :reg)
node.args << Asm::RegisterNode.new(arg[1])
end
if (arg.is_a?(Asm::RegisterNode))
node.args << arg
elsif (arg.is_a?(Integer))
node.args << Asm::NumLiteralNode.new(arg)
elsif (arg.is_a?(Symbol))

View File

@ -26,9 +26,7 @@ module Asm
def build_operand(arg)
if (arg.is_a?(Array))
@operand = 0
arg.each do |sym , reg |
#allow an array of reg (strings), or the [:reg , name] produced by the instruction functions
reg = sym == :reg ? reg : sym
arg.each do |reg |
reg = reg_ref(reg)
@operand |= (1 << reg)
end

View File

@ -8,7 +8,7 @@ module Asm
@objects = []
@position = -1 # marks not set
@label_objects = []
@relocations = []
#@relocations = []
end
attr_reader :relocations, :objects , :position

View File

@ -23,7 +23,8 @@ module Asm
class RegisterListNode < Node
attr_accessor :registers
def initialize regs
@registers = regs.collect{ |sym , reg| (sym == :reg) ? reg : "not a reg #{sym} , #{reg}" }
@registers = regs
regs.each{ |reg| raise "not a reg #{sym} , #{reg}" unless reg.is_a?(Asm::RegisterNode) }
end
end

View File

@ -34,7 +34,7 @@ class TestArmAsm < MiniTest::Test
assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03
end
def test_and # inst eval doesn't really work with and
code = @generator.and( [:reg , 'r1'] , [:reg , 'r2'] , [:reg , 'r3']).first
code = @generator.and( @generator.r1 , @generator.r2 , @generator.r3).first
assert_code code , :and , [0x03,0x10,0x02,0xe0] #e0 01 10 03
end
def test_b
@ -68,6 +68,10 @@ class TestArmAsm < MiniTest::Test
code = @generator.instance_eval { ldr r0, r0 }.first
assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00
end
def test_ldr2
code = @generator.instance_eval { ldr r0, r0 + 4 }.first
assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00
end
def test_ldrb
code = @generator.instance_eval { ldrb r0, r0 }.first
assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00