more wat instructions

This commit is contained in:
Volker Berlin 2019-11-19 19:48:24 +01:00
parent 947f66502b
commit 9286113b0c
4 changed files with 72 additions and 6 deletions

View File

@ -835,6 +835,17 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
default: default:
} }
break; break;
case eqz:
switch( valueType ) {
case i32:
op = I32_EQZ;
break;
case i64:
op = I64_EQZ;
break;
default:
}
break;
case eq: case eq:
switch( valueType ) { switch( valueType ) {
case i32: case i32:
@ -1333,6 +1344,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break; break;
} }
break; break;
case load8_u:
switch( valueType ) {
case i32:
op = I32_LOAD8_U;
break;
case i64:
op = I64_LOAD8_U;
break;
}
break;
} }
if( op == 0 ) { if( op == 0 ) {
throw new Error( valueType + "." + memOp ); throw new Error( valueType + "." + memOp );

View File

@ -108,7 +108,7 @@ public class FunctionName {
* @param signatureName * @param signatureName
* the full Java method signature like "com/foo/Bar.method()V" * the full Java method signature like "com/foo/Bar.method()V"
*/ */
FunctionName( String signatureName ) { public FunctionName( String signatureName ) {
int idx1 = signatureName.indexOf( '.' ); int idx1 = signatureName.indexOf( '.' );
this.className = signatureName.substring( 0, idx1 ); this.className = signatureName.substring( 0, idx1 );
int idx2 = signatureName.indexOf( '(', idx1 ); int idx2 = signatureName.indexOf( '(', idx1 );

View File

@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import de.inetsoftware.classparser.MethodInfo; import de.inetsoftware.classparser.MethodInfo;
import de.inetsoftware.jwebassembly.WasmException; import de.inetsoftware.jwebassembly.WasmException;
import de.inetsoftware.jwebassembly.module.FunctionName;
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion; import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
import de.inetsoftware.jwebassembly.module.WasmCodeBuilder; import de.inetsoftware.jwebassembly.module.WasmCodeBuilder;
import de.inetsoftware.jwebassembly.wasm.MemoryOperator; import de.inetsoftware.jwebassembly.wasm.MemoryOperator;
@ -77,6 +78,9 @@ public class WatParser extends WasmCodeBuilder {
case "i32.add": case "i32.add":
addNumericInstruction( NumericOperator.add, ValueType.i32, javaCodePos, lineNumber ); addNumericInstruction( NumericOperator.add, ValueType.i32, javaCodePos, lineNumber );
break; break;
case "i32.eqz":
addNumericInstruction( NumericOperator.eqz, ValueType.i32, javaCodePos, lineNumber );
break;
case "i32.mul": case "i32.mul":
addNumericInstruction( NumericOperator.mul, ValueType.i32, javaCodePos, lineNumber ); addNumericInstruction( NumericOperator.mul, ValueType.i32, javaCodePos, lineNumber );
break; break;
@ -197,9 +201,17 @@ public class WatParser extends WasmCodeBuilder {
case "table.set": case "table.set":
addTableInstruction( false, getInt( tokens, ++i), javaCodePos, lineNumber ); addTableInstruction( false, getInt( tokens, ++i), javaCodePos, lineNumber );
break; break;
// case "call": case "call":
// addCallInstruction( method, javaCodePos ); StringBuilder builder = new StringBuilder( get( tokens, ++i ) );
// break; String str;
do {
str = get( tokens, ++i );
builder.append( str );
} while ( !")".equals( str ) );
builder.append( get( tokens, ++i ) );
FunctionName name = new FunctionName( builder.substring( 1 ) );
addCallInstruction( name, javaCodePos, lineNumber );
break;
case "return": case "return":
addBlockInstruction( WasmBlockOperator.RETURN, null, javaCodePos, lineNumber ); addBlockInstruction( WasmBlockOperator.RETURN, null, javaCodePos, lineNumber );
break; break;
@ -227,6 +239,9 @@ public class WatParser extends WasmCodeBuilder {
case "i32.load": case "i32.load":
i = addMemoryInstruction( MemoryOperator.load, ValueType.i32, tokens, i, lineNumber ); i = addMemoryInstruction( MemoryOperator.load, ValueType.i32, tokens, i, lineNumber );
break; break;
case "i32.load8_u":
i = addMemoryInstruction( MemoryOperator.load8_u, ValueType.i32, tokens, i, lineNumber );
break;
default: default:
throw new WasmException( "Unknown WASM token: " + tok, lineNumber ); throw new WasmException( "Unknown WASM token: " + tok, lineNumber );
} }

View File

@ -130,6 +130,11 @@ public class WatParserTest {
test( "i32.const -7" ); test( "i32.const -7" );
} }
@Test
public void i32_eqz() throws IOException {
test( "i32.eqz" );
}
@Test @Test
public void i32_mul() throws IOException { public void i32_mul() throws IOException {
test( "i32.mul" ); test( "i32.mul" );
@ -165,6 +170,11 @@ public class WatParserTest {
test( "i64.trunc_sat_f64_s" ); test( "i64.trunc_sat_f64_s" );
} }
@Test
public void f32_abs() throws IOException {
test( "f32.abs" );
}
@Test @Test
public void f32_ceil() throws IOException { public void f32_ceil() throws IOException {
test( "f32.ceil" ); test( "f32.ceil" );
@ -175,6 +185,11 @@ public class WatParserTest {
test( "f32.const 0x1.5p5" ); test( "f32.const 0x1.5p5" );
} }
@Test
public void f32_copysign() throws IOException {
test( "f32.copysign" );
}
@Test @Test
public void f32_convert_i32_s() throws IOException { public void f32_convert_i32_s() throws IOException {
test( "f32.convert_i32_s" ); test( "f32.convert_i32_s" );
@ -230,6 +245,11 @@ public class WatParserTest {
test( "f32.trunc" ); test( "f32.trunc" );
} }
@Test
public void f64_abs() throws IOException {
test( "f64.abs" );
}
@Test @Test
public void f64_ceil() throws IOException { public void f64_ceil() throws IOException {
test( "f64.ceil" ); test( "f64.ceil" );
@ -245,6 +265,11 @@ public class WatParserTest {
test( "f64.convert_i64_s" ); test( "f64.convert_i64_s" );
} }
@Test
public void f64_copysign() throws IOException {
test( "f64.copysign" );
}
@Test @Test
public void f64_div() throws IOException { public void f64_div() throws IOException {
test( "f64.div" ); test( "f64.div" );
@ -335,7 +360,12 @@ public class WatParserTest {
test( "i32.load offset=2 align=1" ); test( "i32.load offset=2 align=1" );
} }
@Test @Test
public void i32_load8_u() throws IOException {
test( "i32.load8_u offset=2 align=1" );
}
@Test
public void errorMissingToken() throws IOException { public void errorMissingToken() throws IOException {
testError( "i32.const", "Missing Token in wasm text format after token: i32.const" ); testError( "i32.const", "Missing Token in wasm text format after token: i32.const" );
} }