From 580d19299e8fd42741fc87f3b93e281e3a8d7285 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Thu, 22 Aug 2024 09:16:03 -0700 Subject: [PATCH] Update README --- README.md | 12 ++++++++++++ .../dev/romainguy/kotlin/explorer/KotlinExplorer.kt | 2 +- .../kotlin/dev/romainguy/kotlin/explorer/State.kt | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4fc45bf..20b34b0c 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,18 @@ which panels are visible using the *View* menu. - Shows the number of instructions and branches per method. - Click a disassembled instruction or register to highlight all occurrences. +# Kotlin Explorer and R8 + +You can use *Build > Optimize with R8* to optimize the compiled code with the R8 tool. +By default, all public classes/members/etc. will be kept, allowing you to analyze them +in the disassembly panels. + +However, keeping everything is not representative of what R8 will do on an actual +application so you can disable that feature, and instead use the `@Keep` annotation +to choose an entry point leading to the desired disassembly. You can also create a +`fun main()` entry point and call your code from there. Be careful to not use constants +when calling other methods as this may lead to aggressive optimization by R8. + # Running Kotlin Explorer Run Kotlin Explorer with `./gradlew jvmRun`. diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt index ece3ce9d..1cabdb95 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt @@ -510,7 +510,7 @@ private fun FrameWindowScope.MainMenu( ) Separator() MenuCheckboxItem("Optimize with R8", CtrlShift(O), explorerState::optimize) - MenuCheckboxItem("Keep everything", CtrlShift(K), explorerState::keepEverything) + MenuCheckboxItem("Keep Everything", CtrlShift(K), explorerState::keepEverything) MenuCheckboxItem("Build on Startup", shortcut = null, explorerState::autoBuildOnStartup) MenuItem( "Build & Disassemble", diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/State.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/State.kt index 78f7a8c2..c54e1628 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/State.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/State.kt @@ -154,7 +154,7 @@ private fun readSourceCode(toolPaths: ToolPaths) = if (toolPaths.sourceFile.exis Files.readString(toolPaths.sourceFile) } else { """ - // NOTE: If Build > Keep everything is *not* checked, used the @Keep + // NOTE: If Build > Keep Everything is *not* checked, used the @Keep // annotation to keep the classes/methods/etc. you want to disassemble fun square(a: Int): Int { return a * a