mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
add support for local.tee to wat parser
This commit is contained in:
parent
baf7fb9cf0
commit
0ae27b2c86
@ -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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
|
@ -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" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user