Skip to content

Commit 9f6ec7f

Browse files
committed
feature: luajit -bl: dump the constant tables (KGC and KN) for each lua proto object as well.
1 parent 83c82b5 commit 9f6ec7f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Table of Contents
1818
* [New JIT parameter defaults](#new-jit-parameter-defaults)
1919
* [String table hashing optimization](#string-table-hashing-optimization)
2020
* [New command-line option `-bL`](#new-command-line-option--bl)
21+
* [More detailed LuaJIT bytecode textual listing](#more-detailed-luajit-bytecode-textual-listing)
2122
* [New macros](#new-macros)
2223
* [Miscellaneous](#miscellaneous)
2324
* [Copyright & License](#copyright--license)
@@ -200,6 +201,24 @@ the first source line.
200201

201202
[Back to TOC](#table-of-contents)
202203

204+
## More detailed LuaJIT bytecode textual listing
205+
206+
The `-bl` option also prints out the constant tables of each Lua prototype.
207+
For example,
208+
209+
```
210+
-- BYTECODE -- a.lua:0-48
211+
KGC 0 "print"
212+
KGC 1 "hi"
213+
KGC 2 table
214+
KGC 3 a.lua:17
215+
KN 1 1000000
216+
KN 2 1.390671161567e-309
217+
...
218+
```
219+
220+
[Back to TOC](#table-of-contents)
221+
203222
## New macros
204223

205224
In the header file `luajit.h`, we defined the macro `OPENRESTY_LUAJIT` for our branch of

src/jit/bc.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,38 @@ local function bcdump(func, out, all, lineinfo)
141141
end
142142
end
143143
out:write(format("-- BYTECODE -- %s-%d\n", fi.loc, fi.lastlinedefined))
144+
145+
for n=-1,-1000000000,-1 do
146+
local kc = funck(func, n)
147+
if not kc then break end
148+
149+
local typ = type(kc)
150+
if typ == "string" then
151+
kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub))
152+
out:write(format("KGC %d %s\n", -(n + 1), kc))
153+
elseif typ == "proto" then
154+
local fi = funcinfo(kc)
155+
if fi.ffid then
156+
kc = vmdef.ffnames[fi.ffid]
157+
else
158+
kc = fi.loc
159+
end
160+
out:write(format("KGC %d %s\n", -(n + 1), kc))
161+
elseif typ == "table" then
162+
out:write(format("KGC %d table\n", -(n + 1)))
163+
else
164+
-- error("unknown KGC type: " .. typ)
165+
end
166+
end
167+
168+
for n=1,1000000000 do
169+
local kc = funck(func, n)
170+
if not kc then break end
171+
if type(kc) == "number" then
172+
out:write(format("KN %d %s\n", n, kc))
173+
end
174+
end
175+
144176
local target = bctargets(func)
145177
for pc=1,1000000000 do
146178
local s = bcline(func, pc, target[pc] and "=>", lineinfo)

0 commit comments

Comments
 (0)