AsmLikeInstructionListingTest: Handle remaining instructions
Adds argument printing for TypeInsnNode, IincInsnNode, MultiANewArrayInsnNode, InvokeDynamicInsnNode, TableSwitchInsnNode, and LookupSwitchInsnNode.
This commit is contained in:
committed by
Alexander Udalov
parent
7ec9d608cc
commit
ca74b7becc
+26
-10
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.ObsoleteTestInfrastructure
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.tree.*
|
||||
@@ -279,7 +278,7 @@ abstract class AbstractAsmLikeInstructionListingTest : CodegenTestCase() {
|
||||
return buildString {
|
||||
append("Local variables:")
|
||||
for (variable in localVariables) {
|
||||
appendLine().append((variable.index.toString() + " " + variable.name + ": " + variable.desc).withMargin())
|
||||
appendLine().append(("${variable.index} ${variable.name}: ${variable.desc}").withMargin())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -296,12 +295,12 @@ abstract class AbstractAsmLikeInstructionListingTest : CodegenTestCase() {
|
||||
|
||||
private fun StringBuilder.renderInstruction(node: AbstractInsnNode, labelMappings: LabelMappings) {
|
||||
if (node is LabelNode) {
|
||||
appendLine("LABEL (L" + labelMappings[node.label] + ")")
|
||||
appendLine("LABEL (L${labelMappings[node.label]})")
|
||||
return
|
||||
}
|
||||
|
||||
if (node is LineNumberNode) {
|
||||
appendLine("LINENUMBER (" + node.line + ")")
|
||||
appendLine("LINENUMBER (${node.line})")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -310,15 +309,32 @@ abstract class AbstractAsmLikeInstructionListingTest : CodegenTestCase() {
|
||||
append(" ").append(Printer.OPCODES[node.opcode] ?: error("Invalid opcode ${node.opcode}"))
|
||||
|
||||
when (node) {
|
||||
is FieldInsnNode -> append(" (" + node.owner + ", " + node.name + ", " + node.desc + ")")
|
||||
is JumpInsnNode -> append(" (L" + labelMappings[node.label.label] + ")")
|
||||
is IntInsnNode -> append(" (" + node.operand + ")")
|
||||
is MethodInsnNode -> append(" (" + node.owner + ", "+ node.name + ", " + node.desc + ")")
|
||||
is VarInsnNode -> append(" (" + node.`var` + ")")
|
||||
is LdcInsnNode -> append(" (" + node.cst + ")")
|
||||
is FieldInsnNode -> append(" (${node.owner}, ${node.name}, ${node.desc})")
|
||||
is JumpInsnNode -> append(" (L${labelMappings[node.label.label]})")
|
||||
is IntInsnNode -> append(" (${node.operand})")
|
||||
is MethodInsnNode -> append(" (${node.owner}, ${node.name}, ${node.desc})")
|
||||
is VarInsnNode -> append(" (${node.`var`})")
|
||||
is LdcInsnNode -> append(" (${node.cst})")
|
||||
is TypeInsnNode -> append(" (${node.desc})")
|
||||
is IincInsnNode -> append(" (${node.`var`}, ${node.incr})")
|
||||
is MultiANewArrayInsnNode -> append(" (${node.desc}, ${node.dims})")
|
||||
is InvokeDynamicInsnNode -> append(" (${node.name}, ${node.desc}, ${node.bsm}, ${node.bsmArgs.joinToString()})")
|
||||
}
|
||||
|
||||
appendLine()
|
||||
|
||||
if (node is TableSwitchInsnNode || node is LookupSwitchInsnNode) {
|
||||
val (cases, default) = if (node is LookupSwitchInsnNode) {
|
||||
node.keys.zip(node.labels) to node.dflt
|
||||
} else {
|
||||
(node as TableSwitchInsnNode).min.rangeTo(node.max).zip(node.labels) to node.dflt
|
||||
}
|
||||
|
||||
for ((key, labelNode) in cases) {
|
||||
appendLine(" $key: L${labelMappings[labelNode.label]}")
|
||||
}
|
||||
appendLine(" default: L${labelMappings[default.label]}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.withMargin(margin: String = " "): String {
|
||||
|
||||
Reference in New Issue
Block a user