mirror of
https://github.com/notwa/lips
synced 2024-05-18 16:33:22 -07:00
add filenames to Dumper errors
This commit is contained in:
parent
fffe542d10
commit
1eed93f2e7
|
@ -33,16 +33,16 @@ function Dumper:push_instruction(t)
|
||||||
self:advance(4)
|
self:advance(4)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:add_instruction_j(line, o, T)
|
function Dumper:add_instruction_j(fn, line, o, T)
|
||||||
self:push_instruction{line=line, o, T}
|
self:push_instruction{fn=fn, line=line, o, T}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:add_instruction_i(line, o, s, t, i)
|
function Dumper:add_instruction_i(fn, line, o, s, t, i)
|
||||||
self:push_instruction{line=line, o, s, t, i}
|
self:push_instruction{fn=fn, line=line, o, s, t, i}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:add_instruction_r(line, o, s, t, d, f, c)
|
function Dumper:add_instruction_r(fn, line, o, s, t, d, f, c)
|
||||||
self:push_instruction{line=line, o, s, t, d, f, c}
|
self:push_instruction{fn=fn, line=line, o, s, t, d, f, c}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:add_label(name)
|
function Dumper:add_label(name)
|
||||||
|
@ -58,6 +58,8 @@ function Dumper:add_bytes(line, ...)
|
||||||
t = {}
|
t = {}
|
||||||
t.kind = 'bytes'
|
t.kind = 'bytes'
|
||||||
t.size = 0
|
t.size = 0
|
||||||
|
t.fn = self.fn
|
||||||
|
t.line = self.line
|
||||||
end
|
end
|
||||||
t.line = line
|
t.line = line
|
||||||
for _, b in ipairs{...} do
|
for _, b in ipairs{...} do
|
||||||
|
@ -70,9 +72,12 @@ function Dumper:add_bytes(line, ...)
|
||||||
self:advance(t.size)
|
self:advance(t.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:add_directive(line, name, a, b)
|
function Dumper:add_directive(fn, line, name, a, b)
|
||||||
|
self.fn = fn
|
||||||
|
self.line = line
|
||||||
local t = {}
|
local t = {}
|
||||||
t.line = line
|
t.fn = self.fn
|
||||||
|
t.line = self.line
|
||||||
if name == 'BYTE' then
|
if name == 'BYTE' then
|
||||||
self:add_bytes(line, a % 0x100)
|
self:add_bytes(line, a % 0x100)
|
||||||
elseif name == 'HALFWORD' then
|
elseif name == 'HALFWORD' then
|
||||||
|
@ -124,7 +129,6 @@ function Dumper:add_directive(line, name, a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:desym(tok)
|
function Dumper:desym(tok)
|
||||||
-- FIXME: errors can give wrong filename
|
|
||||||
if type(tok[2]) == 'number' then
|
if type(tok[2]) == 'number' then
|
||||||
return tok[2]
|
return tok[2]
|
||||||
elseif tok[1] == 'LABELSYM' then
|
elseif tok[1] == 'LABELSYM' then
|
||||||
|
@ -254,9 +258,9 @@ end
|
||||||
function Dumper:dump()
|
function Dumper:dump()
|
||||||
self.pos = self.options.offset or 0
|
self.pos = self.options.offset or 0
|
||||||
for i, t in ipairs(self.commands) do
|
for i, t in ipairs(self.commands) do
|
||||||
if t.line == nil then
|
assert(t.fn, 'Internal Error: no file name available')
|
||||||
error('Internal Error: no line number available')
|
assert(t.line, 'Internal Error: no line number available')
|
||||||
end
|
self.fn = t.fn
|
||||||
self.line = t.line
|
self.line = t.line
|
||||||
if t.kind == 'instruction' then
|
if t.kind == 'instruction' then
|
||||||
local uw, lw = self:dump_instruction(t)
|
local uw, lw = self:dump_instruction(t)
|
||||||
|
|
|
@ -69,36 +69,38 @@ end
|
||||||
function Parser:directive()
|
function Parser:directive()
|
||||||
local name = self.tok
|
local name = self.tok
|
||||||
self:advance()
|
self:advance()
|
||||||
local line = self.line
|
local function add(...)
|
||||||
|
self.dumper:add_directive(self.fn, self.line, ...)
|
||||||
|
end
|
||||||
if name == 'ORG' then
|
if name == 'ORG' then
|
||||||
self.dumper:add_directive(line, name, self:number())
|
add(name, self:number())
|
||||||
elseif name == 'ALIGN' or name == 'SKIP' then
|
elseif name == 'ALIGN' or name == 'SKIP' then
|
||||||
if self:is_EOL() and name == 'ALIGN' then
|
if self:is_EOL() and name == 'ALIGN' then
|
||||||
self.dumper:add_directive(line, name, 0)
|
add(name, 0)
|
||||||
else
|
else
|
||||||
local size = self:number()
|
local size = self:number()
|
||||||
if self:is_EOL() then
|
if self:is_EOL() then
|
||||||
self.dumper:add_directive(line, name, size)
|
add(name, size)
|
||||||
else
|
else
|
||||||
self:optional_comma()
|
self:optional_comma()
|
||||||
self.dumper:add_directive(line, name, size, self:number())
|
add(name, size, self:number())
|
||||||
end
|
end
|
||||||
self:expect_EOL()
|
self:expect_EOL()
|
||||||
end
|
end
|
||||||
elseif name == 'BYTE' or name == 'HALFWORD' then
|
elseif name == 'BYTE' or name == 'HALFWORD' then
|
||||||
self.dumper:add_directive(line, name, self:number())
|
add(name, self:number())
|
||||||
while not self:is_EOL() do
|
while not self:is_EOL() do
|
||||||
self:advance()
|
self:advance()
|
||||||
self:optional_comma()
|
self:optional_comma()
|
||||||
self.dumper:add_directive(line, name, self:number())
|
add(name, self:number())
|
||||||
end
|
end
|
||||||
self:expect_EOL()
|
self:expect_EOL()
|
||||||
elseif name == 'WORD' then -- allow labels in word directives
|
elseif name == 'WORD' then -- allow labels in word directives
|
||||||
self.dumper:add_directive(line, name, self:const()[2])
|
add(name, self:const()[2])
|
||||||
while not self:is_EOL() do
|
while not self:is_EOL() do
|
||||||
self:advance()
|
self:advance()
|
||||||
self:optional_comma()
|
self:optional_comma()
|
||||||
self.dumper:add_directive(line, name, self:const()[2])
|
add(name, self:const()[2])
|
||||||
end
|
end
|
||||||
self:expect_EOL()
|
self:expect_EOL()
|
||||||
elseif name == 'INC' then
|
elseif name == 'INC' then
|
||||||
|
@ -106,10 +108,10 @@ function Parser:directive()
|
||||||
elseif name == 'ASCII' or name == 'ASCIIZ' then
|
elseif name == 'ASCII' or name == 'ASCIIZ' then
|
||||||
local bytes = self:string()
|
local bytes = self:string()
|
||||||
for i, number in ipairs(bytes) do
|
for i, number in ipairs(bytes) do
|
||||||
self.dumper:add_directive(line, 'BYTE', number)
|
add('BYTE', number)
|
||||||
end
|
end
|
||||||
if name == 'ASCIIZ' then
|
if name == 'ASCIIZ' then
|
||||||
self.dumper:add_directive(line, 'BYTE', 0)
|
add('BYTE', 0)
|
||||||
end
|
end
|
||||||
self:expect_EOL()
|
self:expect_EOL()
|
||||||
elseif name == 'INCBIN' then
|
elseif name == 'INCBIN' then
|
||||||
|
@ -246,7 +248,7 @@ function Parser:format_out_raw(outformat, first, args, const, formatconst)
|
||||||
if f == nil then
|
if f == nil then
|
||||||
error('Internal Error: invalid output formatting string', 1)
|
error('Internal Error: invalid output formatting string', 1)
|
||||||
end
|
end
|
||||||
f(self.dumper, self.line, first, out[1], out[2], out[3], out[4], out[5])
|
f(self.dumper, self.fn, self.line, first, out[1], out[2], out[3], out[4], out[5])
|
||||||
end
|
end
|
||||||
|
|
||||||
function Parser:format_out(t, args)
|
function Parser:format_out(t, args)
|
||||||
|
@ -311,12 +313,12 @@ function Parser:tokenize(asm)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function lex()
|
local function lex()
|
||||||
local t = {}
|
|
||||||
local ok, a, b, c, d = coroutine.resume(routine)
|
local ok, a, b, c, d = coroutine.resume(routine)
|
||||||
if not ok then
|
if not ok then
|
||||||
a = a or 'Internal Error: lexer coroutine has stopped'
|
a = a or 'Internal Error: lexer coroutine has stopped'
|
||||||
error(a)
|
error(a)
|
||||||
end
|
end
|
||||||
|
local t = {}
|
||||||
t.tt = a
|
t.tt = a
|
||||||
t.tok = b
|
t.tok = b
|
||||||
t.fn = c
|
t.fn = c
|
||||||
|
|
Loading…
Reference in New Issue
Block a user