implements "neg" instruction code

This commit is contained in:
Volker Berlin 2018-04-02 19:15:42 +02:00
parent d78e958342
commit 7ba809ac86
5 changed files with 32 additions and 3 deletions

View File

@ -15,8 +15,8 @@ Status of the project
* Public API of the Compiler
### Partially Finished
* Binary format file writer (130 of 201 byte code instructions)
* Text format file writer (130 of 201 byte code instructions)
* Binary format file writer (134 of 201 byte code instructions)
* Text format file writer (134 of 201 byte code instructions)
### Open Features
* Exception handling - required the next version of WebAssembly

View File

@ -336,6 +336,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break;
}
break;
case neg:
switch( valueType ) {
case f32:
op = F32_NEG;
break;
case f64:
op = F64_NEG;
break;
}
break;
case mul:
switch( valueType ) {
case i32:

View File

@ -548,6 +548,20 @@ public abstract class ModuleWriter implements Closeable {
case 115: // drem
//TODO can be implemented with a helper function like: (a - (long)(a / b) * (double)b)
throw new WasmException( "Modulo/Remainder for floating numbers is not supported in WASM. Use int or long data types." + op, sourceFile, lineNumber );
case 116: // ineg
writeConstInt( -1 );
writeNumericOperator( NumericOperator.mul, ValueType.i32 );
break;
case 117: // lneg
writeConstLong( -1 );
writeNumericOperator( NumericOperator.mul, ValueType.i64 );
break;
case 118: // fneg
writeNumericOperator( NumericOperator.neg, ValueType.f32 );
break;
case 119: // dneg
writeNumericOperator( NumericOperator.neg, ValueType.f64 );
break;
case 120: // ishl
writeNumericOperator( NumericOperator.shl, ValueType.i32 );
break;

View File

@ -21,6 +21,7 @@ package de.inetsoftware.jwebassembly.module;
public enum NumericOperator {
add,
sub,
neg,
mul,
div,
rem,

View File

@ -90,6 +90,7 @@ public class MathOperations extends AbstractBaseTest {
static int addInt( int a, int b ) {
int c = 1234567;
int e = -1;
e = -e;
double d = -1234567;
int i = 1;
long l = 2;
@ -101,7 +102,8 @@ public class MathOperations extends AbstractBaseTest {
@Export
static int addLong() {
long a = 1L;
long b = 3L;
long b = -3L;
b = -b;
return (int)(a + b);
}
@ -110,6 +112,7 @@ public class MathOperations extends AbstractBaseTest {
float c = -1;
float e = 1.25F;
double d = 1234;
e = -e;
int i = 1;
long l = 2;
float f = 3;
@ -121,6 +124,7 @@ public class MathOperations extends AbstractBaseTest {
double c = -1;
double d = 1234;
double e = 1.25;
e = -e;
int i = 1;
long l = 2;
float f = 3;