use also ref.cast for every cast.

This commit is contained in:
Volker Berlin 2021-02-13 20:56:42 +01:00
parent 0a21fd9de9
commit c1e8191ee0
4 changed files with 14 additions and 0 deletions

View File

@ -1435,6 +1435,11 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
case NEW_WITH_RTT:
opCode = STRUCT_NEW_DEFAULT;
break;
case CAST:
codeStream.writeOpCode( REF_CAST );
codeStream.writeValueType( options.types.valueOf( "java/lang/Object" ) );
codeStream.writeValueType( type );
return;
default:
throw new Error( "Unknown operator: " + op );
}

View File

@ -513,4 +513,6 @@ interface InstructionOpcodes {
static final int ARRAY_LEN = 0xFB17;
static final int RTT_CANON = 0xFB30;
static final int REF_CAST = 0xFB41;
}

View File

@ -228,6 +228,10 @@ class WasmStructInstruction extends WasmInstruction {
writer.writeConst( idx, ValueType.i32 );
}
writer.writeFunctionCall( functionName, null );
if( op == StructOperator.CAST && options.useGC() ) {
writer.writeStructOperator( StructOperator.RTT_CANON, type, null, -1 );
writer.writeStructOperator( op, type, null, -1 );
}
} else {
writer.writeStructOperator( op, type, fieldName, idx );
}

View File

@ -915,6 +915,9 @@ public class TextModuleWriter extends ModuleWriter {
case NEW_WITH_RTT:
operation = "struct.new_with_rtt";
break;
case CAST:
operation = "ref.cast $java/lang/Object";
break;
default:
throw new Error( "Unknown operator: " + op );
}