diff --git a/src/de/inetsoftware/jwebassembly/watparser/WatParser.java b/src/de/inetsoftware/jwebassembly/watparser/WatParser.java index c483e532..3a508ac8 100644 --- a/src/de/inetsoftware/jwebassembly/watparser/WatParser.java +++ b/src/de/inetsoftware/jwebassembly/watparser/WatParser.java @@ -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 @@ */ 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 void parse( String wat, int lineNumber ) { 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 ); diff --git a/test/de/inetsoftware/jwebassembly/module/WatParserTest.java b/test/de/inetsoftware/jwebassembly/module/WatParserTest.java index 70c9441d..d2c8ed27 100644 --- a/test/de/inetsoftware/jwebassembly/module/WatParserTest.java +++ b/test/de/inetsoftware/jwebassembly/module/WatParserTest.java @@ -102,24 +102,74 @@ public void i32_add() throws IOException { 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 void return_() throws IOException { 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" ); + } }