diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java index 7e97e78..eeacc18 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCodeBuilder.java @@ -254,8 +254,8 @@ public abstract class WasmCodeBuilder { /** * Create a WasmLoadStoreInstruction local.get/local.set. * - * @param load - * true: if load + * @param op + * the operation * @param wasmIdx * the index of the variable * @param javaCodePos @@ -264,8 +264,8 @@ public abstract class WasmCodeBuilder { * the line number in the Java source code */ @Nonnull - protected void addLocalInstruction( boolean load, @Nonnegative int wasmIdx, int javaCodePos, int lineNumber ) { - instructions.add( new WasmLocalInstruction( load, wasmIdx, javaCodePos, lineNumber ) ); + protected void addLocalInstruction( VariableOperator op, @Nonnegative int wasmIdx, int javaCodePos, int lineNumber ) { + instructions.add( new WasmLocalInstruction( op, wasmIdx, javaCodePos, lineNumber ) ); } /** diff --git a/src/de/inetsoftware/jwebassembly/module/WasmLoadStoreInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmLoadStoreInstruction.java index 18c1bea..70e1f9d 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmLoadStoreInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmLoadStoreInstruction.java @@ -16,6 +16,9 @@ */ package de.inetsoftware.jwebassembly.module; +import static de.inetsoftware.jwebassembly.wasm.VariableOperator.get; +import static de.inetsoftware.jwebassembly.wasm.VariableOperator.set; + import javax.annotation.Nonnegative; import de.inetsoftware.jwebassembly.wasm.AnyType; @@ -45,7 +48,7 @@ class WasmLoadStoreInstruction extends WasmLocalInstruction { * the line number in the Java source code */ WasmLoadStoreInstruction( boolean load, @Nonnegative int idx, LocaleVariableManager localVariables, int javaCodePos, int lineNumber ) { - super( load, idx, javaCodePos, lineNumber ); + super( load ? get : set, idx, javaCodePos, lineNumber ); this.localVariables = localVariables; } diff --git a/src/de/inetsoftware/jwebassembly/module/WasmLocalInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmLocalInstruction.java index 22bff94..e89ac3b 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmLocalInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmLocalInstruction.java @@ -39,10 +39,10 @@ class WasmLocalInstruction extends WasmInstruction { private int idx; /** - * Create an instance of a load/store instruction + * Create an instance of a load/store instruction for a local variable. * - * @param load - * true: if load + * @param op + * the operation * @param idx * the memory/slot idx of the variable * @param javaCodePos @@ -50,9 +50,9 @@ class WasmLocalInstruction extends WasmInstruction { * @param lineNumber * the line number in the Java source code */ - WasmLocalInstruction( boolean load, @Nonnegative int idx, int javaCodePos, int lineNumber ) { + WasmLocalInstruction( VariableOperator op, @Nonnegative int idx, int javaCodePos, int lineNumber ) { super( javaCodePos, lineNumber ); - this.op = load ? get : set; + this.op = op; this.idx = idx; } diff --git a/src/de/inetsoftware/jwebassembly/watparser/WatParser.java b/src/de/inetsoftware/jwebassembly/watparser/WatParser.java index 8b4c029..39a80f6 100644 --- a/src/de/inetsoftware/jwebassembly/watparser/WatParser.java +++ b/src/de/inetsoftware/jwebassembly/watparser/WatParser.java @@ -29,6 +29,7 @@ import de.inetsoftware.jwebassembly.module.ValueTypeConvertion; import de.inetsoftware.jwebassembly.module.WasmCodeBuilder; import de.inetsoftware.jwebassembly.wasm.NumericOperator; import de.inetsoftware.jwebassembly.wasm.ValueType; +import de.inetsoftware.jwebassembly.wasm.VariableOperator; import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator; /** @@ -58,10 +59,13 @@ public class WatParser extends WasmCodeBuilder { String tok = tokens.get( i ); switch( tok ) { case "local.get": - addLocalInstruction( true, getInt( tokens, ++i), javaCodePos, lineNumber ); + addLocalInstruction( VariableOperator.get, getInt( tokens, ++i), javaCodePos, lineNumber ); break; case "local.set": - addLocalInstruction( false, getInt( tokens, ++i), javaCodePos, lineNumber ); + addLocalInstruction( VariableOperator.set, getInt( tokens, ++i), javaCodePos, lineNumber ); + break; + case "local.tee": + addLocalInstruction( VariableOperator.tee, getInt( tokens, ++i), javaCodePos, lineNumber ); break; // case "get_global": // addGlobalInstruction( true, ref, javaCodePos ); diff --git a/test/de/inetsoftware/jwebassembly/module/WatParserTest.java b/test/de/inetsoftware/jwebassembly/module/WatParserTest.java index 91a1158..616e940 100644 --- a/test/de/inetsoftware/jwebassembly/module/WatParserTest.java +++ b/test/de/inetsoftware/jwebassembly/module/WatParserTest.java @@ -109,6 +109,11 @@ public class WatParserTest { test( "local.set 2" ); } + @Test + public void Local_tee() throws IOException { + test( "local.tee 3" ); + } + @Test public void i32_add() throws IOException { test( "i32.add" );