mirror of
https://github.com/notwa/lips
synced 2024-09-20 15:54:06 -07:00
use filename in errors; fix JALR
This commit is contained in:
parent
4646d467d2
commit
5da1b19fd5
1 changed files with 11 additions and 9 deletions
|
@ -5,7 +5,7 @@
|
||||||
-- lexer and parser are somewhat based on http://chunkbake.luaforge.net/
|
-- lexer and parser are somewhat based on http://chunkbake.luaforge.net/
|
||||||
|
|
||||||
local assembler = {
|
local assembler = {
|
||||||
_VERSION = 'assembler v1',
|
_VERSION = 'assembler v2',
|
||||||
_DESCRIPTION = 'Assembles MIPS assembly files for the R4300i CPU.',
|
_DESCRIPTION = 'Assembles MIPS assembly files for the R4300i CPU.',
|
||||||
_URL = 'https://github.com/notwa/mm/blob/master/Lua/inject/assembler.lua',
|
_URL = 'https://github.com/notwa/mm/blob/master/Lua/inject/assembler.lua',
|
||||||
_LICENSE = [[
|
_LICENSE = [[
|
||||||
|
@ -382,8 +382,9 @@ local instruction_handlers = {
|
||||||
at = nil
|
at = nil
|
||||||
|
|
||||||
local Lexer = Class()
|
local Lexer = Class()
|
||||||
function Lexer:init(asm)
|
function Lexer:init(asm, fn)
|
||||||
self.asm = asm
|
self.asm = asm
|
||||||
|
self.fn = fn or '(string)'
|
||||||
self.pos = 1
|
self.pos = 1
|
||||||
self.line = 1
|
self.line = 1
|
||||||
self.EOF = -1
|
self.EOF = -1
|
||||||
|
@ -391,20 +392,22 @@ function Lexer:init(asm)
|
||||||
end
|
end
|
||||||
|
|
||||||
local Dumper = Class()
|
local Dumper = Class()
|
||||||
function Dumper:init(writer)
|
function Dumper:init(writer, fn)
|
||||||
self.writer = writer
|
self.writer = writer
|
||||||
|
self.fn = fn or '(string)'
|
||||||
self.defines = {}
|
self.defines = {}
|
||||||
self.labels = {}
|
self.labels = {}
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local Parser = Class()
|
local Parser = Class()
|
||||||
function Parser:init(writer)
|
function Parser:init(writer, fn)
|
||||||
self.dumper = Dumper(writer)
|
self.fn = fn or '(string)'
|
||||||
|
self.dumper = Dumper(writer, fn)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lexer:error(msg)
|
function Lexer:error(msg)
|
||||||
error(string.format('%s:%d: Error: %s', 'file.asm', self.line, msg), 2)
|
error(string.format('%s:%d: Error: %s', self.fn, self.line, msg), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lexer:nextc()
|
function Lexer:nextc()
|
||||||
|
@ -607,7 +610,7 @@ function Lexer:lex()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Parser:error(msg)
|
function Parser:error(msg)
|
||||||
error(string.format('%s:%d: Error: %s', 'file.asm', self.line, msg), 2)
|
error(string.format('%s:%d: Error: %s', self.fn, self.line, msg), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Parser:advance()
|
function Parser:advance()
|
||||||
|
@ -832,7 +835,6 @@ function Parser:instruction()
|
||||||
local rd = self:register()
|
local rd = self:register()
|
||||||
local const = h[3] or self:error('internal error: expected const')
|
local const = h[3] or self:error('internal error: expected const')
|
||||||
self.dumper:add_instruction_5_5_5_5_6(h[1], rs, 0, rd, 0, const)
|
self.dumper:add_instruction_5_5_5_5_6(h[1], rs, 0, rd, 0, const)
|
||||||
local rd = self:register()
|
|
||||||
elseif h[2] == argtypes.code then
|
elseif h[2] == argtypes.code then
|
||||||
-- OP
|
-- OP
|
||||||
local const = h[3] or self:error('internal error: expected const')
|
local const = h[3] or self:error('internal error: expected const')
|
||||||
|
@ -904,7 +906,7 @@ end
|
||||||
function Dumper:error(msg)
|
function Dumper:error(msg)
|
||||||
-- TODO: sometimes internal error, sometimes not.
|
-- TODO: sometimes internal error, sometimes not.
|
||||||
-- also, we should pass line numbers down to add_instruction.
|
-- also, we should pass line numbers down to add_instruction.
|
||||||
error(string.format('Dumping Error: %s', msg), 2)
|
error(string.format('%s:%d: Dumper Error: %s', self.fn, self.line, msg), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:push(t)
|
function Dumper:push(t)
|
||||||
|
|
Loading…
Reference in a new issue