From 4aca8bb8df8110a8f2cff7d7a7c6b82ae0a25430 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 21 Feb 2021 22:09:49 +0100 Subject: [PATCH] also track subroutines in the callgraph that only get their address taken --- compiler/src/prog8/optimizer/CallGraph.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/src/prog8/optimizer/CallGraph.kt b/compiler/src/prog8/optimizer/CallGraph.kt index af41345b1..00f2b9c27 100644 --- a/compiler/src/prog8/optimizer/CallGraph.kt +++ b/compiler/src/prog8/optimizer/CallGraph.kt @@ -7,6 +7,7 @@ import prog8.ast.Program import prog8.ast.base.DataType import prog8.ast.base.ParentSentinel import prog8.ast.base.Position +import prog8.ast.expressions.AddressOf import prog8.ast.expressions.FunctionCall import prog8.ast.expressions.IdentifierReference import prog8.ast.statements.* @@ -150,6 +151,17 @@ class CallGraph(private val program: Program, private val asmFileLoader: (filena super.visit(functionCallStatement) } + override fun visit(addressOf: AddressOf) { + val otherSub = addressOf.identifier.targetSubroutine(program) + if(otherSub!=null) { + addressOf.definingSubroutine()?.let { thisSub -> + calls[thisSub] = calls.getValue(thisSub).plus(otherSub) + calledBy[otherSub] = calledBy.getValue(otherSub).plus(thisSub) + } + } + super.visit(addressOf) + } + override fun visit(jump: Jump) { val otherSub = jump.identifier?.targetSubroutine(program) if (otherSub != null) {