diff --git a/lips/Dumper.lua b/lips/Dumper.lua index 24e2494..d908b95 100644 --- a/lips/Dumper.lua +++ b/lips/Dumper.lua @@ -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') diff --git a/lips/Muncher.lua b/lips/Muncher.lua index db54263..c0ab378 100644 --- a/lips/Muncher.lua +++ b/lips/Muncher.lua @@ -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