diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-28 22:13:23 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-28 22:13:23 +0000 |
| commit | 7f06adf8b132821c704deb6b62c1f40468da191f (patch) | |
| tree | 6e946a277b8fbf844c4530a97d1f5632c6a50f9c /src/main/java | |
| parent | bc472ebf76c2a7cf2cca4b8f456f4dfe44065d8e (diff) | |
Avoid restoring previous exception handler twice
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java index 31a23d55..9e8ffbef 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGen.java @@ -686,10 +686,12 @@ public class LlvmPatioCodeGen { var branches = new ArrayList<Branch>(); var llvmSwitchCases = new ArrayList<LlvmSwitch.Case>(); - branches.add(Branch.of( + branches.add(new Branch( tryBodyStartLabel, tryBodyEndLabel, - try_.body() + List.of(), + try_.body(), + List.of(restorePreviousExceptionHandlerInstruction) )); llvmSwitchCases.add(new LlvmSwitch.Case(0, tryBodyStartLabel)); @@ -709,10 +711,9 @@ public class LlvmPatioCodeGen { branches.add(new Branch( catchBodyStartLabel, catchBodyEndLabel, - List.of( - restorePreviousExceptionHandlerInstruction - ), - catchClause.body() + List.of(restorePreviousExceptionHandlerInstruction), + catchClause.body(), + List.of() )); var tag = context.exceptionTag(catchClause.exceptionTypeName()); llvmSwitchCases.add(new LlvmSwitch.Case(tag, catchBodyStartLabel)); @@ -743,8 +744,6 @@ public class LlvmPatioCodeGen { context ); - context = context.addInstruction(restorePreviousExceptionHandlerInstruction); - yield context; } @@ -792,14 +791,15 @@ public class LlvmPatioCodeGen { LlvmVariableLocal startLabel, LlvmVariableLocal endLabel, List<LlvmInstruction> prefixInstructions, - PatioBlock body + PatioBlock body, + List<LlvmInstruction> suffixInstructions ) { public static Branch of( LlvmVariableLocal startLabel, LlvmVariableLocal endLabel, PatioBlock body ) { - return new Branch(startLabel, endLabel, List.of(), body); + return new Branch(startLabel, endLabel, List.of(), body, List.of()); } } @@ -819,6 +819,10 @@ public class LlvmPatioCodeGen { context = generateInstructions(branch.body.body(), context); + for (var suffixInstruction : branch.suffixInstructions) { + context = context.addInstruction(suffixInstruction); + } + var endIsUnreachable = branch.body.body().stream() .anyMatch(instruction -> instruction instanceof PatioUnreachable); |
