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:
}
break;
case eqz:
switch( valueType ) {
case i32:
op = I32_EQZ;
break;
case i64:
op = I64_EQZ;
break;
default:
}
break;
case eq:
switch( valueType ) {
case i32:
@ -1333,6 +1344,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
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 ) {
throw new Error( valueType + "." + memOp );

View File

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

View File

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

View File

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