1 local _setfenv
, _ipairs
, _loadstr
= setfenv
, ipairs
, loadstring
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")
14 local testname
, outname
= ...
15 if (testname
== nil or testname
== "") then
16 testname
= "..\\src-lib\\x86\\src\\_x86_insalias.ltxt"
18 if outname
== nil or outname
== "" then
19 outname
= _match(testname
, "^(.-)%.[^.\\/]*$") .. ".dat"
22 local emblua
= _loadstr(readfile("emblua.lua"))
23 local aliaslist
= emblua(testname
,{type="string"})
25 local function rep_r(c
)
26 if c
== "R" then return "R" end
27 if c
== "M" then return "M" end
28 if c
== "m" then return "M" end
30 local function rep_w(c
)
31 if c
== "R" then return "W" end
32 if c
== "M" then return "M32" end
33 if c
== "m" then return "M" end
35 local function rep_d(c
)
36 if c
== "R" then return "D" end
37 if c
== "M" then return "M64" end
38 if c
== "m" then return "M" end
40 local aliases
, aliases32
, aliases64
= {}, {}, {}
41 for l
in _gmatch(aliaslist
, "([^\r\n]*)[\r\n]") do
42 if _match(l
, "^%s*//") then
45 if _match(l
, "%$([RMm])") then
46 l
= _gsub(l
, "%$([RMm])", rep_r
)
47 .. " -> " .. _gsub(l
, "%$([RMm])", rep_w
)
48 .. ", " .. _gsub(l
, "%$([RMm])", rep_d
)
50 local l
,r32
,r64
= l
:match("^%s*(%S+)%s*%->%s*(%S+)%s*,%s*(%S+)%s*$")
51 if l
and r32
and r64
then
52 if r32
== r64
and r32
~= "INVALID" then
53 aliases
[#aliases
+1] = {l
,r32
};
55 if r32
~= "INVALID" then aliases32
[#aliases32
+1] = {l
,r32
}; end
56 if r64
~= "INVALID" then aliases64
[#aliases64
+1] = {l
,r64
}; end
61 local f
= _open(outname
, "w")
63 f
:write("aliases = {\n")
64 for k
,v
in _ipairs(aliases
) do
65 f
:write(_fmt(" {%q, %q},\n", v
[1], v
[2]))
67 f
:write("}, aliases32 = {\n")
68 for k
,v
in _ipairs(aliases32
) do
69 f
:write(_fmt(" {%q, %q},\n", v
[1], v
[2]))
71 f
:write("}, aliases64 = {\n")
72 for k
,v
in _ipairs(aliases64
) do
73 f
:write(_fmt(" {%q, %q},\n", v
[1], v
[2]))