From 3cc511182a549e9e8f191137049af319a71228be Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 22 Nov 2015 13:28:47 -0800 Subject: [PATCH] handle immediates in place of most offsets --- Lua/inject/assembler.lua | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Lua/inject/assembler.lua b/Lua/inject/assembler.lua index dca5284..b3a481d 100644 --- a/Lua/inject/assembler.lua +++ b/Lua/inject/assembler.lua @@ -898,6 +898,34 @@ function Parser:instruction() args.immediate = {'LOWER', im} self:format_out(addi[3], addi[1], args, addi[4], addi[5]) end + elseif h[2] == 'tob' then -- or h[2] == 'Tob' then + local lui = instruction_handlers['LUI'] + local args = {} + args.rt = self:register() + self:optional_comma() + local o = self:const() + if o[1] == 'LABELSYM' then + self:error('unimplemented: label as an offset') + end + if self:is_EOL() then + local upper = math.floor(o[2]/0x10000) + local lower = o[2] % 0x10000 + if lower >= 0x8000 then + -- accommodate for offsets being signed + upper = (upper + 1) % 0x10000 + end + local lui_args = {} + lui_args.immediate = {'NUM', upper} + lui_args.rt = 'AT' + self:format_out(lui[3], lui[1], lui_args, lui[4], lui[5]) + args.offset = {'NUM', lower} + args.base = 'AT' + else + args.offset = o + self:optional_comma() + args.base = self:deref() + end + self:format_out(h[3], h[1], args, h[4], h[5]) elseif h[2] ~= nil then args = self:format_in(h[2]) self:format_out(h[3], h[1], args, h[4], h[5]) @@ -961,7 +989,9 @@ function Parser:parse(asm) self:tokenize() self:advance() while true do - if self.tt == 'EOL' then + if self.tt == 'EOF' then + break + elseif self.tt == 'EOL' then -- empty line self:advance() elseif self.tt == 'DEF' then