implements all data conversions instruction codes

This commit is contained in:
Volker Berlin 2018-04-02 10:48:24 +02:00
parent f93b164476
commit 6da8916a75
4 changed files with 113 additions and 12 deletions

View File

@ -548,11 +548,41 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
protected void writeCast( ValueTypeConvertion cast ) throws IOException { protected void writeCast( ValueTypeConvertion cast ) throws IOException {
int op; int op;
switch( cast ) { switch( cast ) {
case i2l:
op = I64_EXTEND_S_I32;
break;
case i2f:
op = F32_CONVERT_S_I32;
break;
case i2d:
op = F64_CONVERT_S_I32;
break;
case l2i: case l2i:
op = I32_WRAP_I64; op = I32_WRAP_I64;
break; break;
case i2l: case l2f:
op = I64_EXTEND_S_I32; op = F32_CONVERT_S_I64;
break;
case l2d:
op = F64_CONVERT_S_I64;
break;
case f2i:
op = I32_TRUNC_S_F32;
break;
case f2l:
op = I64_TRUNC_S_F32;
break;
case f2d:
op = F64_PROMOTE_F32;
break;
case d2i:
op = I32_TRUNC_S_F64;
break;
case d2l:
op = I64_TRUNC_S_F64;
break;
case d2f:
op = F32_DEMOTE_F64;
break; break;
default: default:
throw new Error( "Unknown cast: " + cast ); throw new Error( "Unknown cast: " + cast );

View File

@ -582,9 +582,39 @@ public abstract class ModuleWriter implements Closeable {
case 133: // i2l case 133: // i2l
writeCast( ValueTypeConvertion.i2l ); writeCast( ValueTypeConvertion.i2l );
break; break;
case 134: // i2f
writeCast( ValueTypeConvertion.i2f );
break;
case 135: // i2d
writeCast( ValueTypeConvertion.i2d );
break;
case 136: // l2i case 136: // l2i
writeCast( ValueTypeConvertion.l2i ); writeCast( ValueTypeConvertion.l2i );
break; break;
case 137: // l2f
writeCast( ValueTypeConvertion.l2f );
break;
case 138: // l2d
writeCast( ValueTypeConvertion.l2d );
break;
case 139: // f2i
writeCast( ValueTypeConvertion.f2i );
break;
case 140: // f2l
writeCast( ValueTypeConvertion.f2l );
break;
case 141: // f2d
writeCast( ValueTypeConvertion.f2d );
break;
case 142: // d2i
writeCast( ValueTypeConvertion.d2i );
break;
case 143: // d2l
writeCast( ValueTypeConvertion.d2l );
break;
case 144: // d2f
writeCast( ValueTypeConvertion.d2f );
break;
case 145: // i2b case 145: // i2b
writeConstInt( 24 ); writeConstInt( 24 );
writeNumericOperator( NumericOperator.shl, ValueType.i32 ); writeNumericOperator( NumericOperator.shl, ValueType.i32 );

View File

@ -177,11 +177,41 @@ public class TextModuleWriter extends ModuleWriter {
protected void writeCast( ValueTypeConvertion cast ) throws IOException { protected void writeCast( ValueTypeConvertion cast ) throws IOException {
String op; String op;
switch( cast ) { switch( cast ) {
case i2l:
op = "i64.extend_s/i32";
break;
case i2f:
op = "f32.convert_s/i32";
break;
case i2d:
op = "f64.convert_s/i32";
break;
case l2i: case l2i:
op = "i32.wrap/i64"; op = "i32.wrap/i64";
break; break;
case i2l: case l2f:
op = "i64.extend_s/i32"; op = "f32.convert_s/i64";
break;
case l2d:
op = "f64.convert_s/i64";
break;
case f2i:
op = "i32.trunc_s/f32";
break;
case f2l:
op = "i64.trunc_s/f32";
break;
case f2d:
op = "f64.promote/f32";
break;
case d2i:
op = "i32.trunc_s/f64";
break;
case d2l:
op = "i64.trunc_s/f64";
break;
case d2f:
op = "f32.demote/f64";
break; break;
default: default:
throw new Error( "Unknown cast: " + cast ); throw new Error( "Unknown cast: " + cast );

View File

@ -89,10 +89,13 @@ public class MathOperations extends AbstractBaseTest {
@Export @Export
static int addInt( int a, int b ) { static int addInt( int a, int b ) {
int c = 1234567; int c = 1234567;
int d = -1234567;
int e = -1; int e = -1;
double d = -1234567;
int i = 1;
long l = 2;
float f = 3;
b++; b++;
return a + b + c + d + e; return a + b + c + e + (int)d + i + (int)l + (int)f;
} }
@Export @Export
@ -105,9 +108,12 @@ public class MathOperations extends AbstractBaseTest {
@Export @Export
static float addFloat( float a, float b ) { static float addFloat( float a, float b ) {
float c = -1; float c = -1;
float d = 1234;
float e = 1.25F; float e = 1.25F;
return a + b + c + d + e; double d = 1234;
int i = 1;
long l = 2;
float f = 3;
return a + b + c + e + (float)d + i + l + f;
} }
@Export @Export
@ -115,7 +121,10 @@ public class MathOperations extends AbstractBaseTest {
double c = -1; double c = -1;
double d = 1234; double d = 1234;
double e = 1.25; double e = 1.25;
return a + b + c + d + e; int i = 1;
long l = 2;
float f = 3;
return a + b + c + d + e + i + l + f;
} }
@Export @Export
@ -128,10 +137,12 @@ public class MathOperations extends AbstractBaseTest {
long a = -1L; long a = -1L;
long b = 3L; long b = 3L;
long c = -1L; long c = -1L;
long d = 1234L; double d = 1234;
int e = 3; int i = 1;
long l = 2;
float f = 3;
a--; a--;
return (int)(a - b - c - d + e); return (int)(a - b - c - (long)d - i - l - (long)f);
} }
@Export @Export