finally cleaned up those pestey parse errors

This commit is contained in:
Torsten Ruger 2014-04-23 12:58:59 +03:00
parent ceefa05b2f
commit f4299de120
7 changed files with 10 additions and 16 deletions

View File

@ -1,7 +1,5 @@
module Asm
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
ERRSTR_INVALID_ARG = 'invalid operand argument'
class Assembler
def initialize

View File

@ -1,12 +1,8 @@
module Asm
class AssemblyError < StandardError
def initialize(message, node)
def initialize(message)
super(message)
@node = node
end
attr_reader :node
end
end

View File

@ -116,10 +116,10 @@ module Asm
io << packed
io.write_uint8 0b1111 | (COND_CODES[@cond] << 4)
else
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg)
raise Asm::AssemblyError.new("invalid operand argument expected literal not #{arg}")
end
else
raise Asm::AssemblyError.new("unknown instruction #{opcode}", self)
raise Asm::AssemblyError.new("unknown instruction #{opcode} #{self}")
end
end
end

View File

@ -37,7 +37,7 @@ module Asm
def reg_ref(arg)
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
ref =
@ -49,7 +49,7 @@ module Asm
'lr' => 14, 'pc' => 15}[arg.name.downcase]
if (not ref)
raise Asm::AssemblyError.new('unknown register %s' % arg.name.downcase, arg)
raise Asm::AssemblyError.new("unknown register #{arg}")
end
ref

View File

@ -44,7 +44,7 @@ module Asm
@add_offset = 1
end
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
elsif (arg.is_a?(Asm::Label) or arg.is_a?(Asm::NumLiteral))
@ -53,7 +53,7 @@ module Asm
@use_addrtable_reloc = true
@addrtable_reloc_target = arg
else
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect, arg.inspect)
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
end
end

View File

@ -59,7 +59,7 @@ module Asm
@operand = op_with_rot
@i = 1
else
raise Asm::AssemblyError.new(Asm::ERRSTR_NUMERIC_TOO_LARGE, arg)
raise Asm::AssemblyError.new("cannot fit numeric literal argument in operand #{arg}")
end
elsif (arg.is_a?(Asm::Register))
@operand = reg_ref(arg)
@ -89,7 +89,7 @@ module Asm
@operand = rm_ref | (shift_op << 4) | (shift_imm << 4+3)
else
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect, arg)
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
end
end

View File

@ -30,7 +30,7 @@ module Asm
@operand |= (1 << reg)
end
else
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect , arg)
raise Asm::AssemblyError.new("invalid operand argument #{arg.inspect}")
end
end