mirror of
https://github.com/notwa/lips
synced 2024-05-18 08:23:23 -07:00
use key instead of value for overrides
This commit is contained in:
parent
5fb0829319
commit
73920dd31d
49
lips.lua
49
lips.lua
|
@ -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 = {},
|
||||||
|
@ -1036,7 +1036,7 @@ end
|
||||||
|
|
||||||
local overrides = {}
|
local overrides = {}
|
||||||
|
|
||||||
function overrides.LI(self, h)
|
function overrides.LI(self, name)
|
||||||
local lui = instructions['LUI']
|
local lui = instructions['LUI']
|
||||||
local ori = instructions['ORI']
|
local ori = instructions['ORI']
|
||||||
local addiu = instructions['ADDIU']
|
local addiu = instructions['ADDIU']
|
||||||
|
@ -1071,7 +1071,7 @@ function overrides.LI(self, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function overrides.LA(self, h)
|
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 = {}
|
||||||
|
@ -1086,9 +1086,9 @@ function overrides.LA(self, h)
|
||||||
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
|
||||||
|
|
||||||
function overrides.PUSH(self, h)
|
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
|
||||||
|
@ -1108,10 +1108,10 @@ function overrides.PUSH(self, h)
|
||||||
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}}
|
||||||
|
@ -1125,11 +1125,11 @@ function overrides.PUSH(self, h)
|
||||||
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}
|
||||||
|
@ -1139,7 +1139,7 @@ end
|
||||||
overrides.POP = overrides.PUSH
|
overrides.POP = overrides.PUSH
|
||||||
overrides.JPOP = overrides.PUSH
|
overrides.JPOP = overrides.PUSH
|
||||||
|
|
||||||
function overrides.NAND(self, h)
|
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 = {}
|
||||||
|
@ -1154,7 +1154,7 @@ function overrides.NAND(self, h)
|
||||||
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
||||||
end
|
end
|
||||||
|
|
||||||
function overrides.NANDI(self, h)
|
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 = {}
|
||||||
|
@ -1170,7 +1170,7 @@ function overrides.NANDI(self, h)
|
||||||
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
||||||
end
|
end
|
||||||
|
|
||||||
function overrides.NORI(self, h)
|
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 = {}
|
||||||
|
@ -1186,7 +1186,7 @@ function overrides.NORI(self, h)
|
||||||
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
self:format_out(nor[3], nor[1], args, nor[4], nor[5])
|
||||||
end
|
end
|
||||||
|
|
||||||
function overrides.ROL(self, h)
|
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']
|
||||||
|
@ -1213,7 +1213,7 @@ function overrides.ROL(self, h)
|
||||||
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
|
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
|
||||||
end
|
end
|
||||||
|
|
||||||
function overrides.ROR(self, h)
|
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']
|
||||||
|
@ -1240,14 +1240,15 @@ function overrides.ROR(self, h)
|
||||||
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
|
self:format_out(or_[3], or_[1], args, or_[4], or_[5])
|
||||||
end
|
end
|
||||||
|
|
||||||
function overrides.JR(self, h)
|
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
|
end
|
||||||
|
|
||||||
function Parser:instruction()
|
function Parser:instruction()
|
||||||
|
@ -1259,8 +1260,8 @@ function Parser:instruction()
|
||||||
|
|
||||||
if h == nil then
|
if h == nil then
|
||||||
self:error('undefined instruction')
|
self:error('undefined instruction')
|
||||||
elseif overrides[h] then
|
elseif overrides[name] then
|
||||||
overrides[h](self, h)
|
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…
Reference in New Issue
Block a user