Skip to content

Commit 245fa43

Browse files
committedSep 19, 2021
Added support for invoke instruction. By Nandu
1 parent 597bb14 commit 245fa43

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed
 

‎code/ABF/parseTrace.lua

+36-13
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,29 @@ local function idSuccPred(trace)
187187
elseif terminator.name == "indirectbr" then
188188
error("Terminator instruction " .. terminator.name .. " not yet implemented")
189189
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
190202
error("Terminator instruction " .. terminator.name .. " not yet implemented")
191203
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")
193209
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")
195213
else
196214
error("Unknown terminator instruction " .. terminator.name .. " for the basic-block " .. bb.name .. " in function " .. fun.name .. " in module " .. mod.name)
197215
end
@@ -289,15 +307,15 @@ local function getFunctionEntries(trace, C)
289307
if fun.definition then
290308
for bbNum,bb in ipairs(fun.BasicBlocks) do --Examine all basic-blocks; 1 equation for each BB
291309
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
293311
local operands = inst.Operands
294312
local targetFunString = operands[#operands]
295-
local targetFunName = targetFunString:split("<@")[1]:split(":")[2]:strip()
313+
local targetFunName = targetFunString:split("<@")[1]:split(" : ")[2]:strip()
296314
local targetFunNum = mod["-FunctionTable"][targetFunName]
297315
local target = mod.Functions[targetFunNum]
298316

299317
--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
301319
--print(modNum .. "_" .. funNum .. "_" .. bbNum .. ": Call[" .. targetFunName .. "]")
302320
if not modC[targetFunName]["-Entry"] then modC[targetFunName]["-Entry"] = {} end
303321
local E = modC[targetFunName]["-Entry"]
@@ -633,18 +651,23 @@ local function countBasicBlockOps(trace)
633651
name = inst.name .. ":" .. vectorWidth .. ":" .. typeName
634652
end
635653

636-
if inst.name == "call" then
654+
if inst.name == "call" or inst.name == "invoke" then
637655
local operands = inst.Operands
638656
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)
641660
local targetFunNum = mod["-FunctionTable"][targetFunName]
642661
local target = mod.Functions[targetFunNum]
643662

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")
648671
end
649672
elseif inst.name == "br" then
650673
local ops = inst.Operands
@@ -675,7 +698,7 @@ local pureMode = true
675698
local trace = parseTrace(arg[1])
676699

677700
local opCount = countBasicBlockOps(trace)
678-
print(inspect(opCount, false, 10))
701+
--print(inspect(opCount, false, 10))
679702

680703
idSuccPred(trace)
681704
--print(inspect(trace, false, 10))

0 commit comments

Comments
 (0)
Please sign in to comment.