From f30aabe82f61dbd6901f6a75dadde0a64dc626d2 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 3 Aug 2026 10:44:17 +0200 Subject: Modernize jit.* Lua modules. --- src/jit/dump.lua | 132 +++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) (limited to 'src/jit/dump.lua') diff --git a/src/jit/dump.lua b/src/jit/dump.lua index 6a700bbe4..3532e3c4e 100644 --- a/src/jit/dump.lua +++ b/src/jit/dump.lua @@ -62,7 +62,7 @@ local traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek local tracemc, tracesnap = jutil.tracemc, jutil.tracesnap local traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr local bit = require("bit") -local band, shr, tohex = bit.band, bit.rshift, bit.tohex +local tohex = bit.tohex local sub, gsub, format = string.sub, string.gsub, string.format local byte, rep = string.byte, string.rep local type, tostring = type, tostring @@ -90,7 +90,7 @@ local function fillsymtab_tr(tr, nexit) end for i=0,nexit-1 do local addr = traceexitstub(tr, i) - if addr < 0 then addr = addr + 2^32 end + if addr < 0 then addr += 2^32 end t[addr] = tostring(i) end local addr = traceexitstub(tr, nexit) @@ -105,9 +105,9 @@ local function fillsymtab(tr, nexit) local ircall = vmdef.ircall for i=0,#ircall do local addr = ircalladdr(i) - if addr ~= 0 then - if maskaddr then addr = band(addr, maskaddr) end - if addr < 0 then addr = addr + 2^32 end + if addr != 0 then + if maskaddr then addr &= maskaddr end + if addr < 0 then addr += 2^32 end t[addr] = ircall[i] end end @@ -123,7 +123,7 @@ local function fillsymtab(tr, nexit) nexit = 1000000 break end - if addr < 0 then addr = addr + 2^32 end + if addr < 0 then addr += 2^32 end t[addr] = tostring(i) end nexitsym = nexit @@ -142,12 +142,12 @@ local function dump_mcode(tr) local mcode, addr, loop = tracemc(tr) if not mcode then return end if not disass then disass = require("jit.dis_"..jit.arch) end - if addr < 0 then addr = addr + 2^32 end + if addr < 0 then addr += 2^32 end out:write("---- TRACE ", tr, " mcode ", #mcode, "\n") local ctx = disass.create(mcode, addr, dumpwrite) ctx.hexdump = 0 ctx.symtab = fillsymtab(tr, info.nexit) - if loop ~= 0 then + if loop != 0 then symtab[addr+loop] = "LOOP" ctx:disass(0, loop) out:write("->LOOP:\n") @@ -233,7 +233,7 @@ local html_escape = { ["<"] = "<", [">"] = ">", ["&"] = "&", } local function colorize_html(s, t, extra) s = gsub(s, "[<>&]", html_escape) return format('%s', - irtype_text[t], extra and " irt_extra" or "", s) + irtype_text[t], extra ? " irt_extra" : "", s) end local irtype_html = setmetatable({}, @@ -268,25 +268,25 @@ local colorize, irtype local litname = { ["SLOAD "] = setmetatable({}, { __index = function(t, mode) local s = "" - if band(mode, 1) ~= 0 then s = s.."P" end - if band(mode, 2) ~= 0 then s = s.."F" end - if band(mode, 4) ~= 0 then s = s.."T" end - if band(mode, 8) ~= 0 then s = s.."C" end - if band(mode, 16) ~= 0 then s = s.."R" end - if band(mode, 32) ~= 0 then s = s.."I" end - if band(mode, 64) ~= 0 then s = s.."K" end + if mode & 1 != 0 then s ..= "P" end + if mode & 2 != 0 then s ..= "F" end + if mode & 4 != 0 then s ..= "T" end + if mode & 8 != 0 then s ..= "C" end + if mode & 16 != 0 then s ..= "R" end + if mode & 32 != 0 then s ..= "I" end + if mode & 64 != 0 then s ..= "K" end t[mode] = s return s end}), ["XLOAD "] = { [0] = "", "R", "V", "RV", "U", "RU", "VU", "RVU", }, ["CONV "] = setmetatable({}, { __index = function(t, mode) - local s = irtype[band(mode, 31)] - s = irtype[band(shr(mode, 5), 31)].."."..s - if band(mode, 0x800) ~= 0 then s = s.." sext" end - local c = shr(mode, 12) - if c == 1 then s = s.." none" - elseif c == 2 then s = s.." index" - elseif c == 3 then s = s.." check" end + local s = irtype[mode & 31] + s = irtype[(mode >> 5) & 31].."."..s + if mode & 0x800 != 0 then s ..= " sext" end + local c = mode >> 12 + if c == 1 then s ..= " none" + elseif c == 2 then s ..= " index" + elseif c == 3 then s ..= " check" end t[mode] = s return s end}), @@ -325,16 +325,16 @@ local function formatk(tr, idx, sn) local s if tn == "number" then if t < 12 then - s = k == 0 and "NULL" or format("[0x%08x]", k) - elseif band(sn or 0, 0x30000) ~= 0 then - s = band(sn, 0x20000) ~= 0 and "contpc" or "ftsz" + s = k == 0 ? "NULL" : format("[0x%08x]", k) + elseif (sn or 0) & 0x30000 != 0 then + s = sn & 0x20000 != 0 ? "contpc" : "ftsz" elseif k == 2^52+2^51 then s = "bias" else - s = format(0 < k and k < 0x1p-1026 and "%+a" or "%+.14g", k) + s = format(0 < k and k < 0x1p-1026 ? "%+a" : "%+.14g", k) end elseif tn == "string" then - s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub)) + s = format(#k > 20 ? '"%.20s"~' : '"%s"', gsub(k, "%c", ctlsub)) elseif tn == "function" then s = fmtfunc(k) elseif tn == "table" then @@ -348,13 +348,13 @@ local function formatk(tr, idx, sn) end elseif t == 21 then -- int64_t s = sub(tostring(k), 1, -3) - if sub(s, 1, 1) ~= "-" then s = "+"..s end + if sub(s, 1, 1) != "-" then s = "+"..s end elseif sn == 0x1057fff then -- SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL) return "----" -- Special case for LJ_FR2 slot 1. else s = tostring(k) -- For primitives. end - s = colorize(format("%-4s", s), t, band(sn or 0, 0x100000) ~= 0) + s = colorize(format("%-4s", s), t, (sn or 0) & 0x100000 != 0) if slot then s = format("%s @%d", s, slot) end @@ -365,18 +365,18 @@ local function printsnap(tr, snap) local n = 2 for s=0,snap[1]-1 do local sn = snap[n] - if shr(sn, 24) == s then - n = n + 1 - local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS + if sn >> 24 == s then + n += 1 + local ref = (sn & 0xffff) - 0x8000 -- REF_BIAS if ref < 0 then out:write(formatk(tr, ref, sn)) - elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM + elseif sn & 0x80000 != 0 then -- SNAP_SOFTFPNUM out:write(colorize(format("%04d/%04d", ref, ref+1), 14)) else local m, ot, op1, op2 = traceir(tr, ref) - out:write(colorize(format("%04d", ref), band(ot, 31), band(sn, 0x100000) ~= 0)) + out:write(colorize(format("%04d", ref), ot & 31, sn & 0x100000 != 0)) end - out:write(band(sn, 0x10000) == 0 and " " or "|") -- SNAP_FRAME + out:write(sn & 0x10000 == 0 ? " " : "|") -- SNAP_FRAME else out:write("---- ") end @@ -398,9 +398,9 @@ end -- Return a register name or stack slot for a rid/sp location. local function ridsp_name(ridsp, ins) if not disass then disass = require("jit.dis_"..jit.arch) end - local rid, slot = band(ridsp, 0xff), shr(ridsp, 8) + local rid, slot = ridsp & 0xff, ridsp >> 8 if rid == 253 or rid == 254 then - return (slot == 0 or slot == 255) and " {sink" or format(" {%04d", ins-slot) + return (slot == 0 or slot == 255) ? " {sink" : format(" {%04d", ins-slot) end if ridsp > 255 then return format("[%x]", slot*4) end if rid < 128 then return disass.regname(rid) end @@ -412,7 +412,7 @@ local function dumpcallfunc(tr, ins) local ctype if ins > 0 then local m, ot, op1, op2 = traceir(tr, ins) - if band(ot, 31) == 0 then -- nil type means CARG(func, ctype). + if ot & 31 == 0 then -- nil type means CARG(func, ctype). ins = op1 ctype = formatk(tr, op2) end @@ -431,7 +431,7 @@ local function dumpcallargs(tr, ins) out:write(formatk(tr, ins)) else local m, ot, op1, op2 = traceir(tr, ins) - local oidx = 6*shr(ot, 8) + local oidx = 6 * (ot >> 8) local op = sub(vmdef.irnames, oidx+1, oidx+6) if op == "CARG " then dumpcallargs(tr, op1) @@ -468,12 +468,12 @@ local function dump_ir(tr, dumpsnap, dumpreg) out:write(format(".... SNAP #%-3d [ ", snapno)) end printsnap(tr, snap) - snapno = snapno + 1 + snapno += 1 snap = tracesnap(tr, snapno) - snapref = snap and snap[0] or 65536 + snapref = snap ? snap[0] : 65536 end local m, ot, op1, op2, ridsp = traceir(tr, ins) - local oidx, t = 6*shr(ot, 8), band(ot, 31) + local oidx, t = 6 * (ot >> 8), ot & 31 local op = sub(irnames, oidx+1, oidx+6) if op == "LOOP " then if dumpreg then @@ -481,45 +481,45 @@ local function dump_ir(tr, dumpsnap, dumpreg) else out:write(format("%04d ------ LOOP ------------\n", ins)) end - elseif op ~= "NOP " and op ~= "CARG " and - (dumpreg or op ~= "RENAME") then - local rid = band(ridsp, 255) + elseif op != "NOP " and op != "CARG " and + (dumpreg or op != "RENAME") then + local rid = ridsp & 255 if dumpreg then out:write(format("%04d %-6s", ins, ridsp_name(ridsp, ins))) else out:write(format("%04d ", ins)) end out:write(format("%s%s %s %s ", - (rid == 254 or rid == 253) and "}" or - (band(ot, 128) == 0 and " " or ">"), - band(ot, 64) == 0 and " " or "+", + rid == 254 or rid == 253 ? "}" : + ot & 128 == 0 ? " " : ">", + ot & 64 == 0 ? " " : "+", irtype[t], op)) - local m1, m2 = band(m, 3), band(m, 3*4) + local m1, m2 = m & 3, m & (3 << 2) if sub(op, 1, 4) == "CALL" then local ctype - if m2 == 1*4 then -- op2 == IRMlit + if m2 == 1 << 2 then -- op2 == IRMlit out:write(format("%-10s (", vmdef.ircall[op2])) else ctype = dumpcallfunc(tr, op2) end - if op1 ~= -1 then dumpcallargs(tr, op1) end + if op1 != -1 then dumpcallargs(tr, op1) end out:write(")") if ctype then out:write(" ctype ", ctype) end elseif op == "CNEW " and op2 == -1 then out:write(formatk(tr, op1)) - elseif m1 ~= 3 then -- op1 != IRMnone + elseif m1 != 3 then -- op1 != IRMnone if op1 < 0 then out:write(formatk(tr, op1)) else - out:write(format(m1 == 0 and "%04d" or "#%-3d", op1)) + out:write(format(m1 == 0 ? "%04d" : "#%-3d", op1)) end - if m2 ~= 3*4 then -- op2 != IRMnone - if m2 == 1*4 then -- op2 == IRMlit + if m2 != 3 << 2 then -- op2 != IRMnone + if m2 == 1 << 2 then -- op2 == IRMlit local litn = litname[op] if litn and litn[op2] then out:write(" ", litn[op2]) elseif op == "UREFO " or op == "UREFC " then - out:write(format(" #%-3d", shr(op2, 8))) + out:write(format(" #%-3d", op2 >> 8)) else out:write(format(" #%-3d", op2)) end @@ -572,7 +572,7 @@ local function dump_trace(what, tr, func, pc, otr, oex) if what == "start" then if dumpmode.H then out:write('
\n') end
     out:write("---- TRACE ", tr, " ", what)
-    if otr then out:write(" ", otr, "/", oex == -1 and "stitch" or oex) end
+    if otr then out:write(" ", otr, "/", oex == -1 ? "stitch" : oex) end
     out:write(" ", fmtfunc(func, pc), "\n")
   elseif what == "stop" or what == "abort" then
     out:write("---- TRACE ", tr, " ", what)
@@ -599,7 +599,7 @@ end
 
 -- Dump recorded bytecode.
 local function dump_record(tr, func, pc, depth)
-  if depth ~= recdepth then
+  if depth != recdepth then
     recdepth = depth
     recprefix = rep(" .", depth)
   end
@@ -615,7 +615,7 @@ local function dump_record(tr, func, pc, depth)
   else
     out:write(line)
   end
-  if pc >= 0 and band(funcbc(func, pc), 0xff) < 16 then -- ORDER BC
+  if pc >= 0 and funcbc(func, pc) & 0xff < 16 then -- ORDER BC
     out:write(bcline(func, pc+1, recprefix)) -- Write JMP for cond.
   end
 end
@@ -664,7 +664,7 @@ local function dumpoff()
     jit.attach(dump_texit)
     jit.attach(dump_record)
     jit.attach(dump_trace)
-    if out and out ~= stdout and out ~= stderr then out:close() end
+    if out and out != stdout and out != stderr then out:close() end
     out = nil
   end
 end
@@ -674,16 +674,16 @@ local function dumpon(opt, outfile)
   if active then dumpoff() end
 
   local term = os.getenv("TERM")
-  local colormode = (term and term:match("color") or os.getenv("COLORTERM")) and "A" or "T"
+  local colormode = (term ? (term:match("color")) : os.getenv("COLORTERM")) ? "A" : "T"
   if opt then
     opt = gsub(opt, "[TAH]", function(mode) colormode = mode; return ""; end)
   end
 
   local m = { t=true, b=true, i=true, m=true, }
-  if opt and opt ~= "" then
+  if opt and opt != "" then
     local o = sub(opt, 1, 1)
-    if o ~= "+" and o ~= "-" then m = {} end
-    for i=1,#opt do m[sub(opt, i, i)] = (o ~= "-") end
+    if o != "+" and o != "-" then m = {} end
+    for i=1,#opt do m[sub(opt, i, i)] = (o != "-") end
   end
   dumpmode = m
 
@@ -700,7 +700,7 @@ local function dumpon(opt, outfile)
 
   if not outfile then outfile = os.getenv("LUAJIT_DUMPFILE") end
   if outfile then
-    out = outfile == "-" and stdout or assert(io.open(outfile, "w"))
+    out = outfile == "-" ? stdout : assert(io.open(outfile, "w"))
   else
     out = stdout
   end
-- 
cgit v1.2.3-55-g6feb