finally cleaned up those pestey parse errors
This commit is contained in:
parent
ceefa05b2f
commit
f4299de120
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
module Asm
|
module Asm
|
||||||
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
|
|
||||||
ERRSTR_INVALID_ARG = 'invalid operand argument'
|
|
||||||
|
|
||||||
class Assembler
|
class Assembler
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
module Asm
|
module Asm
|
||||||
class AssemblyError < StandardError
|
class AssemblyError < StandardError
|
||||||
def initialize(message, node)
|
def initialize(message)
|
||||||
super(message)
|
super(message)
|
||||||
|
|
||||||
@node = node
|
|
||||||
end
|
end
|
||||||
attr_reader :node
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -116,10 +116,10 @@ module Asm
|
|||||||
io << packed
|
io << packed
|
||||||
io.write_uint8 0b1111 | (COND_CODES[@cond] << 4)
|
io.write_uint8 0b1111 | (COND_CODES[@cond] << 4)
|
||||||
else
|
else
|
||||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg)
|
raise Asm::AssemblyError.new("invalid operand argument expected literal not #{arg}")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise Asm::AssemblyError.new("unknown instruction #{opcode}", self)
|
raise Asm::AssemblyError.new("unknown instruction #{opcode} #{self}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ module Asm
|
|||||||
|
|
||||||
def reg_ref(arg)
|
def reg_ref(arg)
|
||||||
if (not arg.is_a?(Asm::Register))
|
if (not arg.is_a?(Asm::Register))
|
||||||
raise Asm::AssemblyError.new('argument must be a register', arg)
|
raise Asm::AssemblyError.new("argument must be a register not #{arg}")
|
||||||
end
|
end
|
||||||
|
|
||||||
ref =
|
ref =
|
||||||
@ -49,7 +49,7 @@ module Asm
|
|||||||
'lr' => 14, 'pc' => 15}[arg.name.downcase]
|
'lr' => 14, 'pc' => 15}[arg.name.downcase]
|
||||||
|
|
||||||
if (not ref)
|
if (not ref)
|
||||||
raise Asm::AssemblyError.new('unknown register %s' % arg.name.downcase, arg)
|
raise Asm::AssemblyError.new("unknown register #{arg}")
|
||||||
end
|
end
|
||||||
|
|
||||||
ref
|
ref
|
||||||
|
@ -44,7 +44,7 @@ module Asm
|
|||||||
@add_offset = 1
|
@add_offset = 1
|
||||||
end
|
end
|
||||||
if (@operand.abs > 4095)
|
if (@operand.abs > 4095)
|
||||||
raise Asm::AssemblyError.new('reference offset too large/small (max 4095)', argr.right)
|
raise Asm::AssemblyError.new("reference offset too large/small (max 4095) #{argr.right}" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif (arg.is_a?(Asm::Label) or arg.is_a?(Asm::NumLiteral))
|
elsif (arg.is_a?(Asm::Label) or arg.is_a?(Asm::NumLiteral))
|
||||||
@ -53,7 +53,7 @@ module Asm
|
|||||||
@use_addrtable_reloc = true
|
@use_addrtable_reloc = true
|
||||||
@addrtable_reloc_target = arg
|
@addrtable_reloc_target = arg
|
||||||
else
|
else
|
||||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect, arg.inspect)
|
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ module Asm
|
|||||||
@operand = op_with_rot
|
@operand = op_with_rot
|
||||||
@i = 1
|
@i = 1
|
||||||
else
|
else
|
||||||
raise Asm::AssemblyError.new(Asm::ERRSTR_NUMERIC_TOO_LARGE, arg)
|
raise Asm::AssemblyError.new("cannot fit numeric literal argument in operand #{arg}")
|
||||||
end
|
end
|
||||||
elsif (arg.is_a?(Asm::Register))
|
elsif (arg.is_a?(Asm::Register))
|
||||||
@operand = reg_ref(arg)
|
@operand = reg_ref(arg)
|
||||||
@ -89,7 +89,7 @@ module Asm
|
|||||||
|
|
||||||
@operand = rm_ref | (shift_op << 4) | (shift_imm << 4+3)
|
@operand = rm_ref | (shift_op << 4) | (shift_imm << 4+3)
|
||||||
else
|
else
|
||||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect, arg)
|
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ module Asm
|
|||||||
@operand |= (1 << reg)
|
@operand |= (1 << reg)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect , arg)
|
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user