mirror of
https://github.com/notwa/mm
synced 2024-11-05 00:19:02 -08:00
update lips
This commit is contained in:
parent
7114fdbcf5
commit
955b5a5848
3 changed files with 21 additions and 4 deletions
|
@ -100,7 +100,7 @@ function Dumper:add_directive(fn, line, name, a, b)
|
|||
t.kind = 'goto'
|
||||
t.addr = a
|
||||
insert(self.commands, t)
|
||||
self.pos = a % 0x80000000
|
||||
self.pos = a
|
||||
self:advance(0)
|
||||
elseif name == 'ALIGN' then
|
||||
t.kind = 'ahead'
|
||||
|
@ -129,7 +129,15 @@ function Dumper:add_directive(fn, line, name, a, b)
|
|||
end
|
||||
|
||||
function Dumper:desym(t)
|
||||
if type(t.tok) == 'number' then
|
||||
if t.tt == 'REL' then
|
||||
local target = t.tok % 0x80000000
|
||||
local pos = self.pos % 0x80000000
|
||||
local rel = floor(target/4) - 1 - floor(pos/4)
|
||||
if rel > 0x8000 or rel <= -0x8000 then
|
||||
self:error('branch too far')
|
||||
end
|
||||
return rel % 0x10000
|
||||
elseif type(t.tok) == 'number' then
|
||||
return t.tok
|
||||
elseif t.tt == 'REG' then
|
||||
assert(data.all_registers[t.tok], 'Internal Error: unknown register')
|
||||
|
|
|
@ -28,6 +28,7 @@ function Lexer:init(asm, fn, options)
|
|||
self.pos = 1
|
||||
self.line = 1
|
||||
self.EOF = -1
|
||||
self.was_EOL = false
|
||||
self:nextc()
|
||||
end
|
||||
|
||||
|
@ -59,6 +60,7 @@ function Lexer:nextc()
|
|||
end
|
||||
self.ord = 10
|
||||
end
|
||||
self.was_EOL = self.ord == 10
|
||||
|
||||
self.chr = char(self.ord)
|
||||
if self.pos <= #self.asm then
|
||||
|
@ -281,6 +283,9 @@ function Lexer:lex(_yield)
|
|||
yield('EOL', '\n')
|
||||
self:nextc()
|
||||
elseif self.ord == self.EOF then
|
||||
if not self.was_EOL then
|
||||
yield('EOL', '\n')
|
||||
end
|
||||
yield('EOF', self.EOF)
|
||||
break
|
||||
elseif self.chr == ';' then
|
||||
|
|
|
@ -116,8 +116,12 @@ function Muncher:const(relative, no_label)
|
|||
self:error('labels are not allowed here')
|
||||
end
|
||||
local t = self:token(self.t)
|
||||
if relative and self.tt == 'LABELSYM' then
|
||||
t.tt = 'LABELREL'
|
||||
if relative then
|
||||
if self.tt == 'LABELSYM' then
|
||||
t.tt = 'LABELREL'
|
||||
else
|
||||
t.tt = 'REL'
|
||||
end
|
||||
end
|
||||
self:advance()
|
||||
return t
|
||||
|
|
Loading…
Reference in a new issue