just use register nodes as registers (no more arrays)
This commit is contained in:
parent
40a6437893
commit
2784a8da98
@ -22,7 +22,7 @@ module Asm
|
|||||||
rfp sl fp ip sp lr pc
|
rfp sl fp ip sp lr pc
|
||||||
).each { |reg|
|
).each { |reg|
|
||||||
define_method(reg) {
|
define_method(reg) {
|
||||||
[:reg, reg]
|
Asm::RegisterNode.new(reg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,10 +32,8 @@ module Asm
|
|||||||
node.args = []
|
node.args = []
|
||||||
|
|
||||||
args.each { |arg|
|
args.each { |arg|
|
||||||
if (arg.is_a?(Array))
|
if (arg.is_a?(Asm::RegisterNode))
|
||||||
if (arg[0] == :reg)
|
node.args << arg
|
||||||
node.args << Asm::RegisterNode.new(arg[1])
|
|
||||||
end
|
|
||||||
elsif (arg.is_a?(Integer))
|
elsif (arg.is_a?(Integer))
|
||||||
node.args << Asm::NumLiteralNode.new(arg)
|
node.args << Asm::NumLiteralNode.new(arg)
|
||||||
elsif (arg.is_a?(Symbol))
|
elsif (arg.is_a?(Symbol))
|
||||||
|
@ -26,9 +26,7 @@ module Asm
|
|||||||
def build_operand(arg)
|
def build_operand(arg)
|
||||||
if (arg.is_a?(Array))
|
if (arg.is_a?(Array))
|
||||||
@operand = 0
|
@operand = 0
|
||||||
arg.each do |sym , reg |
|
arg.each do |reg |
|
||||||
#allow an array of reg (strings), or the [:reg , name] produced by the instruction functions
|
|
||||||
reg = sym == :reg ? reg : sym
|
|
||||||
reg = reg_ref(reg)
|
reg = reg_ref(reg)
|
||||||
@operand |= (1 << reg)
|
@operand |= (1 << reg)
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Asm
|
|||||||
@objects = []
|
@objects = []
|
||||||
@position = -1 # marks not set
|
@position = -1 # marks not set
|
||||||
@label_objects = []
|
@label_objects = []
|
||||||
@relocations = []
|
#@relocations = []
|
||||||
end
|
end
|
||||||
attr_reader :relocations, :objects , :position
|
attr_reader :relocations, :objects , :position
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ module Asm
|
|||||||
class RegisterListNode < Node
|
class RegisterListNode < Node
|
||||||
attr_accessor :registers
|
attr_accessor :registers
|
||||||
def initialize regs
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class TestArmAsm < MiniTest::Test
|
|||||||
assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03
|
assert_code code , :add , [0x03,0x10,0x81,0xe0] #e0 81 10 03
|
||||||
end
|
end
|
||||||
def test_and # inst eval doesn't really work with and
|
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
|
assert_code code , :and , [0x03,0x10,0x02,0xe0] #e0 01 10 03
|
||||||
end
|
end
|
||||||
def test_b
|
def test_b
|
||||||
@ -68,6 +68,10 @@ class TestArmAsm < MiniTest::Test
|
|||||||
code = @generator.instance_eval { ldr r0, r0 }.first
|
code = @generator.instance_eval { ldr r0, r0 }.first
|
||||||
assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00
|
assert_code code, :ldr , [0x00,0x00,0x90,0xe5] #e5 90 00 00
|
||||||
end
|
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
|
def test_ldrb
|
||||||
code = @generator.instance_eval { ldrb r0, r0 }.first
|
code = @generator.instance_eval { ldrb r0, r0 }.first
|
||||||
assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00
|
assert_code code, :ldrb , [0x00,0x00,0xd0,0xe5] #e5 d0 00 00
|
||||||
|
Loading…
Reference in New Issue
Block a user