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 isaN(k,v) return not v[N==32 and "x64" or "x32"] end
18 //===-- jitcs_x86_%(N)_regs.h C++ -----------------------------------------*-===//
20 // Register definitions for %(N)bit x86 code.
22 //===----------------------------------------------------------------------===//
24 #ifndef _JITCS_X86_%(N)_REGS_H_
25 #define _JITCS_X86_%(N)_REGS_H_
27 #include "jitcs_base.h"
28 #include "jitcs_ids.h"
30 /*| local data= runfile("../src/data/x86_reglist.dat")
31 /*| local function hex2(n) return string.format("0x%02x", n) end
35 struct VirtualRegister;
39 /*| for k,v in ipairs(data.classes) do
42 /*| local c2r, c2ra, n2r = {}, {}, {}
43 /*| for k,v in ipairs(data.registers) do
45 /*| local c = c2r[v.class] or {}
49 /*| for k,v2 in ipairs(data.registeraliases) do
50 /*| local v = n2r[v2.dest]
51 /*| local c = c2ra[v.class] or {}
57 RC_Count = %(#data.refclasses),
61 #define RCLID(ID) static_cast<RegClassId>((ID))
62 /*| for l,cl in pred_ipairs(data.refclasses,isaN) do
63 static const RegClassId RC_%(cl.name) = RCLID(%l);
65 /*| for l,cl in pred_ipairs(data.refclassaliases,isaN) do
66 static const RegClassId RC_%(cl.name) = RC_%(cl.dest);
71 enum RegSubClassEnum {
72 /*| for l,cl in pred_ipairs(data.classes,isaN) do
79 /*| for l,cl in pred_ipairs(data.classes, isaN) do
81 /*| for k,v in pred_ipairs(c2r[cl.name], isaN) do
82 R_%(v.name) = %(hex2(v.id)),
84 /*| if c2ra[cl.name] and #c2ra[cl.name] > 0 then
86 /*| for k,v in pred_ipairs(c2ra[cl.name],isaN) do
87 R_%(v.name) = R_%(v.dest),
92 /*| for k,v in pred_ipairs(data.classaliases,isaN) do
93 typedef %(v.dest)Enum %(v.name)Enum;
97 /*| local nn32, nn64, v2nn = 0, 0, {}
99 /*| for l,cl in ipairs(data.classes) do
100 /*| for k,v in ipairs(c2r[cl.name]) do
101 /*| local cond32 = (cl.x32 or not cl.x64) and (v.x32 or not v.x64)
102 /*| local cond64 = (not cl.x32 or cl.x64) and (not v.x32 or v.x64)
103 /*| if (z == 1 and cond32 and cond64) or (z == 2 and cond32 and not cond64) or (z == 3 and not cond32 and cond64) then
104 /*| v2nn[v.name] = {x32 = cond32 and nn32, x64 = cond64 and nn64}
105 /*| if (cond32) then nn32 = nn32 + 1 end
106 /*| if (cond64) then nn64 = nn64 + 1 end
113 /*| for k = 1, (N == 32 and nn32 or nn64) do
114 extern const VirtualRegister _fixedRegister%(k - 1);
116 template <const VirtualRegister &VR, RegSubClassEnum RSC>
118 operator VirtualRegister *() const { return const_cast<VirtualRegister*>(&VR); }
120 /*| for l,cl in pred_ipairs(data.classes,isaN) do
122 /*| for k,v in pred_ipairs(c2r[cl.name],isaN) do
123 static const RegLookup<_fixedRegister%(N==32 and v2nn[v.name].x32 or v2nn[v.name].x64), RSC_%(cl.name)> %(v.name);
125 /*| if c2ra[cl.name] and #c2ra[cl.name] > 0 then
127 /*| for k,v in pred_ipairs(c2ra[cl.name],isaN) do
128 static const RegLookup<_fixedRegister%(N==32 and v2nn[v.dest].x32 or v2nn[v.dest].x64), RSC_%(cl.name)> %(v.name);
134 /*| function buildt(base, range)
135 /*| local f,t = range:match("^(%d+)%-(%d+)$")
136 /*| return "(r >= "..(base+tonumber(f)).." && r <= "..(base+tonumber(t))..")"
138 /*| function testrn(v32, v64)
139 /*| --if (v32 and v64 and v32 == v64) then return v32 end
140 /*| return "("..(((N==32 and v32) or (N==64 and v64)) or "false")..")"
142 /*| for l,cl in pred_ipairs(data.refclasses,isaN) do
143 /*| local test, test2 = nil, nil
144 /*| for k,v in ipairs(cl.classes) do
145 /*| local b = n2c[v].regbase
146 /*| local t32, t64 = buildt(b,n2c[v].restrictres or n2c[v].restrictres_32 or "0-7"),
147 /*| buildt(b,n2c[v].restrictres or n2c[v].restrictres_64 or "0-15")
148 /*| test = (test and (test .. " || ") or "")
149 /*| test = test .. testrn((n2c[v].x32 or not n2c[v].x64) and t32,
150 /*| (n2c[v].x64 or not n2c[v].x32) and t64)
152 /*| for k,v in ipairs(cl.superrefclasses or {}) do
153 /*| local t = "rc == RC_" .. v
154 /*| test2 = (test2 or "") .. " || "
155 /*| test2 = test2 .. testrn((n2c[v].x32 or not n2c[v].x64) and t, (n2c[v].x64 or not n2c[v].x32) and t)
157 inline bool Is%(cl.name)(RegId r) { return %(test or ""); }
158 inline bool Is%(cl.name)(RegClassId rc) { return rc == RC_%(cl.name)%(test2 or ""); }
162 RegClassId GetRegClass(const VirtualRegister* r);
164 /*| for l,cl in pred_ipairs(data.refclasses,isaN) do
165 struct %(cl.name)Ref : public Ref<VirtualRegister> {
166 %(cl.name)Ref() = delete;
167 %(cl.name)Ref(const %(cl.name)Ref& other) = default;
168 %(cl.name)Ref& operator =(const %(cl.name)Ref& other) = default;
169 /*| for k,v in pred_ipairs(cl.classes,function(k,v) return isaN(nil,n2c[v]) end) do
170 template<const VirtualRegister & VR>
171 %(cl.name)Ref(RegLookup<VR, RSC_%(n2c[v].name)> r) : Ref<VirtualRegister>(VR) {}
173 %(cl.name)Ref(Ref<VirtualRegister> r) : Ref<VirtualRegister>(r) { assert(Is%(cl.name)(GetRegClass(r._ptr))); }
174 %(cl.name)Ref(VirtualRegister* r) : Ref<VirtualRegister>(r) { assert(Is%(cl.name)(GetRegClass(r))); }
179 /*| for l,cl in pred_ipairs(data.refclassaliases,isaN) do
180 typedef %(cl.dest)Ref %(cl.name)Ref;
184 } // end of namespace jitcs::x86_%(N)
185 } // end of namespace jitcs
187 // _JITCS_X86_%(N)_REGS_H_