From 2f62271453c0d8bb4b8bde763594c8e3ce8099dc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 5 Apr 2021 00:55:27 +0200 Subject: [PATCH] callgraph --- compiler/src/prog8/optimizer/CallGraph.kt | 33 ++++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/compiler/src/prog8/optimizer/CallGraph.kt b/compiler/src/prog8/optimizer/CallGraph.kt index c58895c8c..e9766d609 100644 --- a/compiler/src/prog8/optimizer/CallGraph.kt +++ b/compiler/src/prog8/optimizer/CallGraph.kt @@ -200,13 +200,32 @@ class CallGraph(private val program: Program, private val asmFileLoader: (filena return false } - fun unused(stmt: ISymbolStatement): Boolean { - if(stmt is Subroutine) - return calledBy[stmt].isNullOrEmpty() // TODO also check inline assembly if it uses the subroutine + fun unused(sub: Subroutine): Boolean { + return calledBy[sub].isNullOrEmpty() // TODO also check inline assembly if it uses the subroutine + } - // TODO implement algorithm to check usages of other things: - // stmt can be: Block, Label, VarDecl (including ParameterVarDecl), Subroutine, StructDecl. - // NOTE also check inline assembly blocks that may reference a name. - return false + fun unused(block: Block): Boolean { + return false // TODO implement unused check for Block, also check inline asm + } + + fun unused(decl: VarDecl): Boolean { + return false // TODO implement unused check for vardecls, also check inline asm + } + + fun unused(struct: StructDecl): Boolean { + return false // TODO implement unused check for struct decls, also check inline asm + } + + inline fun unused(label: Label) = false // just always output labels + + fun unused(stmt: ISymbolStatement): Boolean { + return when(stmt) { + is Subroutine -> unused(stmt) + is Block -> unused(stmt) + is VarDecl -> unused(stmt) + is Label -> false // just always output labels + is StructDecl -> unused(stmt) + else -> false + } } }