Module:Instruction set table builder
Documentation for this module may be created at Module:Instruction set table builder/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
function string.split(str, len)
local output = {};
for match in str:gmatch("."..string.rep(".?", len - 1)) do
if(#match > 0) then
table.insert(output, match);
end
end
return output;
end
function string.addSpacing(str, len)
local tab = string.split(str, len)
local output = ""
for i = 1, #i, 1 do
output = output .. tab[i] .. " "
end
return output
end
function p.notation( frame )
local args = getArgs(frame)
local s = "{| class=\"wikitable\" style=\"text-align: center;\"\n! Symbol !! Description\n"
local arr = {}
for k,v in pairs(args) do
table.insert(arr, v)
end
for i = 1, #arr, 2 do
s = s .. "|-\n"
s = s .. "| " .. arr[i] .. " || style=\"text-align: left;\"| " .. arr[i + 1] .. "\n"
end
s = s .. "|}\n"
return s
end
function p.set( frame )
local args = getArgs(frame)
local s = "{| class=\"wikitable\" style=\"text-align: center;\"\n! Mnemonic !! Description !! 32-bit Instruction Word\n"
local arr = {}
for k,v in pairs(args) do
table.insert(arr, v)
end
for i = 1, #arr, 4 do
s = s .. "|-\n"
s = s .. "| style=\"text-align: left; font-family: Consolas,Monaco,Lucida Console,monospace;\"| " .. string.gsub(string.format("%-10s", arr[i]), " ", " ") .. arr[i + 1]
.. " || style=\"text-align: left; font-family: Consolas,Monaco,Lucida Console,monospace;\"| " .. arr[i + 2]
.. " || style=\"font-family: Consolas,Monaco,Lucida Console,monospace;\"| " .. string.addSpacing(string.gsub(arr[i + 3], " ", ""), 4)
.. "\n"
end
s = s .. "|}\n"
return s
end
return p