Search in sources :

Example 1 with PseudocodeLabel

use of org.jetbrains.kotlin.cfg.pseudocode.PseudocodeLabel in project kotlin by JetBrains.

the class AbstractPseudocodeTest method dumpInstructions.

protected void dumpInstructions(@NotNull PseudocodeImpl pseudocode, @NotNull StringBuilder out, @NotNull Function3<Instruction, /*next*/
Instruction, /*prev*/
Instruction, String> getInstructionData) {
    List<Instruction> instructions = pseudocode.getInstructionsIncludingDeadCode();
    Set<Instruction> remainedAfterPostProcessInstructions = Sets.newHashSet(pseudocode.getInstructions());
    List<PseudocodeLabel> labels = pseudocode.getLabels();
    int instructionColumnWidth = countInstructionColumnWidth(instructions);
    for (int i = 0; i < instructions.size(); i++) {
        Instruction instruction = instructions.get(i);
        for (PseudocodeLabel label : labels) {
            if (label.getTargetInstructionIndex() == i) {
                out.append(label).append(":\n");
            }
        }
        StringBuilder line = new StringBuilder();
        // Only print NEXT and PREV if the values are non-trivial
        Instruction next = i == instructions.size() - 1 ? null : instructions.get(i + 1);
        Instruction prev = i == 0 ? null : instructions.get(i - 1);
        String prefix = getIsDeadInstructionPrefix(instruction, remainedAfterPostProcessInstructions) + getDepthInstructionPrefix(instruction, prev);
        line.append(formatInstruction(instruction, instructionColumnWidth, prefix));
        line.append(getInstructionData.invoke(instruction, next, prev));
        out.append(StringUtil.trimTrailing(line.toString()));
        out.append("\n");
    }
}
Also used : PseudocodeLabel(org.jetbrains.kotlin.cfg.pseudocode.PseudocodeLabel) Instruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction) LocalFunctionDeclarationInstruction(org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction)

Aggregations

PseudocodeLabel (org.jetbrains.kotlin.cfg.pseudocode.PseudocodeLabel)1 Instruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction)1 LocalFunctionDeclarationInstruction (org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction)1