fix block initialization style by adding init methods

This commit is contained in:
Torsten Ruger 2014-04-18 19:19:57 +03:00
parent 529f109171
commit 4bb74a0de2
3 changed files with 19 additions and 11 deletions

View File

@ -87,7 +87,8 @@ module Asm
@use_addrtable_reloc = true
@addrtable_reloc_target = arg1
else
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg1)
puts "Invalid #{arg1.inspect}"
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg1.inspect)
end
end

View File

@ -33,18 +33,12 @@ class Asm::Arm::CodeGenerator
args.each { |arg|
if (arg.is_a?(Array))
if (arg[0] == :reg)
node.args << Asm::RegisterArgNode.new { |n|
n.name = arg[1]
}
node.args << Asm::RegisterArgNode.new(arg[1])
end
elsif (arg.is_a?(Integer))
node.args << Asm::NumLiteralArgNode.new { |n|
n.value = arg
}
node.args << Asm::NumLiteralArgNode.new(arg)
elsif (arg.is_a?(Symbol))
node.args << Asm::LabelRefArgNode.new { |n|
n.label = arg.to_s
}
node.args << Asm::LabelRefArgNode.new(arg.to_s)
elsif (arg.is_a?(Asm::Arm::GeneratorLabel) or arg.is_a?(Asm::Arm::GeneratorExternLabel))
node.args << arg
else
@ -55,7 +49,7 @@ class Asm::Arm::CodeGenerator
@asm.add_object Asm::Arm::Instruction.new(node)
end
%w(adc add and bic eor orr rsb rsc sbc sub mov mvn cmn cmp teq tst b bl bx swi strb
%w(adc add and bic eor orr rsb rsc sbc sub mov mvn cmn cmp teq tst b bl bx swi str strb ldr ldrb
).each { |inst|
define_method(inst) { |*args|
instruction inst.to_sym, *args

View File

@ -37,6 +37,9 @@ module Asm
class RegisterArgNode < ArgNode
attr_accessor :name
def initialize name
@name = name
end
end
class RegisterListArgNode < ArgNode
@ -45,18 +48,28 @@ module Asm
class NumLiteralArgNode < ArgNode
attr_accessor :value
def initialize val
@value = val
end
end
class NumEquivAddrArgNode < NumLiteralArgNode
end
class LabelRefArgNode < ArgNode
attr_accessor :label, :label_object
def initialize label , object = nil
@label = label
@label_object = object
end
end
class LabelEquivAddrArgNode < LabelRefArgNode
end
class ReferenceArgNode < ArgNode
attr_accessor :argument
def initilize arg
@argument = arg
end
end
class ParseError < StandardError