mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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.
|
* Create a WasmLoadStoreInstruction local.get/local.set.
|
||||||
*
|
*
|
||||||
* @param load
|
* @param op
|
||||||
* true: if load
|
* the operation
|
||||||
* @param wasmIdx
|
* @param wasmIdx
|
||||||
* the index of the variable
|
* the index of the variable
|
||||||
* @param javaCodePos
|
* @param javaCodePos
|
||||||
@ -264,8 +264,8 @@ public abstract class WasmCodeBuilder {
|
|||||||
* the line number in the Java source code
|
* the line number in the Java source code
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected void addLocalInstruction( boolean load, @Nonnegative int wasmIdx, int javaCodePos, int lineNumber ) {
|
protected void addLocalInstruction( VariableOperator op, @Nonnegative int wasmIdx, int javaCodePos, int lineNumber ) {
|
||||||
instructions.add( new WasmLocalInstruction( load, wasmIdx, javaCodePos, lineNumber ) );
|
instructions.add( new WasmLocalInstruction( op, wasmIdx, javaCodePos, lineNumber ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package de.inetsoftware.jwebassembly.module;
|
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 javax.annotation.Nonnegative;
|
||||||
|
|
||||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||||
@ -45,7 +48,7 @@ class WasmLoadStoreInstruction extends WasmLocalInstruction {
|
|||||||
* the line number in the Java source code
|
* the line number in the Java source code
|
||||||
*/
|
*/
|
||||||
WasmLoadStoreInstruction( boolean load, @Nonnegative int idx, LocaleVariableManager localVariables, int javaCodePos, int lineNumber ) {
|
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;
|
this.localVariables = localVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@ class WasmLocalInstruction extends WasmInstruction {
|
|||||||
private int idx;
|
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
|
* @param op
|
||||||
* true: if load
|
* the operation
|
||||||
* @param idx
|
* @param idx
|
||||||
* the memory/slot idx of the variable
|
* the memory/slot idx of the variable
|
||||||
* @param javaCodePos
|
* @param javaCodePos
|
||||||
@ -50,9 +50,9 @@ class WasmLocalInstruction extends WasmInstruction {
|
|||||||
* @param lineNumber
|
* @param lineNumber
|
||||||
* the line number in the Java source code
|
* 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 );
|
super( javaCodePos, lineNumber );
|
||||||
this.op = load ? get : set;
|
this.op = op;
|
||||||
this.idx = idx;
|
this.idx = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
|||||||
import de.inetsoftware.jwebassembly.module.WasmCodeBuilder;
|
import de.inetsoftware.jwebassembly.module.WasmCodeBuilder;
|
||||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.VariableOperator;
|
||||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,10 +59,13 @@ public class WatParser extends WasmCodeBuilder {
|
|||||||
String tok = tokens.get( i );
|
String tok = tokens.get( i );
|
||||||
switch( tok ) {
|
switch( tok ) {
|
||||||
case "local.get":
|
case "local.get":
|
||||||
addLocalInstruction( true, getInt( tokens, ++i), javaCodePos, lineNumber );
|
addLocalInstruction( VariableOperator.get, getInt( tokens, ++i), javaCodePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case "local.set":
|
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;
|
break;
|
||||||
// case "get_global":
|
// case "get_global":
|
||||||
// addGlobalInstruction( true, ref, javaCodePos );
|
// addGlobalInstruction( true, ref, javaCodePos );
|
||||||
|
@ -109,6 +109,11 @@ public class WatParserTest {
|
|||||||
test( "local.set 2" );
|
test( "local.set 2" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void Local_tee() throws IOException {
|
||||||
|
test( "local.tee 3" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void i32_add() throws IOException {
|
public void i32_add() throws IOException {
|
||||||
test( "i32.add" );
|
test( "i32.add" );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user