Read all the GCproto in a bytecode serialization by skipping
This commit is contained in:
parent
e76d2cb187
commit
0d88291fde
|
|
@ -3,20 +3,24 @@ local opcodes = require('opcodes')
|
||||||
|
|
||||||
local function inspect_proto(proto)
|
local function inspect_proto(proto)
|
||||||
print('\n-- proto --')
|
print('\n-- proto --')
|
||||||
-- print('Debug: ' .. proto.debug)
|
|
||||||
print('Params: ' .. proto.numparams)
|
print('Params: ' .. proto.numparams)
|
||||||
print('Frame Size: ' .. proto.framesize)
|
print('Frame Size: ' .. proto.framesize)
|
||||||
print('#Upvalues: ' .. proto.numuv)
|
print('#instructions: ' .. proto.numbc)
|
||||||
print('#kgc: ' .. proto.numkgc)
|
print('#upvalues: ' .. proto.numuv)
|
||||||
print('#bcins: ' .. proto.numbc)
|
print('#collectable constants: ' .. proto.numkgc)
|
||||||
|
print('#numeric constants: ' .. proto.numkn)
|
||||||
|
|
||||||
|
if proto.debugInfo ~= nil then
|
||||||
|
print('-- bytecode: lines ' .. proto.debugInfo.firstLine .. ' ' .. proto.debugInfo.numLine)
|
||||||
|
else
|
||||||
print('-- bytecode --')
|
print('-- bytecode --')
|
||||||
|
end
|
||||||
for i = 1, #proto.bcins do
|
for i = 1, #proto.bcins do
|
||||||
local decoded = opcodes.decode(proto.bcins[i])
|
local decoded = opcodes.decode(proto.bcins[i])
|
||||||
if opcodes.defs[decoded.id] ~= nil then
|
if opcodes.defs[decoded.id] ~= nil then
|
||||||
local def = opcodes.defs[decoded.id]
|
local def = opcodes.defs[decoded.id]
|
||||||
-- check for ABC or AD format
|
-- check for ABC or AD format
|
||||||
if def.b == opcodes.Mode.none then
|
if def.b ~= opcodes.Mode.none then
|
||||||
print(string.format('%s\t A: %s\tB: %s\t C: %s', def.name, decoded.a, decoded.b, decoded.c))
|
print(string.format('%s\t A: %s\tB: %s\t C: %s', def.name, decoded.a, decoded.b, decoded.c))
|
||||||
else
|
else
|
||||||
print(string.format('%s\t A: %s\tD: %s', def.name, decoded.a, decoded.d))
|
print(string.format('%s\t A: %s\tD: %s', def.name, decoded.a, decoded.d))
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,8 @@ local function read_proto(fp)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local curpos = fp:seek()
|
||||||
|
|
||||||
-- read proto header
|
-- read proto header
|
||||||
local flags = read_u8(fp)
|
local flags = read_u8(fp)
|
||||||
local numparams = read_u8(fp)
|
local numparams = read_u8(fp)
|
||||||
|
|
@ -109,7 +111,6 @@ local function read_proto(fp)
|
||||||
if bit.band(flags, FLAG_STRIP) ~= 0 then
|
if bit.band(flags, FLAG_STRIP) ~= 0 then
|
||||||
debugLen = read_uleb128(fp)
|
debugLen = read_uleb128(fp)
|
||||||
|
|
||||||
-- TODO: is this correct?
|
|
||||||
if debugLen ~= 0 then
|
if debugLen ~= 0 then
|
||||||
local firstLine = read_uleb128(fp)
|
local firstLine = read_uleb128(fp)
|
||||||
local numLine = read_uleb128(fp)
|
local numLine = read_uleb128(fp)
|
||||||
|
|
@ -124,6 +125,10 @@ local function read_proto(fp)
|
||||||
local uvdata = read_u16n(fp, numuv)
|
local uvdata = read_u16n(fp, numuv)
|
||||||
-- local kgc
|
-- local kgc
|
||||||
-- local numkn
|
-- local numkn
|
||||||
|
-- local debug = fp:read(debugLen)
|
||||||
|
|
||||||
|
-- TODO: remove when reading of kgc, numkn and debug is implemented
|
||||||
|
fp:seek('set', curpos + length)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
flags = flags,
|
flags = flags,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
local function b(x)
|
||||||
|
return x+1
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
function b(x)
|
||||||
|
return x
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function c(y)
|
||||||
|
return y
|
||||||
|
end
|
||||||
|
|
||||||
|
return b(1) * c(2)
|
||||||
Loading…
Reference in New Issue