Class diagram drawn in umbrello (detail was removed for visibility).
[avr-sim.git] / analyzers / callgraph.lua
blob9c2a6c2d0864e03c9ffda7dfd83aacc0ffa76c6c
1 function this.listcalls(this)
2 table.foreach( this.functions, function(key, value)
3 print( string.format("%.4x", key) )
4 table.foreach(value, print)
5 end)
6 end
8 function this.addcall(this, address, functionname)
9 table.insert( this.stack, address )
11 if( this.functions[ address ] == nil ) then
12 this.functions[address] = {
13 name = functionname,
14 calls = 1,
15 start = this.ticks,
16 maxlength = 0,
17 frequency = 0
19 else
20 f = this.functions[address]
21 f.frequency = ((f.frequency * (f.calls - 1)) + (this.ticks - f.start)) / f.calls
22 f.calls = f.calls + 1
23 f.start = this.ticks
24 end
25 end
27 function this.endcall(this)
28 address = table.remove( this.stack )
30 f = this.functions[address]
31 if( f ~= nil ) then
32 len = this.ticks - f.start
33 if( len > f.maxlength ) then
34 f.maxlength = len
35 end
36 end
37 end
39 function this.finish(this)
40 this:listcalls()
41 end
43 function this.call(this, address, push)
44 if( push ) then
45 -- print( "Call ", string.format("%.4x", address), " ", Program:functionName(address) )
46 this:addcall(address, Program:functionName(address) )
47 end
48 end
50 function this.interrupt(this, vector, address)
51 -- print( "Int ", string.format("%.2d %.4x", vector, address) )
52 this:addcall( address, string.format("vector_%.2d", vector) )
53 end
55 function this.ret(this, interrupt)
56 this:endcall()
57 --[[
58 if( interrupt ) then
59 print("Reti")
60 else
61 print("Ret")
62 end
63 --]]
64 end
66 this.functions = {}
67 this.stack = {}