1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-11-14 09:39:03 -08:00

expect addresses in literal immediates of branches

this is more useful than letting the immediate number simply pass through
This commit is contained in:
Connor Olding 2016-04-02 08:38:22 -07:00
parent fdb4b351a6
commit 4220509be5
2 changed files with 15 additions and 3 deletions

View file

@ -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')

View file

@ -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