2016-12-11 16:04:53 +11:00
|
|
|
tArgs = {...}
|
|
|
|
|
2017-01-15 07:03:40 +11:00
|
|
|
insd = {[4095] = "ppc",
|
2016-12-11 16:04:53 +11:00
|
|
|
[4094] = "swp",
|
|
|
|
[4093] = "read",
|
|
|
|
[4092] = "write",
|
|
|
|
[4091] = "add",
|
|
|
|
[4090] = "sub",
|
|
|
|
[4089] = "jmp",
|
|
|
|
[4088] = "sez"}
|
|
|
|
insc = {}
|
2017-01-15 07:03:40 +11:00
|
|
|
insc.ppc = 4095
|
2016-12-11 16:04:53 +11:00
|
|
|
insc.swp = 4094
|
|
|
|
insc.read = 4093
|
|
|
|
insc.write = 4092
|
|
|
|
insc.add = 4091
|
|
|
|
insc.sub = 4090
|
|
|
|
insc.jmp = 4089
|
|
|
|
insc.sez = 4088
|
|
|
|
|
2017-02-12 06:41:22 +11:00
|
|
|
local f=io.open("ins.def","rb")
|
|
|
|
local c = "";
|
|
|
|
if f then
|
|
|
|
c=f:read("*a")
|
|
|
|
f:close()
|
|
|
|
insd,insc = {}, {}
|
|
|
|
for l in c:gmatch("(.+)\n") do
|
|
|
|
lt = {}
|
|
|
|
for w in l:gmatch("%S+") do table.insert(lt,w) end
|
|
|
|
insc[lt[2]] = tonumber(lt[1])
|
|
|
|
insd[tonumber(lt[1])] = lt[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not tArgs[2] then
|
|
|
|
error("requires a file argument and a compile/decompile flag")
|
|
|
|
end
|
2016-12-11 16:04:53 +11:00
|
|
|
f = io.open(tArgs[2],"rb")
|
|
|
|
if not f then error("file inaccessable") end
|
|
|
|
c = f:read("*a")
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
for w in c:gmatch("%S+") do
|
|
|
|
if tArgs[1] == "-c" then
|
|
|
|
if insc[w] ~= nil then
|
|
|
|
print(insc[w])
|
|
|
|
else
|
|
|
|
print(w)
|
|
|
|
end
|
|
|
|
elseif tArgs[1] == "-d" then
|
|
|
|
if insd[tonumber(w)] ~= nil then
|
|
|
|
print(insd[tonumber(w)])
|
|
|
|
else
|
|
|
|
print(w)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|