1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-05-18 16:33:22 -07:00

reimplement addressing modes

this allows labels as offsets
and implied offsets of 0
This commit is contained in:
Connor Olding 2016-01-13 14:31:58 -08:00
parent bf3f86e568
commit e21dbc72e6
2 changed files with 24 additions and 17 deletions

View File

@ -146,7 +146,7 @@ function Dumper:desym(tok)
end end
return rel % 0x10000 return rel % 0x10000
end end
self:error('failed to desym') -- internal error? error('Internal Error: failed to desym')
end end
function Dumper:toval(tok) function Dumper:toval(tok)

View File

@ -264,27 +264,34 @@ function Parser:instruction()
self:error('undefined instruction') self:error('undefined instruction')
elseif overrides[name] then elseif overrides[name] then
overrides[name](self, name) overrides[name](self, name)
elseif h[2] == 'tob' then -- or h[2] == 'Tob' then elseif h[2] == 'tob' then -- TODO: or h[2] == 'Tob' then
local lui = data.instructions['LUI'] local lui = data.instructions['LUI']
local addu = data.instructions['ADDU']
local args = {} local args = {}
args.rt = self:register() args.rt = self:register()
self:optional_comma() self:optional_comma()
local o = self:const() if self.tt == 'DEREF' then
local is_label = o[1] == 'LABELSYM' args.offset = {'NUM', 0}
if self:is_EOL() then
local lui_args = {}
lui_args.immediate = {'UPPEROFF', o}
lui_args.rt = 'AT'
self:format_out(lui, lui_args)
args.offset = {'LOWER', o}
args.base = 'AT'
else
if is_label then
self:error('labels cannot be used as offsets')
end
args.offset = {'SIGNED', o}
self:optional_comma()
args.base = self:deref() args.base = self:deref()
else -- NUM or LABELSYM
local lui_args = {}
local addu_args = {}
local o = self:const()
args.offset = {'LOWER', o}
if o[1] == 'LABELSYM' or o[2] >= 0x80000000 then
lui_args.immediate = {'UPPEROFF', o}
lui_args.rt = 'AT'
self:format_out(lui, lui_args)
if not self:is_EOL() then
addu_args.rd = 'AT'
addu_args.rs = 'AT'
addu_args.rt = self:deref()
self:format_out(addu, addu_args)
end
args.base = 'AT'
else
args.base = self:deref()
end
end end
self:format_out(h, args) self:format_out(h, args)
elseif h[2] ~= nil then elseif h[2] ~= nil then