From 32368f399848eda05922afeb2d47f410a5b0543b Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Tue, 24 Nov 2015 16:34:18 -0800 Subject: [PATCH] optimize LI/LA --- lips.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lips.lua b/lips.lua index d1acbdb..d712df4 100644 --- a/lips.lua +++ b/lips.lua @@ -917,19 +917,24 @@ function Parser:instruction() args.rt = self:register() self:optional_comma() local im = self:const() + local is_label = im[1] == 'LABELSYM' + -- this is really just semantics as far as i can tell if h == 'LI' and is_label then self:error('use LA for labels') end if h == 'LA' and not is_label then self:error('use LI for immediates') end - if h == 'LA' or im[2] >= 0x10000 then + + if im[2] >= 0x10000 then args.rs = args.rt args.immediate = {'UPPER', im} self:format_out(lui[3], lui[1], args, lui[4], lui[5]) - args.immediate = {'LOWER', im} - self:format_out(ori[3], ori[1], args, ori[4], ori[5]) + if im[2] % 0x10000 ~= 0 then + args.immediate = {'LOWER', im} + self:format_out(ori[3], ori[1], args, ori[4], ori[5]) + end else args.rs = 'R0' args.immediate = {'LOWER', im}