mirror of
https://github.com/notwa/mm
synced 2024-11-05 02:49: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.kind = 'goto'
|
||||||
t.addr = a
|
t.addr = a
|
||||||
insert(self.commands, t)
|
insert(self.commands, t)
|
||||||
self.pos = a % 0x80000000
|
self.pos = a
|
||||||
self:advance(0)
|
self:advance(0)
|
||||||
elseif name == 'ALIGN' then
|
elseif name == 'ALIGN' then
|
||||||
t.kind = 'ahead'
|
t.kind = 'ahead'
|
||||||
|
@ -129,7 +129,15 @@ function Dumper:add_directive(fn, line, name, a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:desym(t)
|
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
|
return t.tok
|
||||||
elseif t.tt == 'REG' then
|
elseif t.tt == 'REG' then
|
||||||
assert(data.all_registers[t.tok], 'Internal Error: unknown register')
|
assert(data.all_registers[t.tok], 'Internal Error: unknown register')
|
||||||
|
|
|
@ -28,6 +28,7 @@ function Lexer:init(asm, fn, options)
|
||||||
self.pos = 1
|
self.pos = 1
|
||||||
self.line = 1
|
self.line = 1
|
||||||
self.EOF = -1
|
self.EOF = -1
|
||||||
|
self.was_EOL = false
|
||||||
self:nextc()
|
self:nextc()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ function Lexer:nextc()
|
||||||
end
|
end
|
||||||
self.ord = 10
|
self.ord = 10
|
||||||
end
|
end
|
||||||
|
self.was_EOL = self.ord == 10
|
||||||
|
|
||||||
self.chr = char(self.ord)
|
self.chr = char(self.ord)
|
||||||
if self.pos <= #self.asm then
|
if self.pos <= #self.asm then
|
||||||
|
@ -281,6 +283,9 @@ function Lexer:lex(_yield)
|
||||||
yield('EOL', '\n')
|
yield('EOL', '\n')
|
||||||
self:nextc()
|
self:nextc()
|
||||||
elseif self.ord == self.EOF then
|
elseif self.ord == self.EOF then
|
||||||
|
if not self.was_EOL then
|
||||||
|
yield('EOL', '\n')
|
||||||
|
end
|
||||||
yield('EOF', self.EOF)
|
yield('EOF', self.EOF)
|
||||||
break
|
break
|
||||||
elseif self.chr == ';' then
|
elseif self.chr == ';' then
|
||||||
|
|
|
@ -116,8 +116,12 @@ function Muncher:const(relative, no_label)
|
||||||
self:error('labels are not allowed here')
|
self:error('labels are not allowed here')
|
||||||
end
|
end
|
||||||
local t = self:token(self.t)
|
local t = self:token(self.t)
|
||||||
if relative and self.tt == 'LABELSYM' then
|
if relative then
|
||||||
t.tt = 'LABELREL'
|
if self.tt == 'LABELSYM' then
|
||||||
|
t.tt = 'LABELREL'
|
||||||
|
else
|
||||||
|
t.tt = 'REL'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self:advance()
|
self:advance()
|
||||||
return t
|
return t
|
||||||
|
|
Loading…
Reference in a new issue