From 4220509be5160034ddaff0c77f8aed8858fa3c63 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 2 Apr 2016 08:38:22 -0700 Subject: [PATCH] expect addresses in literal immediates of branches this is more useful than letting the immediate number simply pass through --- lips/Dumper.lua | 10 +++++++++- lips/Muncher.lua | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) 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