add aliases, fix cond jumps

This commit is contained in:
Redo
2022-11-01 10:08:45 -06:00
parent dfc9f18ec7
commit 46e5b83cef
4 changed files with 25 additions and 16 deletions

View File

@@ -2,7 +2,9 @@
local arch8608 = require("rom-8608-defs")
local aliases = {
-- todo
["jpz imm8"] = {"jeq imm8"},
["jnz imm8"] = {"jne imm8"},
["jmp q" ] = {"ret" },
}
local function trim(s) return s:gsub("^ +", ""):gsub(" +$", "").."" end
@@ -357,13 +359,18 @@ local function instrsFromArch(arch)
["word [ imm8 ]" ] = function(imms) return arraySize(imms)*2, false end,
["word [ imm16 ]"] = function(imms) return arraySize(imms)*2, false end,
}
local function addMnem(mnem, opcode)
instrs[mnem] = opcode
if mnem:find("%*") then instrs[mnem:gsub("%*", "%[").." ]"] = opcode end
end
for _, instr in ipairs(arch.instructions) do
if instr.mnem then
local mnem = instr.mnem
mnem = mnem:gsub("([%*%+%-])", " %1 ")
mnem = trim(mnem):gsub(" +", " ")
instrs[mnem] = instr.opcode
if mnem:find("%*") then instrs[mnem:gsub("%*", "%[").." ]"] = instr.opcode end
addMnem(mnem, instr.opcode)
local alias = aliases[trim(mnem)]
if alias then for _, v in ipairs(alias) do addMnem(v, instr.opcode) end end
end
end
return instrs