2 Instruction Alias To Data tool for X86:
3 Copyright (C) 2013-2014 Dirk Steinke.
4 See copyright and license notice in COPYRIGHT or include/jitcs.h
6 The tool reads src/data/x86_insalias.ltxt and transforms it into
7 src/data/x86_insalias.dat.
10 local _setfenv
, _ipairs
, _loadstr
= setfenv
, ipairs
, loadstring
12 local _match
, _gmatch
, _fmt
= string.match
, string.gmatch
, string.format
13 local _gsub
, _sub
= string.gsub, string.sub
14 local _exec
= os
.execute
16 local function readfile(n
)
17 local f
= _open(n
) or _open("tools/"..n
)
18 local ctnt
= f
:read("*a")
23 local testname
, outname
= ...
24 if (testname
== nil or testname
== "") then
25 testname
= "..\\src-lib\\x86\\src\\_x86_insalias.ltxt"
27 if outname
== nil or outname
== "" then
28 outname
= _match(testname
, "^(.-)%.[^.\\/]*$") .. ".dat"
31 local emblua
= _loadstr(readfile("emblua.lua"))
32 local aliaslist
= emblua(testname
,{type="string"})
34 local function rep_r(c
)
35 if c
== "R" then return "R" end
36 if c
== "M" then return "M" end
37 if c
== "m" then return "M" end
39 local function rep_w(c
)
40 if c
== "R" then return "W" end
41 if c
== "M" then return "M32" end
42 if c
== "m" then return "M" end
44 local function rep_d(c
)
45 if c
== "R" then return "D" end
46 if c
== "M" then return "M64" end
47 if c
== "m" then return "M" end
49 local aliases
, aliases32
, aliases64
= {}, {}, {}
50 for l
in _gmatch(aliaslist
, "([^\r\n]*)[\r\n]") do
51 if _match(l
, "^%s*//") then
54 if _match(l
, "%$([RMm])") then
55 l
= _gsub(l
, "%$([RMm])", rep_r
)
56 .. " -> " .. _gsub(l
, "%$([RMm])", rep_w
)
57 .. ", " .. _gsub(l
, "%$([RMm])", rep_d
)
59 local l
,r32
,r64
= l
:match("^%s*(%S+)%s*%->%s*(%S+)%s*,%s*(%S+)%s*$")
60 if l
and r32
and r64
then
61 if r32
== r64
and r32
~= "INVALID" then
62 aliases
[#aliases
+1] = {l
,r32
};
64 if r32
~= "INVALID" then aliases32
[#aliases32
+1] = {l
,r32
}; end
65 if r64
~= "INVALID" then aliases64
[#aliases64
+1] = {l
,r64
}; end
70 local f
= _open(outname
, "w")
72 f
:write("aliases = {\n")
73 for k
,v
in _ipairs(aliases
) do
74 f
:write(_fmt(" {%q, %q},\n", v
[1], v
[2]))
76 f
:write("}, aliases32 = {\n")
77 for k
,v
in _ipairs(aliases32
) do
78 f
:write(_fmt(" {%q, %q},\n", v
[1], v
[2]))
80 f
:write("}, aliases64 = {\n")
81 for k
,v
in _ipairs(aliases64
) do
82 f
:write(_fmt(" {%q, %q},\n", v
[1], v
[2]))