Skip to content

Commit

Permalink
implements "neg" instruction code
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Apr 2, 2018
1 parent d78e958 commit 7ba809a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ protected void writeNumericOperator( NumericOperator numOp, @Nullable ValueType
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:
Expand Down
14 changes: 14 additions & 0 deletions src/de/inetsoftware/jwebassembly/module/ModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,20 @@ private void writeCodeChunk( CodeInputStream byteCode, int lineNumber, ConstantP
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public enum NumericOperator {
add,
sub,
neg,
mul,
div,
rem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static double doubleConst() {
static int addInt( int a, int b ) {
int c = 1234567;
int e = -1;
e = -e;
double d = -1234567;
int i = 1;
long l = 2;
Expand All @@ -101,7 +102,8 @@ static int addInt( int a, int b ) {
@Export
static int addLong() {
long a = 1L;
long b = 3L;
long b = -3L;
b = -b;
return (int)(a + b);
}

Expand All @@ -110,6 +112,7 @@ static float addFloat( float a, float b ) {
float c = -1;
float e = 1.25F;
double d = 1234;
e = -e;
int i = 1;
long l = 2;
float f = 3;
Expand All @@ -121,6 +124,7 @@ static double addDouble( double a, double b ) {
double c = -1;
double d = 1234;
double e = 1.25;
e = -e;
int i = 1;
long l = 2;
float f = 3;
Expand Down

0 comments on commit 7ba809a

Please sign in to comment.