From 7f06adf8b132821c704deb6b62c1f40468da191f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 28 Nov 2023 22:13:23 +0000 Subject: Avoid restoring previous exception handler twice --- .../compiler/backends/llvm/LlvmPatioCodeGen.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/main/java') 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(); var llvmSwitchCases = new ArrayList(); - 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 prefixInstructions, - PatioBlock body + PatioBlock body, + List 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); -- cgit v1.2.3