add support for more const instructions on WatParser

This commit is contained in:
Volker Berlin 2019-11-12 20:06:31 +01:00
parent 8f36ed4d6d
commit c6d569c66c
2 changed files with 33 additions and 3 deletions

View File

@ -82,6 +82,9 @@ public class WatParser extends WasmCodeBuilder {
case "i32.trunc_sat_f32_s":
addConvertInstruction( ValueTypeConvertion.f2i, javaCodePos, lineNumber );
break;
case "i64.const":
addConstInstruction( Long.parseLong( get( tokens, ++i ) ), ValueType.i64, javaCodePos, lineNumber );
break;
case "i64.extend_i32_s":
addConvertInstruction( ValueTypeConvertion.i2l, javaCodePos, lineNumber );
break;
@ -97,6 +100,9 @@ public class WatParser extends WasmCodeBuilder {
case "f32.ceil":
addNumericInstruction( NumericOperator.ceil, ValueType.f32, javaCodePos, lineNumber );
break;
case "f32.const":
addConstInstruction( Float.parseFloat( get( tokens, ++i ) ), ValueType.f32, javaCodePos, lineNumber );
break;
case "f32.convert_i32_s":
addConvertInstruction( ValueTypeConvertion.i2f, javaCodePos, lineNumber );
break;
@ -139,6 +145,9 @@ public class WatParser extends WasmCodeBuilder {
case "f64.ceil":
addNumericInstruction( NumericOperator.ceil, ValueType.f64, javaCodePos, lineNumber );
break;
case "f64.const":
addConstInstruction( Double.parseDouble( get( tokens, ++i ) ), ValueType.f64, javaCodePos, lineNumber );
break;
case "f64.convert_i64_s":
addConvertInstruction( ValueTypeConvertion.l2d, javaCodePos, lineNumber );
break;

View File

@ -77,6 +77,12 @@ public class WatParserTest {
wasSpace = true;
}
break;
case ';':
do {
i++;
} while( i < str.length() && str.charAt( i ) != '\n' );
i--;
break;
default:
builder.append( ch );
wasSpace = false;
@ -106,12 +112,12 @@ public class WatParserTest {
@Test
public void Local_set() throws IOException {
test( "local.set 2" );
test( "i32.const 42 local.set 2" );
}
@Test
public void Local_tee() throws IOException {
test( "local.tee 3" );
test( "i64.const 42 local.tee 3" );
}
@Test
@ -121,7 +127,7 @@ public class WatParserTest {
@Test
public void i32_const() throws IOException {
test( " i32.const -7 " );
test( "i32.const -7" );
}
@Test
@ -134,6 +140,11 @@ public class WatParserTest {
test( "i32.trunc_sat_f32_s" );
}
@Test
public void i64_const() throws IOException {
test( "i64.const 13" );
}
@Test
public void i64_extend_i32_s() throws IOException {
test( "i64.extend_i32_s" );
@ -154,6 +165,11 @@ public class WatParserTest {
test( "f32.ceil" );
}
@Test
public void f32_const() throws IOException {
test( "f32.const 0x1.5p5" );
}
@Test
public void f32_convert_i32_s() throws IOException {
test( "f32.convert_i32_s" );
@ -214,6 +230,11 @@ public class WatParserTest {
test( "f64.ceil" );
}
@Test
public void f64_const() throws IOException {
test( "f64.const 0x1.5p5" );
}
@Test
public void f64_convert_i64_s() throws IOException {
test( "f64.convert_i64_s" );