mirror of
https://github.com/notwa/mm
synced 2025-02-05 05:23:22 -08:00
update lips
This commit is contained in:
parent
37d711dbec
commit
2d9ca2fae6
1 changed files with 226 additions and 201 deletions
|
@ -413,8 +413,8 @@ local instructions = {
|
|||
SUBIU = {9, 'tsk', 'sti'}, -- ADDIU RT, RS, -immediate
|
||||
|
||||
-- ...that expand to multiple instructions
|
||||
LI = 'LI', -- only one instruction for values < 0x10000
|
||||
LA = 'LA',
|
||||
LI = {}, -- only one instruction for values < 0x10000
|
||||
LA = {},
|
||||
|
||||
-- variable arguments
|
||||
PUSH = 'PUSH',
|
||||
|
@ -426,11 +426,11 @@ local instructions = {
|
|||
--DIV = {}, -- 3 arguments
|
||||
REM = {}, -- 3 arguments
|
||||
|
||||
NAND = 'NAND', -- AND, NOT
|
||||
NANDI = 'NANDI', -- ANDI, NOT
|
||||
NORI = 'NORI', -- ORI, NOT
|
||||
ROL = 'ROL', -- SLL, SRL, OR
|
||||
ROR = 'ROR', -- SRL, SLL, OR
|
||||
NAND = {}, -- AND, NOT
|
||||
NANDI = {}, -- ANDI, NOT
|
||||
NORI = {}, -- ORI, NOT
|
||||
ROL = {}, -- SLL, SRL, OR
|
||||
ROR = {}, -- SRL, SLL, OR
|
||||
|
||||
SEQ = {},
|
||||
SEQI = {},
|
||||
|
@ -1034,16 +1034,9 @@ function Parser:format_out(outformat, first, args, const, formatconst)
|
|||
f(self.dumper, self.line, first, out[1], out[2], out[3], out[4], out[5])
|
||||
end
|
||||
|
||||
function Parser:instruction()
|
||||
local name = self.tok
|
||||
local h = instructions[name]
|
||||
self:advance()
|
||||
local overrides = {}
|
||||
|
||||
-- FIXME: errors thrown here probably have the wrong line number (+1)
|
||||
|
||||
if h == nil then
|
||||
self:error('undefined instruction')
|
||||
elseif h == 'LI' then
|
||||
function overrides.LI(self, name)
|
||||
local lui = instructions['LUI']
|
||||
local ori = instructions['ORI']
|
||||
local addiu = instructions['ADDIU']
|
||||
|
@ -1076,7 +1069,9 @@ function Parser:instruction()
|
|||
args.immediate = {'LOWER', im}
|
||||
self:format_out(addiu[3], addiu[1], args, addiu[4], addiu[5])
|
||||
end
|
||||
elseif h == 'LA' then
|
||||
end
|
||||
|
||||
function overrides.LA(self, name)
|
||||
local lui = instructions['LUI']
|
||||
local addiu = instructions['ADDIU']
|
||||
local args = {}
|
||||
|
@ -1089,9 +1084,11 @@ function Parser:instruction()
|
|||
self:format_out(lui[3], lui[1], args, lui[4], lui[5])
|
||||
args.immediate = {'LOWER', im}
|
||||
self:format_out(addiu[3], addiu[1], args, addiu[4], addiu[5])
|
||||
elseif h == 'PUSH' or h == 'POP' or h == 'JPOP' then
|
||||
end
|
||||
|
||||
function overrides.PUSH(self, name)
|
||||
local addi = instructions['ADDI']
|
||||
local w = instructions[h == 'PUSH' and 'SW' or 'LW']
|
||||
local w = instructions[name == 'PUSH' and 'SW' or 'LW']
|
||||
local jr = instructions['JR']
|
||||
local stack = {}
|
||||
while not self:is_EOL() do
|
||||
|
@ -1111,10 +1108,10 @@ function Parser:instruction()
|
|||
end
|
||||
end
|
||||
if #stack == 0 then
|
||||
self:error(h..' requires at least one argument')
|
||||
self:error(name..' requires at least one argument')
|
||||
end
|
||||
local args = {}
|
||||
if h == 'PUSH' then
|
||||
if name == 'PUSH' then
|
||||
args.rt = 'SP'
|
||||
args.rs = 'SP'
|
||||
args.immediate = {'NEGATE', {'NUM', #stack*4}}
|
||||
|
@ -1128,17 +1125,21 @@ function Parser:instruction()
|
|||
self:format_out(w[3], w[1], args, w[4], w[5])
|
||||
end
|
||||
end
|
||||
if h == 'JPOP' then
|
||||
if name == 'JPOP' then
|
||||
args.rs = 'RA'
|
||||
self:format_out(jr[3], jr[1], args, jr[4], jr[5])
|
||||
end
|
||||
if h == 'POP' or h == 'JPOP' then
|
||||
if name == 'POP' or name == 'JPOP' then
|
||||
args.rt = 'SP'
|
||||
args.rs = 'SP'
|
||||
args.immediate = {'NUM', #stack*4}
|
||||
self:format_out(addi[3], addi[1], args, addi[4], addi[5])
|
||||
end
|
||||
elseif h == 'NAND' then
|
||||
end
|
||||
overrides.POP = overrides.PUSH
|
||||
overrides.JPOP = overrides.PUSH
|
||||
|
||||
function overrides.NAND(self, name)
|
||||
local and_ = instructions['AND']
|
||||
local nor = instructions['NOR']
|
||||
local args = {}
|
||||
|
@ -1151,7 +1152,9 @@ function Parser:instruction()
|
|||
args.rs = args.rd
|
||||
args.rt = 'R0'
|
||||
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
||||
elseif h == 'NANDI' then
|
||||
end
|
||||
|
||||
function overrides.NANDI(self, name)
|
||||
local andi = instructions['ANDI']
|
||||
local nor = instructions['NOR']
|
||||
local args = {}
|
||||
|
@ -1165,7 +1168,9 @@ function Parser:instruction()
|
|||
args.rs = args.rt
|
||||
args.rt = 'R0'
|
||||
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
||||
elseif h == 'NORI' then
|
||||
end
|
||||
|
||||
function overrides.NORI(self, name)
|
||||
local ori = instructions['ORI']
|
||||
local nor = instructions['NOR']
|
||||
local args = {}
|
||||
|
@ -1179,7 +1184,9 @@ function Parser:instruction()
|
|||
args.rs = args.rt
|
||||
args.rt = 'R0'
|
||||
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
||||
elseif h == 'ROL' then
|
||||
end
|
||||
|
||||
function overrides.ROL(self, name)
|
||||
local sll = instructions['SLL']
|
||||
local srl = instructions['SRL']
|
||||
local or_ = instructions['OR']
|
||||
|
@ -1204,7 +1211,9 @@ function Parser:instruction()
|
|||
args.rs = left
|
||||
args.rt = 'AT'
|
||||
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
|
||||
elseif h == 'ROR' then
|
||||
end
|
||||
|
||||
function overrides.ROR(self, name)
|
||||
local sll = instructions['SLL']
|
||||
local srl = instructions['SRL']
|
||||
local or_ = instructions['OR']
|
||||
|
@ -1229,14 +1238,30 @@ function Parser:instruction()
|
|||
args.rs = right
|
||||
args.rt = 'AT'
|
||||
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
|
||||
elseif name == 'JR' then
|
||||
end
|
||||
|
||||
function overrides.JR(self, name)
|
||||
local jr = instructions['JR']
|
||||
local args = {}
|
||||
if self:is_EOL() then
|
||||
args.rs = 'RA'
|
||||
else
|
||||
args.rs = self:register()
|
||||
end
|
||||
self:format_out(h[3], h[1], args, h[4], h[5])
|
||||
self:format_out(jr[3], jr[1], args, jr[4], jr[5])
|
||||
end
|
||||
|
||||
function Parser:instruction()
|
||||
local name = self.tok
|
||||
local h = instructions[name]
|
||||
self:advance()
|
||||
|
||||
-- FIXME: errors thrown here probably have the wrong line number (+1)
|
||||
|
||||
if h == nil then
|
||||
self:error('undefined instruction')
|
||||
elseif overrides[name] then
|
||||
overrides[name](self, name)
|
||||
elseif h[2] == 'tob' then -- or h[2] == 'Tob' then
|
||||
local lui = instructions['LUI']
|
||||
local args = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue