From 4e65cc1882293b7bf59c4cc5b3cabbcb1011fd1f Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sun, 15 Nov 2020 00:32:33 +0100 Subject: [PATCH] switch_jmp is a conditional jump after all. --- .../lib/assembly/dataFlowAnalysis/ControlFlowGraph.kt | 7 +++---- .../world/phantasmal/lib/fileFormats/quest/ByteCode.kt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/commonMain/kotlin/world/phantasmal/lib/assembly/dataFlowAnalysis/ControlFlowGraph.kt b/lib/src/commonMain/kotlin/world/phantasmal/lib/assembly/dataFlowAnalysis/ControlFlowGraph.kt index c815fffc..90b8cad7 100644 --- a/lib/src/commonMain/kotlin/world/phantasmal/lib/assembly/dataFlowAnalysis/ControlFlowGraph.kt +++ b/lib/src/commonMain/kotlin/world/phantasmal/lib/assembly/dataFlowAnalysis/ControlFlowGraph.kt @@ -11,13 +11,12 @@ enum class BranchType { None, /** - * ret + * ret. */ Return, /** - * jmp or switch_jmp. switch_jmp is a non-conditional jump because it always jumps even though - * the jump location is dynamic. + * jmp. */ Jump, @@ -200,7 +199,7 @@ private fun createBasicBlocks(cfg: ControlFlowGraphBuilder, segment: Instruction branchLabels = listOf(inst.args[2].value as Int) } OP_SWITCH_JMP.code -> { - branchType = BranchType.Jump + branchType = BranchType.ConditionalJump branchLabels = inst.args.drop(1).map { it.value as Int } } diff --git a/lib/src/commonMain/kotlin/world/phantasmal/lib/fileFormats/quest/ByteCode.kt b/lib/src/commonMain/kotlin/world/phantasmal/lib/fileFormats/quest/ByteCode.kt index c7b0f8f7..6008770c 100644 --- a/lib/src/commonMain/kotlin/world/phantasmal/lib/fileFormats/quest/ByteCode.kt +++ b/lib/src/commonMain/kotlin/world/phantasmal/lib/fileFormats/quest/ByteCode.kt @@ -411,7 +411,7 @@ private fun parseInstructionsSegment( for (i in instructions.size - 1 downTo 0) { val opcode = instructions[i].opcode.code - if (opcode == OP_RET.code || opcode == OP_JMP.code || opcode == OP_SWITCH_JMP.code) { + if (opcode == OP_RET.code || opcode == OP_JMP.code) { dropThrough = false break }