Added VirtualRegister class. Added generation of Register/Resource tables
[jitcs.git] / tools / template2header.lua
blob8fff207a7e7d95ca2f195dd50aa5fbc833bf1787
1 local _setfenv, _ipairs, _loadstr = setfenv, ipairs, loadstring
2 local _open = io.open
3 local _match, _gmatch, _fmt = string.match, string.gmatch, string.format
4 local _gsub, _sub = string.gsub, string.sub
5 local _exec = os.execute
7 local function readfile(n)
8 local f = _open(n) or _open("tools/"..n)
9 local ctnt = f:read("*a")
10 f:close()
11 return ctnt
12 end
14 local srcname, N, dstname = ...
15 if N == "32" or N == "64" then
16 else
17 N = "32"
18 end
19 if (srcname == nil or srcname == "") then
20 srcname = "..\\include\\vmjit_x86_xx_insids.lh"
21 end
22 if dstname == nil or dstname == "" then
23 dstname = _match(_gsub(srcname, "xx", N), "^(.-)%.[^.\\/]*$") .. ".h"
24 end
26 local emblua = _loadstr(readfile("emblua.lua"))
27 local oldtext = readfile(srcname)
28 oldtext = _gsub(oldtext, "%$%$%$", N)
29 local newtext = emblua({type = "string", value = oldtext, file = srcname},{type="string"})
31 local f = _open(dstname, "w")
32 f:write(newtext)
33 f:close()