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