mirror of
https://github.com/notwa/lips
synced 2025-03-09 19:32:49 -07: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:
parent
fdb4b351a6
commit
4220509be5
2 changed files with 15 additions and 3 deletions
|
@ -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')
|
||||||
|
|
|
@ -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…
Add table
Reference in a new issue