mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
improve wat parser for native support. #2
This commit is contained in:
parent
2a72dfa58d
commit
3d5a98627f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 -2019 Volker Berlin (i-net software)
|
||||
Copyright 2018 - 2019 Volker Berlin (i-net software)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -37,14 +37,13 @@ import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
*/
|
||||
public class WatParser extends WasmCodeBuilder {
|
||||
|
||||
public WatParser() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given wasm text format and generate a list of WasmInstuctions
|
||||
*
|
||||
* @param wat
|
||||
* the text format content of a function
|
||||
* @param lineNumber
|
||||
* the line number for an error message
|
||||
*/
|
||||
public void parse( String wat, int lineNumber ) {
|
||||
try {
|
||||
@ -70,14 +69,44 @@ public class WatParser extends WasmCodeBuilder {
|
||||
case "i32.add":
|
||||
addNumericInstruction( NumericOperator.add, ValueType.i32, javaCodePos );
|
||||
break;
|
||||
case "i32.trunc_sat_f32_s":
|
||||
addConvertInstruction( ValueTypeConvertion.f2i, javaCodePos );
|
||||
break;
|
||||
case "i64.extend_i32_s":
|
||||
addConvertInstruction( ValueTypeConvertion.i2l, javaCodePos );
|
||||
break;
|
||||
case "i64.trunc_sat_f64_s":
|
||||
addConvertInstruction( ValueTypeConvertion.d2l, javaCodePos );
|
||||
break;
|
||||
case "f32.convert_i32_s":
|
||||
addConvertInstruction( ValueTypeConvertion.i2f, javaCodePos );
|
||||
break;
|
||||
case "f32.div":
|
||||
addNumericInstruction( NumericOperator.div, ValueType.f32, javaCodePos );
|
||||
break;
|
||||
case "f32.max":
|
||||
addNumericInstruction( NumericOperator.max, ValueType.f32, javaCodePos );
|
||||
break;
|
||||
case "f32.mul":
|
||||
addNumericInstruction( NumericOperator.mul, ValueType.f32, javaCodePos );
|
||||
break;
|
||||
case "f32.sub":
|
||||
addNumericInstruction( NumericOperator.sub, ValueType.f32, javaCodePos );
|
||||
break;
|
||||
case "f64.convert_i64_s":
|
||||
addConvertInstruction( ValueTypeConvertion.l2d, javaCodePos );
|
||||
break;
|
||||
case "f64.div":
|
||||
addNumericInstruction( NumericOperator.div, ValueType.f64, javaCodePos );
|
||||
break;
|
||||
case "f64.max":
|
||||
addNumericInstruction( NumericOperator.max, ValueType.f64, javaCodePos );
|
||||
break;
|
||||
case "i64.extend_i32_s":
|
||||
addConvertInstruction( ValueTypeConvertion.i2l, javaCodePos );
|
||||
case "f64.mul":
|
||||
addNumericInstruction( NumericOperator.mul, ValueType.f64, javaCodePos );
|
||||
break;
|
||||
case "f64.sub":
|
||||
addNumericInstruction( NumericOperator.sub, ValueType.f64, javaCodePos );
|
||||
break;
|
||||
// case "call":
|
||||
// addCallInstruction( method, javaCodePos );
|
||||
|
@ -102,24 +102,74 @@ public class WatParserTest {
|
||||
test( "i32.add" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void i32_const() throws IOException {
|
||||
test( " i32.const -7 " );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void i32_trunc_sat_f32_s() throws IOException {
|
||||
test( "i32.trunc_sat_f32_s" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void i64_extend_i32_s() throws IOException {
|
||||
test( "i64.extend_i32_s" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void i64_trunc_sat_f64_s() throws IOException {
|
||||
test( "i64.trunc_sat_f64_s" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f32_convert_i32_s() throws IOException {
|
||||
test( "f32.convert_i32_s" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f32_div() throws IOException {
|
||||
test( "f32.div" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f32_max() throws IOException {
|
||||
test( "f32.max" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f32_mul() throws IOException {
|
||||
test( "f32.mul" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f32_sub() throws IOException {
|
||||
test( "f32.sub" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f64_convert_i64_s() throws IOException {
|
||||
test( "f64.convert_i64_s" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f64_div() throws IOException {
|
||||
test( "f64.div" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void f64_max() throws IOException {
|
||||
test( "f64.max" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void i32_const() throws IOException {
|
||||
test( " i32.const -7 " );
|
||||
public void f64_mul() throws IOException {
|
||||
test( "f64.mul" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void i64_extend_i32_s() throws IOException {
|
||||
test( "i64.extend_i32_s" );
|
||||
public void f64_sub() throws IOException {
|
||||
test( "f64.sub" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -131,4 +181,9 @@ public class WatParserTest {
|
||||
public void errorMissingToken() throws IOException {
|
||||
testError( "i32.const", "Missing Token in wasm text format after token: i32.const" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorUnknownToken() throws IOException {
|
||||
testError( "foobar", "Unknown WASM token: foobar" );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user