1 #/bin/emblua LUAPREFIX=/*|
7 /*| function pred_ipairs(t, pred)
8 /*| return function(t,k)
13 /*| until not v or pred(k, v)
17 /*| function isa(v) return not v[N==32 and "x64" or "x32only"] end
18 /*| function isaN(k,v) return not v[N==32 and "x64" or "x32"] end
19 #include "test_asm_x86_%(N).h"
20 #include "jitcs_machine.h"
21 #include "jitcs_tmpalloc.h"
22 #include "jitcs_memmgr.h"
23 #include "jitcs_function.h"
24 #include "jitcs_int_virtualregister.h"
28 using namespace jitcs;
30 /*| local idata= runfile("../src/data/x86_inslist.dat")
31 /*| local iadata= runfile("../src/data/x86_insalias.dat")
32 /*| local function hex2(n) return string.format("0x%02x", n) end
35 void TestAssemblerX86_%(N)::setupInstructionNames
36 (std::map<std::string, u32>& m) {
37 /*| for k,op in pred_ipairs(idata.ops, function(k,op) return isa(op.opclass.isa) end) do
38 /*| local fix = string.match(op.name, "^TEST_M[BHWDR]$") and "^0x80000000" or ""
39 m["%(string.lower(op.name))"] = x86_%(N)::I_%(op.name)%(fix);
41 /*| for k,v in ipairs{{0,iadata.aliases}, {N,iadata["aliases"..N]}} do
42 /*| for kk,vv in ipairs(v[2]) do
43 /*| local fix = string.match(vv[1], "^TEST_M[BHWDR]$") and "^0x80000000" or ""
44 m["%(string.lower(vv[1]))"] = x86_%(N)::I_%(vv[2])%(fix);
49 template <typename T> static T* unconst(const T* p) {
50 return const_cast<T*>(p);
52 const char* TestAssemblerX86_%(N)::addInstruction
53 (u32 insid, std::vector<std::string> const& parms) {
55 /*| local rparm = {GR8 = true, GR16 = true, GR32 = true, GR64 = true,
56 /*| VR128 = true, VR256 = true, VR512 = true }
57 /*| local mparm = {MemId = true, ["i8*"] = true, ["i16*"] = true, ["i32*"] = true,
58 /*| ["i64*"] = true, ["i128*"] = true, ["i256*"] = true,
59 /*| ["i512*"] = true }
60 /*| local bbparm = {BB = true}
61 /*| local function t1t(t)
62 /*| if rparm[t] then return "RefOrNull<const VirtualRegister>" end
63 /*| if mparm[t] then return "RefOrNull<MemoryReference>" end
64 /*| if bbparm[t] then return "RefOrNull<BasicBlock>" end
67 /*| local function t2t(t)
68 /*| if rparm[t] then return t.."Ref" end
69 /*| if mparm[t] then return "MemRef" end
70 /*| if bbparm[t] then return "BBRef" end
73 /*| local function t2tb(t,v)
74 /*| if rparm[t] then return "unconst("..v.."._ptr)" end
75 /*| if mparm[t] then return v.."._ptr" end
76 /*| if bbparm[t] then return v.."._ptr" end
79 /*| local _fmt = string.format
80 /*| local parmclasslu, parmclasses = {}, {}
81 /*| for k,op in pred_ipairs(idata.ops, function(k,op) return isa(op.opclass.isa) end) do
83 /*| for l,v in ipairs(op.operands) do
84 /*| if not v.fixed then parmlist = (parmlist and (parmlist..",") or "")..v.type end
86 /*| local t = parmclasslu[parmlist or ""]
88 /*| t = {opcodes={}, operands = op.operands}
89 /*| parmclasslu[parmlist or ""] = t
90 /*| parmclasses[#parmclasses + 1] = t
92 /*| t.opcodes[#t.opcodes + 1] = op.name
94 /*| for k,pcl in ipairs(parmclasses) do
95 /*| for l,v in ipairs(pcl.opcodes) do
96 /*| local fix = string.match(v, "^TEST_M[BHWDR]$") and "^0x80000000" or ""
97 case x86_%(N)::I_%(v)%(fix):
100 /*| local myparms = {}
101 /*| for k,v in ipairs(pcl.operands) do
102 /*| if not v.fixed then myparms[#myparms + 1] = v end
104 if (parms.size() != %(#myparms)) return "invalid number of operands";
105 /*| local myparmslist = ""
106 /*| for it,t in ipairs(myparms) do
107 /*| local tt, ttt = t1t(t.type), t2t(t.type)
108 /*| myparmslist = myparmslist .. ", " .. (ttt and ("vv"..it) or ("v"..it))
110 if (!make%(ttt or t.type)(v%(it), parms[%(it-1)])) return "invalid operand";
112 x86_%(N)::%(ttt) vv%(it)(%(t2tb(t.type,"v"..it)));
116 /*| for l,v in ipairs(pcl.opcodes) do
117 /*| local fix = string.match(v, "^TEST_M[BHWDR]$") and "^0x80000000" or ""
118 case x86_%(N)::I_%(v)%(fix):
119 x86_%(N)::%(v)(ibuf%(myparmslist));
123 return "missing case";
128 return "unknown instruction";