fix type handling for NUL values with GC support

This commit is contained in:
Volker Berlin 2020-09-24 21:46:02 +02:00
parent 77d81e3f13
commit 856194dbce
5 changed files with 11 additions and 8 deletions

View File

@ -1395,7 +1395,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break;
case NULL:
opCode = REF_NULL;
type = options.useGC() ? ValueType.eqref : ValueType.externref;
type = options.useGC() ? type : ValueType.externref;
break;
default:
throw new Error( "Unknown operator: " + op );

View File

@ -98,8 +98,7 @@ class WasmOutputStream extends LittleEndianOutputStream {
public void writeRefValueType( AnyType type ) throws IOException {
if( type.isRefType() ) {
if( options.useGC() ) {
//TODO writeValueType( ValueType.ref_type );
type = ValueType.eqref;
writeValueType( ValueType.optref );
} else {
type = ValueType.externref;
}

View File

@ -108,7 +108,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
case 0: // nop
break;
case 1: // aconst_null
addStructInstruction( StructOperator.NULL, null, null, codePos, lineNumber );
addStructInstruction( StructOperator.NULL, "java/lang/Object", null, codePos, lineNumber );
break;
case 2: // iconst_m1
case 3: // iconst_0

View File

@ -64,10 +64,10 @@ class WasmStructInstruction extends WasmInstruction {
* @param types
* the type manager
*/
WasmStructInstruction( @Nullable StructOperator op, @Nullable String typeName, @Nullable NamedStorageType fieldName, int javaCodePos, int lineNumber, TypeManager types ) {
WasmStructInstruction( @Nullable StructOperator op, @Nonnull String typeName, @Nullable NamedStorageType fieldName, int javaCodePos, int lineNumber, TypeManager types ) {
super( javaCodePos, lineNumber );
this.op = op;
this.type = typeName == null ? null : types.valueOf( typeName );
this.type = types.valueOf( typeName );
this.fieldName = fieldName;
if( type != null && fieldName != null ) {
type.useFieldName( fieldName );

View File

@ -861,8 +861,12 @@ public class TextModuleWriter extends ModuleWriter {
operation = "struct.set";
break;
case NULL:
operation = options.useGC() ? "ref.null eq" : "ref.null extern";
type = null;
if( options.useGC() ) {
operation = "ref.null";
} else {
operation = "ref.null extern";
type = null;
}
break;
default:
throw new Error( "Unknown operator: " + op );