-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHook.lua
69 lines (56 loc) · 1.8 KB
/
Hook.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--[[
This module contains the implementation of the hook
which will be used to extract the types from function calls
--]]
require "Function"
function printInfo(info)
for k,v in pairs(info) do print(k,v) end
end
local fstack = { }
--[[ Because lua tail-call elimination
some calls won't have the equivalent "return" event
on the stack. For this reason, we assign the tail call
return type for each consecutive tail call on the stack
until the call event that generated de tail call
--]]
-- Push function information on fstack
local function push(info)
return table.insert(fstack, info)
end
-- Pop function information from fstack
local function pop()
return table.remove(fstack)
end
-- Hook function used to extract local value types from functions
function hook(event)
local info = debug.getinfo(2,"frt")
local names
if Names[info.func] == nil then
names = debug.getinfo(2,"Sn")
Names[info.func] = names
end
--[[ Functions defined in [C] won't have it place in table
'Functions' even if it was called sometime inside the
program.
--]]
if Names[info.func].what == "Lua" then
if event == "call" or event == "tail call" then
-- Update function count
updateCount(info.func)
-- push function information
push(info)
-- update function parameter types
updateParameter(info.func, info.ftransfer, info.ntransfer)
elseif event == "return" then
-- Pop function information from stack
local p = pop()
-- update poped function result types
updateResult(p.func, info.ftransfer, info.ntransfer)
-- update consecutive tail calls with current result information
while p.istailcall do
p = pop()
updateResult(p.func, info.ftransfer, info.ntransfer)
end
end
end
end