diff options
Diffstat (limited to 'src/jit/bc.lua')
| -rw-r--r-- | src/jit/bc.lua | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/jit/bc.lua b/src/jit/bc.lua index 8014d6029..59bc35b83 100644 --- a/src/jit/bc.lua +++ b/src/jit/bc.lua | |||
| @@ -43,9 +43,8 @@ | |||
| 43 | local jit = require("jit") | 43 | local jit = require("jit") |
| 44 | local jutil = require("jit.util") | 44 | local jutil = require("jit.util") |
| 45 | local vmdef = require("jit.vmdef") | 45 | local vmdef = require("jit.vmdef") |
| 46 | local bit = require("bit") | ||
| 47 | local sub, gsub, format = string.sub, string.gsub, string.format | 46 | local sub, gsub, format = string.sub, string.gsub, string.format |
| 48 | local byte, band, shr = string.byte, bit.band, bit.rshift | 47 | local byte = string.byte |
| 49 | local funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck | 48 | local funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck |
| 50 | local funcuvname = jutil.funcuvname | 49 | local funcuvname = jutil.funcuvname |
| 51 | local bcnames = vmdef.bcnames | 50 | local bcnames = vmdef.bcnames |
| @@ -65,49 +64,49 @@ end | |||
| 65 | local function bcline(func, pc, prefix) | 64 | local function bcline(func, pc, prefix) |
| 66 | local ins, m = funcbc(func, pc) | 65 | local ins, m = funcbc(func, pc) |
| 67 | if not ins then return end | 66 | if not ins then return end |
| 68 | local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128) | 67 | local ma, mb, mc = m & 7, (m >> 3) & 15, (m >> 7) & 15 |
| 69 | local a = band(shr(ins, 8), 0xff) | 68 | local a = (ins >> 8) & 0xff |
| 70 | local oidx = 6*band(ins, 0xff) | 69 | local oidx = 6 * (ins & 0xff) |
| 71 | local op = sub(bcnames, oidx+1, oidx+6) | 70 | local op = sub(bcnames, oidx+1, oidx+6) |
| 72 | local s = format("%04d %s %-6s %3s ", | 71 | local s = format("%04d %s %-6s %3s ", |
| 73 | pc, prefix or " ", op, ma == 0 and "" or a) | 72 | pc, prefix or " ", op, ma == 0 ? "" : a) |
| 74 | local d = shr(ins, 16) | 73 | local d = ins >> 16 |
| 75 | if mc == 13*128 then -- BCMjump | 74 | if mc == 13 then -- BCMjump |
| 76 | return format("%s=> %04d\n", s, pc+d-0x7fff) | 75 | return format("%s=> %04d\n", s, pc+d-0x7fff) |
| 77 | end | 76 | end |
| 78 | if mb ~= 0 then | 77 | if mb != 0 then |
| 79 | d = band(d, 0xff) | 78 | d &= 0xff |
| 80 | elseif mc == 0 then | 79 | elseif mc == 0 then |
| 81 | return s.."\n" | 80 | return s.."\n" |
| 82 | end | 81 | end |
| 83 | local kc | 82 | local kc |
| 84 | if mc == 10*128 then -- BCMstr | 83 | if mc == 10 then -- BCMstr |
| 85 | kc = funck(func, -d-1) | 84 | kc = funck(func, -d-1) |
| 86 | kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub)) | 85 | kc = format(#kc > 40 ? '"%.40s"~' : '"%s"', gsub(kc, "%c", ctlsub)) |
| 87 | elseif mc == 9*128 then -- BCMnum | 86 | elseif mc == 9 then -- BCMnum |
| 88 | kc = funck(func, d) | 87 | kc = funck(func, d) |
| 89 | if op == "TSETM " then kc = kc - 2^52 end | 88 | if op == "TSETM " then kc -= 2^52 end |
| 90 | elseif mc == 12*128 then -- BCMfunc | 89 | elseif mc == 12 then -- BCMfunc |
| 91 | local fi = funcinfo(funck(func, -d-1)) | 90 | local fi = funcinfo(funck(func, -d-1)) |
| 92 | if fi.ffid then | 91 | if fi.ffid then |
| 93 | kc = vmdef.ffnames[fi.ffid] | 92 | kc = vmdef.ffnames[fi.ffid] |
| 94 | else | 93 | else |
| 95 | kc = fi.loc | 94 | kc = fi.loc |
| 96 | end | 95 | end |
| 97 | elseif mc == 5*128 then -- BCMuv | 96 | elseif mc == 5 then -- BCMuv |
| 98 | kc = funcuvname(func, d) | 97 | kc = funcuvname(func, d) |
| 99 | end | 98 | end |
| 100 | if ma == 5 then -- BCMuv | 99 | if ma == 5 then -- BCMuv |
| 101 | local ka = funcuvname(func, a) | 100 | local ka = funcuvname(func, a) |
| 102 | if kc then kc = ka.." ; "..kc else kc = ka end | 101 | if kc then kc = ka.." ; "..kc else kc = ka end |
| 103 | end | 102 | end |
| 104 | if mb ~= 0 then | 103 | if mb != 0 then |
| 105 | local b = shr(ins, 24) | 104 | local b = ins >> 24 |
| 106 | if kc then return format("%s%3d %3d ; %s\n", s, b, d, kc) end | 105 | if kc then return format("%s%3d %3d ; %s\n", s, b, d, kc) end |
| 107 | return format("%s%3d %3d\n", s, b, d) | 106 | return format("%s%3d %3d\n", s, b, d) |
| 108 | end | 107 | end |
| 109 | if kc then return format("%s%3d ; %s\n", s, d, kc) end | 108 | if kc then return format("%s%3d ; %s\n", s, d, kc) end |
| 110 | if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits | 109 | if mc == 7 and d > 32767 then d -= 65536 end -- BCMlits |
| 111 | return format("%s%3d\n", s, d) | 110 | return format("%s%3d\n", s, d) |
| 112 | end | 111 | end |
| 113 | 112 | ||
| @@ -117,7 +116,7 @@ local function bctargets(func) | |||
| 117 | for pc=1,1000000000 do | 116 | for pc=1,1000000000 do |
| 118 | local ins, m = funcbc(func, pc) | 117 | local ins, m = funcbc(func, pc) |
| 119 | if not ins then break end | 118 | if not ins then break end |
| 120 | if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end | 119 | if m & (15 << 7) == (13 << 7) then target[pc+(ins >> 16)-0x7fff] = true end |
| 121 | end | 120 | end |
| 122 | return target | 121 | return target |
| 123 | end | 122 | end |
| @@ -159,7 +158,7 @@ local function bclistoff() | |||
| 159 | if active then | 158 | if active then |
| 160 | active = false | 159 | active = false |
| 161 | jit.attach(h_list) | 160 | jit.attach(h_list) |
| 162 | if out and out ~= stdout and out ~= stderr then out:close() end | 161 | if out and out != stdout and out != stderr then out:close() end |
| 163 | out = nil | 162 | out = nil |
| 164 | end | 163 | end |
| 165 | end | 164 | end |
| @@ -169,7 +168,7 @@ local function bcliston(outfile) | |||
| 169 | if active then bclistoff() end | 168 | if active then bclistoff() end |
| 170 | if not outfile then outfile = os.getenv("LUAJIT_LISTFILE") end | 169 | if not outfile then outfile = os.getenv("LUAJIT_LISTFILE") end |
| 171 | if outfile then | 170 | if outfile then |
| 172 | out = outfile == "-" and stdout or assert(io.open(outfile, "w")) | 171 | out = outfile == "-" ? stdout : assert(io.open(outfile, "w")) |
| 173 | else | 172 | else |
| 174 | out = stderr | 173 | out = stderr |
| 175 | end | 174 | end |
