@@ -187,11 +187,29 @@ local function idSuccPred(trace)
187
187
elseif terminator .name == " indirectbr" then
188
188
error (" Terminator instruction " .. terminator .name .. " not yet implemented" )
189
189
elseif terminator .name == " switch" then
190
+ local ops = terminator .Operands
191
+ -- print("switch", inspect(ops))
192
+ sucs [" default" ] = fun .BasicBlockTable [ops [2 ]:split (" <@" )[1 ]:split (" :" )[2 ]:strip ()]
193
+ for i = 3 ,# ops ,2 do
194
+ local valTable = ops [i ]:split (" <@" )[1 ]:split (" " )
195
+ local val = valTable [# valTable ]:strip ()
196
+ -- print(ops[i], val)
197
+ sucs [val ] = fun .BasicBlockTable [ops [i + 1 ]:split (" <@" )[1 ]:split (" :" )[2 ]:strip ()]
198
+ -- print(ops[i+1], sucs[val])
199
+ end
200
+ -- error("Terminator instruction " .. terminator.name .. " not yet implemented")
201
+ elseif terminator .name == " catchswitch" then
190
202
error (" Terminator instruction " .. terminator .name .. " not yet implemented" )
191
203
elseif terminator .name == " invoke" then
192
- error (" Terminator instruction " .. terminator .name .. " not yet implemented" )
204
+ local ops = terminator .Operands
205
+ -- print("invoke", inspect(ops))
206
+ sucs [" normal" ] = fun .BasicBlockTable [ops [2 ]:split (" <@" )[1 ]:split (" :" )[2 ]:strip ()]
207
+ sucs [" except" ] = fun .BasicBlockTable [ops [3 ]:split (" <@" )[1 ]:split (" :" )[2 ]:strip ()] -- unwind
208
+ -- error("Terminator instruction " .. terminator.name .. " not yet implemented")
193
209
elseif terminator .name == " resume" then
194
- error (" Terminator instruction " .. terminator .name .. " not yet implemented" )
210
+ -- print("resume", inspect(ops))
211
+ sucs [" resume" ] = fun .name
212
+ -- error("Terminator instruction " .. terminator.name .. " not yet implemented")
195
213
else
196
214
error (" Unknown terminator instruction " .. terminator .name .. " for the basic-block " .. bb .name .. " in function " .. fun .name .. " in module " .. mod .name )
197
215
end
@@ -289,15 +307,15 @@ local function getFunctionEntries(trace, C)
289
307
if fun .definition then
290
308
for bbNum ,bb in ipairs (fun .BasicBlocks ) do -- Examine all basic-blocks; 1 equation for each BB
291
309
for instNum ,inst in ipairs (bb .Instructions ) do -- Examine all instructions for 'call's
292
- if inst .name == " call" then
310
+ if inst .name == " call" or inst . name == " invoke " then
293
311
local operands = inst .Operands
294
312
local targetFunString = operands [# operands ]
295
- local targetFunName = targetFunString :split (" <@" )[1 ]:split (" : " )[2 ]:strip ()
313
+ local targetFunName = targetFunString :split (" <@" )[1 ]:split (" : " )[2 ]:strip ()
296
314
local targetFunNum = mod [" -FunctionTable" ][targetFunName ]
297
315
local target = mod .Functions [targetFunNum ]
298
316
299
317
-- print("Calling: " .. targetFunName .. " (" .. (target.definition and "Defined" or "Declared") .. ", " .. (target.intrinsic and "Intrinsic" or "Extrinsic") .. ")")
300
- if (target .definition and not target .intrinsic ) then
318
+ if (target and target .definition and not target .intrinsic ) then
301
319
-- print(modNum .. "_" .. funNum .. "_" .. bbNum .. ": Call[" .. targetFunName .. "]")
302
320
if not modC [targetFunName ][" -Entry" ] then modC [targetFunName ][" -Entry" ] = {} end
303
321
local E = modC [targetFunName ][" -Entry" ]
@@ -633,18 +651,23 @@ local function countBasicBlockOps(trace)
633
651
name = inst .name .. " :" .. vectorWidth .. " :" .. typeName
634
652
end
635
653
636
- if inst .name == " call" then
654
+ if inst .name == " call" or inst . name == " invoke " then
637
655
local operands = inst .Operands
638
656
local targetFunString = operands [# operands ]
639
- -- print(inspect(operands), targetFunString)
640
- local targetFunName = targetFunString :split (" <@" )[1 ]:split (" :" )[2 ]:strip ()
657
+ -- print(inspect(operands), "\n", targetFunString, "\n")
658
+ local targetFunName = targetFunString :split (" <@" )[1 ]:split (" : " )[2 ]:strip ()
659
+ -- print(targetFunName)
641
660
local targetFunNum = mod [" -FunctionTable" ][targetFunName ]
642
661
local target = mod .Functions [targetFunNum ]
643
662
644
- -- print("Calling: " .. targetFunName .. " (" .. (target.definition and "Defined" or "Declared") .. ", " .. (target.intrinsic and "Intrinsic" or "Extrinsic") .. ")")
645
- if (target .definition and not target .intrinsic ) then
646
- bbOpCount [" call" ] = (bbOpCount [" call" ] or 0 ) + 1
647
- bbOpCount [" TOTAL" ] = bbOpCount [" TOTAL" ] + 1
663
+ if (target ) then
664
+ print (" Calling: " .. targetFunName .. " (" .. (target .definition and " Defined" or " Declared" ) .. " , " .. (target .intrinsic and " Intrinsic" or " Extrinsic" ) .. " )" )
665
+ if (target .definition and not target .intrinsic ) then
666
+ bbOpCount [inst .name ] = (bbOpCount [inst .name ] or 0 ) + 1
667
+ bbOpCount [" TOTAL" ] = bbOpCount [" TOTAL" ] + 1
668
+ end
669
+ else
670
+ print (" Calling: " .. targetFunName .. " which is undefined in the trace file" )
648
671
end
649
672
elseif inst .name == " br" then
650
673
local ops = inst .Operands
@@ -675,7 +698,7 @@ local pureMode = true
675
698
local trace = parseTrace (arg [1 ])
676
699
677
700
local opCount = countBasicBlockOps (trace )
678
- print (inspect (opCount , false , 10 ))
701
+ -- print(inspect(opCount, false, 10))
679
702
680
703
idSuccPred (trace )
681
704
-- print(inspect(trace, false, 10))
0 commit comments