From 25423c6bb8d92c2274299bab7cb115fc6558f004 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Mon, 13 Apr 2020 16:05:41 +0200 Subject: [PATCH] pass LocalvariableManager to the BranchManager to create temp variable for CATCh blocks. --- .../inetsoftware/jwebassembly/module/BranchManger.java | 10 ++++++++-- .../jwebassembly/module/JavaMethodWasmCodeBuilder.java | 2 +- .../jwebassembly/module/WasmCodeBuilder.java | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/BranchManger.java b/src/de/inetsoftware/jwebassembly/module/BranchManger.java index ebb9dbf..cfb3cf7 100644 --- a/src/de/inetsoftware/jwebassembly/module/BranchManger.java +++ b/src/de/inetsoftware/jwebassembly/module/BranchManger.java @@ -56,6 +56,8 @@ class BranchManger { private final List instructions; + private final LocaleVariableManager localVariables; + private TryCatchFinally[] exceptionTable; /** @@ -65,10 +67,13 @@ class BranchManger { * compiler option/properties * @param instructions * the target for instructions + * @param localVariables + * the local variables */ - public BranchManger( WasmOptions options, List instructions ) { - this.instructions = instructions; + public BranchManger( WasmOptions options, List instructions, LocaleVariableManager localVariables ) { this.options = options; + this.instructions = instructions; + this.localVariables = localVariables; } /** @@ -921,6 +926,7 @@ class BranchManger { if( tryCatch.isFinally() ) { catchNode.add( new BranchNode( catchPos, catchPos, WasmBlockOperator.DROP, null ) ); } else { + //TODO localVariables.getTempVariable( ValueType.exnref, catchPos, endPos ); https://github.com/WebAssembly/wabt/issues/1388 catchNode.add( new BranchNode( catchPos, catchPos, WasmBlockOperator.BR_ON_EXN, null, 1 ) ); catchNode.add( new BranchNode( catchPos, catchPos, WasmBlockOperator.RETHROW, null ) ); diff --git a/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java index 06b88e9..d3c91ae 100644 --- a/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/JavaMethodWasmCodeBuilder.java @@ -53,7 +53,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder { @Override void init( WasmOptions options, ClassFileLoader classFileLoader ) { super.init( options, classFileLoader ); - this.branchManager = new BranchManger( options, getInstructions() ); + this.branchManager = new BranchManger( options, getInstructions(), getLocalVariables() ); } /** diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java index 2ae92b6..fc0e289 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java @@ -90,10 +90,20 @@ public abstract class WasmCodeBuilder { * * @return the list */ + @Nonnull List getInstructions() { return instructions; } + /** + * Get the manager of local variables + * @return the manager + */ + @Nonnull + LocaleVariableManager getLocalVariables() { + return localVariables; + } + /** * Check if the last instruction is a return instruction *